AutoHotkey Community

It is currently May 25th, 2012, 6:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: May 24th, 2007, 12:19 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Quote:
How to enable Drag for a Static Control ?
http://www.autohotkey.com/forum/viewtopic.php?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.

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


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:

Code:
IfNotExist, *.png
  Loop 5
   UrlDownloadtoFile, http://www.autohotkey.net/~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 ?


Last edited by SKAN on June 11th, 2010, 5:34 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 12:28 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
How to enable Drag for Any Control

Code:
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

   }
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 3:09 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Very nice effects! I suppose you got some snap-to-grid functionality, and redraw of the control, to make it useful for games, like Go, or chess. Please post those, too! Congratulations!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 7:13 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
@majkinetor: Very nice :D. Thanks for sharing the technique.
@Laszlo: My Picture Puzzle somewhat demonstartes a crude method to snap controls to the virtual grid.

Thanks. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 10:07 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.
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... :-)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 11:07 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
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.

Quote:
Beside, we rarely need to move (with mouse) non-static controls, but yet the demonstration is interesting.

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...

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 ? :D

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 11:33 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
majkinetor wrote:
I didn't inted to provide full blown example, just to see is it possible.
I understood it as such, my remarks aren't to deprecate your work, but to complement it, in case somebody wants to use it.

Quote:
I don't see why you constantly talk about if something is useful and how much is it useful.
Where did I wrote that it isn't useful? Would I wrote "interesting" (twice! :-P) for something I judge useless?

Quote:
I created this for toralf and SGUI which is extremely 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.

Quote:
Anyway, there is a great feedback you get just by knowing how some stuff can be done and fullfiling your curiosity and xperience.
That's exactly what I meant by "interesting".

Quote:
Perhaps... to old ? :D
Perhaps... too touchy?

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 12:19 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
PhiLho wrote:
Skan, your solution is very interesting by its simplicity.


Thanks! :)

PhiLho wrote:
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.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:16 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Unless you provide an option to dynamically change the GUI of all your applications.

Acctually, I was thinking about this.

Quote:
Perhaps... too touchy?

Definitely. Didn't you learn that already about me ?
Anyway, its not as bad as too old :P (btw, how old are you :D )

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:23 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
majkinetor wrote:
Anyway, its not as bad as too old :P (btw, how old are you :D )


46 - 48 would be my best guess! :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:34 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Hey, I won't be 46 before October 6!
And I am much younger in mind! :-P (what do you mean by "it shows"?)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2007, 2:17 pm 
Offline

Joined: December 28th, 2006, 9:46 am
Posts: 440
Regarding click'n'drag --

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:

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,,Click'N'Drag the Icons!      ; here
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2007, 3:28 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Thanks! I have updated the post :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 26th, 2010, 6:30 pm 
SKAN wrote:

How to enable Drag for a Static Control ?
http://www.autohotkey.com/forum/viewtopic.php?p=123732#123732

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


Related Post: How to enable Drag for a GUI without a Titlebar ?

:idea: :D




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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2010, 7:11 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3825
Location: Louisville KY USA
in its most simplistic form
Code:
#InstallMouseHook
SetTimer,mouse,10
mouse:
   if !drag := GetKeyState("LButton", "P")
      ToolTip % "Mouse Up"
   Else ToolTip % "Holding down"
Return

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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:
cron
Powered by phpBB® Forum Software © phpBB Group