Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How to] Enable Drag for a Static Control ?


  • Please log in to reply
26 replies to this topic
Trente
  • Guests
  • Last active:
  • Joined: --

in its most simplistic form

#InstallMouseHook 
SetTimer,mouse,10
mouse:
	if !drag := GetKeyState("LButton", "P") 
		ToolTip % "Mouse Up"
	Else ToolTip % "Holding down"
Return



How exactly would that integrate with SKAN's code snippet? Your code suggests that it would apply in general to clicking or dragging. But SKAN's code is specific to each image being dragged. In addition, I would need to seperate clicking on one of those images versus clicking on a blank area of the screen.

I need something that integrates on a per-image basis - I think.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
and so your saying you have no imagination to try figure it out? why should we do it all for you then maybe someone else will i wont
Never lose.
WIN or LEARN.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

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


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
hrmm would this also fix the 'glitch'?
...
; http://msdn.microsoft.com/en-us/library/dd145167(v=VS.85).aspx
dllCall("UpdateWindow", UInt, sHwnd1)
...
Just wondering..

Posted Image

don't duplicate, iterate!


Trente
  • Guests
  • Last active:
  • Joined: --

and so your saying you have no imagination to try figure it out? why should we do it all for you then maybe someone else will i wont



It's not about imagination, it's about programming knowledge and skill. I'm not asking others to do my work for me, but if I'm having difficulty figuring out how something works, I ask for help.

In case it slipped past you, this part of the forum is for people asking for help. If this is your attitude when it comes to people less skilled than you, it might be best if you spent your time elsewhere.

Trente
  • Guests
  • Last active:
  • Joined: --

Redrawing the control before & after drag fixes the visual glitch.. for the rest of your queries, the following code should answer:

Another - simpler way - for differentiating between click and click-drag is to use a modifier key:



Thank you, SKAN. That helped me to understand better.

If it's not possible to do a true drag vs click, then I think the second method works better for me since it's less awkward (not to mention faster) to use a modifier key than to wait for a long click.


Honestly, thank you for taking the time to enlighten me. :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

not possible to do a true drag vs click


I did not tell that. I do not know your application.
Mine is Picture Puzzle where I use 'drag control' to swap picture tiles.
Try the following:

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:
 App := A_GuiControl, Count := pX := pY := 0
 ; Scan for mouse movement while Left-Mouse-Button is down
 While GetKeyState( "LButton","P" ) {
   MouseGetPos,X,Y,,sHwnd, 2
   Count := ( X<>pX || Y<>pY ) ? Count+1 : Count, pX:=X, pY:=Y
   IfGreater, Count, 3, GoTo, ControlMove ; Movement detected.., Trigger Control Move
 }
 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

the second method works better for me since it's less awkward


Awkward? A Mobile-phone-switch is not awkward in a mobile phone :)..., again, I do not know your application. I was just experimenting possibilities.

Honestly, thank you for taking the time to enlighten me. :)


Honestly, I am pleased when somebody finds 'help' in my post. Most of my replies in Ask-for-help do not attract a reply from the original poster. :(

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

In case it slipped past you, this part of the forum is for people asking for help.


Just to clarify Trente, the Scripts & Functions forum is NOT the forum for people asking for help. Ask for Help is the correct forum.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Agreed!

This thread is way too important to be sullied with help requests.

Posted Image

don't duplicate, iterate!


Trente
  • Guests
  • Last active:
  • Joined: --

In case it slipped past you, this part of the forum is for people asking for help.


Just to clarify Trente, the Scripts & Functions forum is NOT the forum for people asking for help. Ask for Help is the correct forum.


I realized that about two seconds after hitting "Submit", but it was too late. :)

My apologies. However, I still maintain that it was a poor attitude to have.

Trente
  • Guests
  • Last active:
  • Joined: --

Agreed!

This thread is way too important to be sullied with help requests.


I understand. I'm moving this discussion to another thread.

Trente
  • Guests
  • Last active:
  • Joined: --

not possible to do a true drag vs click


I did not tell that. I do not know your application.



SKAN, let's continue this here:
http://www.autohotke...topic58614.html