 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Wed May 23, 2007 11:19 pm Post subject: How to enable Drag for a Static Control ? |
|
|
| 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 |
Related Post: How to enable Drag for a GUI without a Titlebar ?
|
Last edited by SKAN on Fri Jul 13, 2007 4:46 pm; edited 2 times in total |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3652 Location: Belgrade
|
Posted: Wed May 23, 2007 11:28 pm Post subject: |
|
|
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
}
} |
_________________
 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu May 24, 2007 2:09 am Post subject: |
|
|
| 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! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Thu May 24, 2007 6:13 am Post subject: |
|
|
@majkinetor: Very nice . Thanks for sharing the technique.
@Laszlo: My Picture Puzzle somewhat demonstartes a crude method to snap controls to the virtual grid.
Thanks.  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu May 24, 2007 9:07 am Post subject: |
|
|
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...  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3652 Location: Belgrade
|
Posted: Thu May 24, 2007 10:07 am Post subject: |
|
|
| 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 ?  _________________
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu May 24, 2007 10:33 am Post subject: |
|
|
| 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! ) 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 ?  | Perhaps... too touchy? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Thu May 24, 2007 11:19 am Post subject: |
|
|
| PhiLho wrote: | | Skan, your solution is very interesting by its simplicity. |
Thanks!
Yes! I remember it. I was a newbie by then and could not understand much of it.
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3652 Location: Belgrade
|
Posted: Thu May 24, 2007 12:16 pm Post subject: |
|
|
| 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 (btw, how old are you ) _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Thu May 24, 2007 12:23 pm Post subject: |
|
|
| majkinetor wrote: | Anyway, its not as bad as too old (btw, how old are you ) |
46 - 48 would be my best guess!  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu May 24, 2007 12:34 pm Post subject: |
|
|
Hey, I won't be 46 before October 6!
And I am much younger in mind! (what do you mean by "it shows"?) _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 390
|
Posted: Fri Jul 13, 2007 1:17 pm Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Fri Jul 13, 2007 2:28 pm Post subject: |
|
|
Thanks! I have updated the post  |
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Thu Sep 06, 2007 9:31 pm Post subject: |
|
|
| Quote: | | How to Animate a GUI Window ? | Have found that marvelous piece of code. A life saver!
Thanks, Skan (I owe you a लस्सी)  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Thu Sep 06, 2007 9:57 pm Post subject: |
|
|
| BoBoĻ wrote: | | I owe you a लस्सी |
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|