How to enable Drag for a Static Control ?
http://www.autohotke...p=123732#123732
For a Picture Puzzle game, I had to enable Drag and Drop for Static Controls. Lucky me, I found a simple way.
Run the following Copy/Paste/Try example - Should be self explanatory!
Credit: Thanks to adamrgolf for his suggestion to add a WinSet, Redraw command.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
Edit: 2010-Jun-11
______________________
MouseGetPos produces bizarre results when we try to move a fan-stacked series of images. The wrong control was being moved: Read Discussion. To overcome the said effect, we may use a matching pair of pseudo-arrays ( one for 'control hwnd' and the other for 'variable name' ) to determine the exact control that was clicked. Here follows a working example:IfNotExist, *.png Loop 5 UrlDownloadtoFile, https://ahknet.autohotkey.com/~goyyah/pic%A_Index%.png, pic%A_Index%.png Loop *.png Gui, 1:Add, Picture, xp+64 y32 hwndhWnd%A_Index% Border vI%A_Index% gControlMove +0x4000000, %A_LoopFileLongPath% ; WS_CLIPSIBLINGS := 0x4000000 Gui, 1:Show, w800 h600, Draggable-Controls Return ControlMove: Ix := SubStr( A_GuiControl,2 ), sHwnd := hWnd%Ix% DllCall( "SetWindowPos", UInt,sHwnd, UInt,0, UInt,0, UInt,0, UInt,0, UInt,0, UInt,0x43 ) Sleep -1 ; ^ SWP_NOMOVE := 0x2 | SWP_NOSIZE := 0x1 | SWP_SHOWWINDOW := 0x40 = 0x43 SendMessage, 0x112, 0xF012, 0,, ahk_id %sHwnd% ; WM_SYSCOMMAND and SC_MOVE Return
Related Post: How to enable Drag for a GUI without a Titlebar ?

[How to] Enable Drag for a Static Control ?
![[How to] Enable Drag for a Static Control ?: post #1](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
SetBatchlines -1 SetControlDelay, -1 #SingleInstance force WM_LBUTTONDOWN := 0x201 WM_LBUTTONUP := 0x202 WM_MOUSEMOVE := 0x200 onmessage(WM_LBUTTONDOWN, "OnClickDown") onmessage(WM_LBUTTONUP, "OnClickUp") onmessage(WM_MOUSEMOVE, "OnMouseMove") Gui +LastFound +resize handle := WinExist() dc := DllCall("GetDC", "uint", handle) Gui Show, h300 w300 gui add, Button, x100 y100 w80 h30, MyControl return OnClickDown(){ global if A_GuiControl = MyControl mode = move } OnClickUp(){ global if A_GuiControl = MyControl mode = static } OnMouseMove() { global if mode = move { MouseGetPos mx, my ControlGetPos x, y, w, h, MyControl, ahk_id %handle% controlmove MyControl, mx,my } }
![[How to] Enable Drag for a Static Control ?: post #2](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
![[How to] Enable Drag for a Static Control ?: post #3](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)

@Laszlo: My Picture Puzzle somewhat demonstartes a crude method to snap controls to the virtual grid.
Thanks.

![[How to] Enable Drag for a Static Control ?: post #4](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
And it might need some adjustments to avoid moving the top-left button to the cursor position.
Beside, we rarely need to move (with mouse) non-static controls, but yet the demonstration is interesting.
Skan, your solution is very interesting by its simplicity.
I provided a much more convoluted solution a long time ago, based on Veovis' code, seen in its sigma game.
strange results when attempting a Gui Drag event...
I also made a splitter bar using the above code: Splitter bar window control with AHk
I guess it is time to put these scripts to the trash can... :-)
![[How to] Enable Drag for a Static Control ?: post #5](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)

majkinetor, this is interesting, but you should distinguish simple click from held click & move: after moving the button, its action is triggered. And it might need some adjustments to avoid moving the top-left button to the cursor position.
I didn't inted to provide full blown example, just to see is it possible. I made this for toralf and SGUI long time ago.
I don't see why you constantly talk about if something is useful and how much is it useful. If you need it, its useful, if you don't need it, even the most useful stuff is unuseful. Like I told you, I created this for toralf and SGUI which is extremely useful...Beside, we rarely need to move (with mouse) non-static controls, but yet the demonstration is interesting.
Anyway, there is a great feedback you get just by knowing how some stuff can be done and fullfiling your curiosity and xperience. I guess you forgot that. Perhaps... to old ?

![[How to] Enable Drag for a Static Control ?: post #6](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
I understood it as such, my remarks aren't to deprecate your work, but to complement it, in case somebody wants to use it.I didn't inted to provide full blown example, just to see is it possible.
Where did I wrote that it isn't useful? Would I wrote "interesting" (twice! :-P) for something I judge useless?I don't see why you constantly talk about if something is useful and how much is it useful.
SGUI is very useful indeed, and falls in the category of "rare use", no? Unless you provide an option to dynamically change the GUI of all your applications.I created this for toralf and SGUI which is extremely useful...
That's exactly what I meant by "interesting".Anyway, there is a great feedback you get just by knowing how some stuff can be done and fullfiling your curiosity and xperience.
Perhaps... too touchy?Perhaps... to old ?
![[How to] Enable Drag for a Static Control ?: post #7](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)

Skan, your solution is very interesting by its simplicity.
Thanks!

I provided a much more convoluted solution a long time ago, based on Veovis' code, seen in its sigma game.
strange results when attempting a Gui Drag event...
I also made a splitter bar using the above code: Splitter bar window control with AHk
Yes! I remember it. I was a newbie by then and could not understand much of it.

![[How to] Enable Drag for a Static Control ?: post #8](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Acctually, I was thinking about this.Unless you provide an option to dynamically change the GUI of all your applications.
Definitely. Didn't you learn that already about me ?Perhaps... too touchy?
Anyway, its not as bad as too old


![[How to] Enable Drag for a Static Control ?: post #9](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Anyway, its not as bad as too old
(btw, how old are you
)
46 - 48 would be my best guess! :roll:
![[How to] Enable Drag for a Static Control ?: post #10](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
And I am much younger in mind! :-P (what do you mean by "it shows"?)
![[How to] Enable Drag for a Static Control ?: post #11](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)

If you use skans example a few posts back, if you drag an icon ontop of another icon, and then move the bottommost icon -- it still shows whatever part the of the top icon was directly above it
if you add a redraw it seems to help a bit:
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 ] [color=red] Winset,Redraw,,Click'N'Drag the Icons![/color] ; here Return
![[How to] Enable Drag for a Static Control ?: post #12](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
How to enable Drag for a Static Control ?
http://www.autohotke...p=123732#123732Loop 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
Related Post: How to enable Drag for a GUI without a Titlebar ?
:idea:![]()
SKAN, I have a few questions for you about this wonderful snippet of code...
1. How can I distinguish between the drag action, and a click action? And since it seems that all dragable images would have the same action code, is there a way to reference the variable of whichever image was clicked?
2. If I drag an image passing completely over another one, there are no glitches. But if I let go of the drag while one image is on top of another, then as soon as I drag that top image away, it retains whatever portion of the bottom image it was covering. I have to click that top image a second time in order to clear that. Is there a way to fix that visual glitch?
![[How to] Enable Drag for a Static Control ?: post #14](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
#InstallMouseHook SetTimer,mouse,10 mouse: if !drag := GetKeyState("LButton", "P") ToolTip % "Mouse Up" Else ToolTip % "Holding down" Return
![[How to] Enable Drag for a Static Control ?: post #15](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
WIN or LEARN.