AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tips N Tricks
Goto page Previous  1, 2, 3 ... 20, 21, 22, 23, 24, 25  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed May 23, 2007 11:19 pm    Post subject: How to enable Drag for a Static Control ? Reply with quote

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 ?

Idea Very Happy


Last edited by SKAN on Fri Jul 13, 2007 4:46 pm; edited 2 times in total
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Wed May 23, 2007 11:28 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Thu May 24, 2007 2:09 am    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu May 24, 2007 6:13 am    Post subject: Reply with quote

@majkinetor: Very nice Very Happy. Thanks for sharing the technique.
@Laszlo: My Picture Puzzle somewhat demonstartes a crude method to snap controls to the virtual grid.

Thanks. Smile
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu May 24, 2007 9:07 am    Post subject: Reply with 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.
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... Smile
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Thu May 24, 2007 10:07 am    Post subject: Reply with quote

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 ? Very Happy
_________________
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu May 24, 2007 10:33 am    Post subject: Reply with quote

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! Razz) 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 ? Very Happy
Perhaps... too touchy?
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu May 24, 2007 11:19 am    Post subject: Reply with quote

PhiLho wrote:
Skan, your solution is very interesting by its simplicity.


Thanks! Smile

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.

Smile
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Thu May 24, 2007 12:16 pm    Post subject: Reply with quote

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 Razz (btw, how old are you Very Happy )
_________________
Back to top
View user's profile Send private message MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu May 24, 2007 12:23 pm    Post subject: Reply with quote

majkinetor wrote:
Anyway, its not as bad as too old Razz (btw, how old are you Very Happy )


46 - 48 would be my best guess! Rolling Eyes
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu May 24, 2007 12:34 pm    Post subject: Reply with quote

Hey, I won't be 46 before October 6!
And I am much younger in mind! Razz (what do you mean by "it shows"?)
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
adamrgolf



Joined: 28 Dec 2006
Posts: 390

PostPosted: Fri Jul 13, 2007 1:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Fri Jul 13, 2007 2:28 pm    Post subject: Reply with quote

Thanks! I have updated the post Smile
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Thu Sep 06, 2007 9:31 pm    Post subject: Reply with quote

Quote:
How to Animate a GUI Window ?
Have found that marvelous piece of code. A life saver!
Thanks, Skan (I owe you a लस्सी) Cool
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu Sep 06, 2007 9:57 pm    Post subject: Reply with quote

BoBoĻ wrote:
I owe you a लस्सी


Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 20, 21, 22, 23, 24, 25  Next
Page 21 of 25

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group