AutoHotkey Community

It is currently May 26th, 2012, 4:32 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: gui drag checkbox
PostPosted: March 17th, 2009, 2:14 pm 
Offline

Joined: April 18th, 2007, 9:03 am
Posts: 127
how can i modify this to take affect on checkbox insted?

Code:
Loop 6
 Gui, Add, Picture, Icon%A_Index% gControlMove, User32.dll
Gui, Add, Text, w200 h30 +0x201 +Border gControlMove, Static Text Control
Gui, Show, w400 h300, Click'N'Drag the Icons!
Return

ControlMove:
  MouseGetPos,,,,sHwnd, 2
  PostMessage, 0x112,0xF012,0,,ahk_id %sHwnd% ; [ WM_SYSCOMMAND+SC_MOVE ]
  Winset,Redraw,,ahk_id %sHwnd% ; Thanks to adamrgolf
Return

_________________
you'll have to excuse me...I'm from Sweden, so my English is not that good...(but now it's better cuz JSLover/Guest is helping me)...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 10:13 pm 
Offline

Joined: September 19th, 2005, 1:31 am
Posts: 115
I had the same problem with a calandar box. I think the problem is this script won't work for edit enabled (non static) controls.

Try creating a static control around the check box, and when you move that control, it first save the current position of the checkbox, hides it, then moves the static control, and then moves and shows the check box at the new location.

Sorry, don't have time to create a script right now. GL.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2009, 2:29 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Note, this is NOT fully functioning. It's buggy, flickers, and won't take the clicks on the checkbox (or move the checkbox) except every other time. I think it's a matter of what has focus (the text box or the checkbox). I post my progress - hopefully someone with more experience can make it work better. Note, the text control starts off hidden (not sure how to fix that) - it's in the top left corner. Hover over it and it will show.

If it doesn't drag, click it again (and it will drag) - like I said, it's buggy.

Code:
Gui, Add, CheckBox, gControlMove1 vCheckBox1 hwndCheckBox1_hwnd, Text

;Text control used to move the checkbox
;(occupies the same location and moves with the checkbox)
Gui, Add, Text, xp yp wp hp gControlMove1 vText1 hwndText1

Gui, Show, w300 h300, Click'N'Drag the Icons!
Return

ControlMove1:
{
    Count++
   
    MouseGetPos, PrevX, PrevY, , sHwnd, 2

    GuiControlGet, FocusedControl, FocusV

    ToolTip, % Count . " " . (sHwnd = Text1 ? "Text" : "Checkbox")

    PostMessage, 0x112,0xF012,0,,ahk_id %sHwnd% ; [ WM_SYSCOMMAND+SC_MOVE ]
    Winset,Redraw,,ahk_id %sHwnd% ; Thanks to adamrgolf

    ;necessary
    Sleep, 50
   
    MouseGetPos, NewX, NewY

    GuiControlGet, ControlPos, Pos, Text1

    GuiControl, MoveDraw, Text1, % "x" . ControlPosX + (NewX - PrevX)
        . "y" . ControlPosY + (NewY - PrevY)

    return
}

GuiEscape:
GuiClose:
ExitApp

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2009, 3:54 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
GOT IT! I modified majkinetor's Drag for Any Control and got it working great. The refreshing is a little buggy (when a control is dragged over another control). I'm not sure the cause of this (update - it's the keyboard focus), but it doesn't seem to be caused by the drag.

Ex: Have the controls overlap (some); then, move the mouse (don't drag) over the controls - you'll see what I mean.

Setup
Specify the list of dragable controls in OnMouseDown. Note, the draggable controls MUST exist (i.e. be created) when the script is created - doesn't support dynamic creation of draggable controls. The HWND value is retrieved when the first mouse click is performed (done only once). So, if the control doesn't exist then, it won't be draggable.

Code:
;required
OnMessage(0x200, "OnMouseMove") ;WM_MOUSEMOVE   := 0x200
OnMessage(0x201, "OnClickDown") ;WM_LBUTTONDOWN := 0x201
OnMessage(0x202, "OnClickUp")   ;WM_LBUTTONUP   := 0x202

;draggable (MUST store the HWND in a value - see OnClickDown for details)
gui add, Checkbox, x50 y50 w80 h30 hwndMyControl_HWND, MyControl
gui add, Checkbox, x50 y100 w80 h30 hwndMyControl2_HWND, MyControl2
   
;not draggable
gui add, Checkbox, x150 y100 w80 h30, MyControl3

Gui Show, h300 w300
return

GuiEscape:
GuiClose:
ExitApp

OnClickDown()
{
    global

    ;list of controls to make draggable
    static ListOfDraggableControls
   
    local ThisControl
   
    if (!ListOfDraggableControls)
    {
        ;done only once

        ;these are the HWNDs for the draggable controls
        ListOfDraggableControls =
        (LTrim Comments
            %MyControl_HWND%
            %MyControl2_HWND%
        )
    }

    ;store the initial Mouse Position - used to move the control relative to the mouse movements.
    MouseGetPos, DragAnyControlX, DragAnyControlY, , ThisControl, 2

    if (!ThisControl)
        return

    ;DragAnyControl is already empty
   
    Loop, Parse, ListOfDraggableControls, `n
    {
        if (A_LoopField = ThisControl)
        {
            DragAnyControl := ThisControl
            break
        }
    }

    if (DragAnyControl)
    {
        ;used to detect a drag versus a normal click
        DraggedControl := false
       
        Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
       
        ;don't send the mouse down (yet) - in case of a drag
        return 0
    }
}

OnClickUp()
{
    global DragAnyControl, DraggedControl
   
    if (DragAnyControl)
    {
        Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
       
        DragAnyControl := ""
       
        if (!DraggedControl)
        {
            ;send the mouse click (since no drag was performed)
            Send, {LButton}
        }

        ;don't send the click up either (handled above)
        return 0
    }
}

OnMouseMove()
{
    global DragAnyControl, DragAnyControlX, DragAnyControlY, DraggedControl

    if (DragAnyControl)
    {
        MouseGetPos, MouseX, MouseY
        ControlGetPos, ControlPosX, ControlPosY, , , , ahk_id %DragAnyControl%
       
        ControlMove, , ControlPosX + (MouseX - DragAnyControlX)
            , ControlPosY + (MouseY - DragAnyControlY)
            , , , ahk_id %DragAnyControl%
           
        Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
       
        ;update the position
        DragAnyControlX := MouseX
        DragAnyControlY := MouseY
       
        DraggedControl := true
   }
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2009, 1:29 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Drag any control with Ctrl+Click:

Code:
#NoEnv
WM_MOUSEMOVE := 0x200
WM_LBUTTONDOWN := 0x201
WM_LBUTTONUP := 0x202
; ------------------------------------------------------------------------------
Loop 5
   Gui, Add, Picture, Icon%A_Index%, User32.dll
Gui, Add, Text, w200 h30 +0x201 +Border, Static Text Control
Gui, Add, Checkbox, , Checkbox
Gui, Add, Edit, w200 r3, Edit
Gui, Add, DDL, w200 r5, DDL||
Gui, Add, Button, , Move me!
Gui, Show, w400 , Ctrl+Click'N'Drag!
Gui, +LastFound
GuiID := WInExist()
OnMessage(WM_LBUTTONDOWN, "LButtonDown")
Return
; ------------------------------------------------------------------------------
GuiClose:
ExitApp
; ------------------------------------------------------------------------------
LButtonDown(W) {
   Global
   Static MK_LBUTTON := 0x1
   Static MK_CONTROL := 0x8
   If (W = (MK_CONTROL + MK_LBUTTON)) {
      MouseGetPos, MX, MY, , CH, 2
      If (CH) {
         ControlGetPos, CX, CY, , , , ahk_id %CH%
         DX := CX - MX, DY := CY - MY
         OnMessage(WM_LBUTTONDOWN, "")
         ; WI : WINDOWINFO
         NumPut(VarSetCapacity(WI, 68, 0), WI)
         DllCall("GetWindowInfo", "UInt", GuiID, "Uint", &WI)
         ; CR : CLIENTRECT
         VarSetCapacity(CR, 16, 0)
         NumPut(NumGet(WI, 20), CR), NumPut(NumGet(WI, 24), CR, 4)
         NumPut(NumGet(WI, 28), CR, 8), NumPut(NumGet(WI, 32), CR, 12)
         DllCall("ClipCursor", "UInt", &CR)
         WinGet, CList, ControlListHwnd, ahk_id %GuiID%
         Loop, Parse, CList, `n
            If (A_LoopField != CH)
               Control, Disable, , , ahk_id %A_LoopField%
         OnMessage(WM_MOUSEMOVE, "MouseMove")
         OnMessage(WM_LBUTTONUP, "LButtonUp")
         Return 1 ; Don't pass the Click!
      }
   }
}
; ------------------------------------------------------------------------------
LButtonUp() {
   GLobal
   OnMessage(WM_MOUSEMOVE, "")
   OnMessage(WM_LBUTTONUP, "")
   Loop, Parse, CList, `n
      If (A_LoopField != CH)
         Control, Enable, , , ahk_id %A_LoopField%
   Winset, Redraw, , ahk_id %CH% ; %GuiID%
   DllCall("ClipCursor", "UInt", 0)
   OnMessage(WM_LBUTTONDOWN, "LButtonDown")
}
; ------------------------------------------------------------------------------
MouseMove() {
   Global
   Critical
   MouseGetPos, MX, MY
   ControlMove, , MX + DX, MY + DY, , , ahk_id %CH%
}
; ------------------------------------------------------------------------------

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2009, 2:56 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Wow! Very vice.

I learned of a new fuction ClipCursor, which I'm sure will be useful. Also, your use of DX instead of recalculating each time, genious. Thank you very much for sharing your code.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, rbrtryn, SKAN, tterB, Yahoo [Bot] and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group