How to enable Drag for a Static Control ?
http://www.autohotke...p=123732#123732
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?
Redrawing the control before & after drag fixes the visual glitch.. for the rest of your queries, the following code should answer:
Gui, Add, Picture, Icon vCalc gMPPS, calc.exe
Gui, Add, Picture, Icon vNotepad gMPPS, notepad.exe
Gui, Show, w400 h300, Click to Launch or Long-Click to Move
Return
[color=red]MPPS:[/color] ; [color=black]Mobile-Phone-Power-Switch, which provides dual functionality. A short-press of the[/color]
; [color=black]Power button shows you a menu whereas a long-press would shut-off the Mobile phone[/color]
TC:=A_TickCount, App:=A_GuiControl
MouseGetPos,,,,sHwnd1, 2
While LongClick := GetKeyState( "LButton","P" )
If (A_TickCount-TC) > DllCall("GetDoubleClickTime")
Break
IfNotEqual,LongClick,1, GoTo, AppLaunch
[color=red]ControlMove:[/color]
MouseGetPos,,,,sHwnd2, 2
IfNotEqual, sHwnd2, %sHwnd1%, Return
SoundBeep 500
Winset,Redraw,,ahk_id %sHwnd1%
SendMessage, 0x112,0xF012,0,,ahk_id %sHwnd1% ; [ WM_SYSCOMMAND+SC_MOVE ]
Winset,Redraw,,ahk_id %sHwnd1%
[color=red]Return[/color]
[color=red]AppLaunch:[/color]
IfEqual,App,Notepad, Run,notepad.exe
IfEqual,App,Calc, Run,calc.exe
[color=red]Return[/color]
Another - simpler way - for differentiating between click and click-drag is to use a modifier key:
Gui, Add, Picture, Icon vCalc gAppLaunch, calc.exe
Gui, Add, Picture, Icon vNotepad gAppLaunch, notepad.exe
Gui, Show, w400 h300, Click to Launch or Long-Click to Move
Return
AppLaunch:
If GetKeyState( "Control","P" )
GoTo, ControlMove
App := A_GuiControl
IfEqual,App,Notepad, Run,notepad.exe
IfEqual,App,Calc, Run,calc.exe
Return
ControlMove:
MouseGetPos,,,,sHwnd, 2
Winset,Redraw,,ahk_id %sHwnd%
SendMessage, 0x112,0xF012,0,,ahk_id %sHwnd% ; [ WM_SYSCOMMAND+SC_MOVE ]
Winset,Redraw,,ahk_id %sHwnd%
Return