 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
lilljimpa
Joined: 18 Apr 2007 Posts: 127
|
Posted: Tue Mar 17, 2009 1:14 pm Post subject: gui drag checkbox |
|
|
how can i modify this to take affect on checkbox insted?
| 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 |
_________________ you'll have to excuse me...I'm from Sweden, so my English is not that good...(but now it's better cuz JSLover/Guest is helping me)... |
|
| Back to top |
|
 |
ProsperousOne
Joined: 19 Sep 2005 Posts: 115
|
Posted: Wed Mar 25, 2009 9:13 pm Post subject: |
|
|
I had the same problem with a calandar box. I think the problem is this script won't work for edit enabled (non static) controls.
Try creating a static control around the check box, and when you move that control, it first save the current position of the checkbox, hides it, then moves the static control, and then moves and shows the check box at the new location.
Sorry, don't have time to create a script right now. GL. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Thu Mar 26, 2009 1:29 am Post subject: |
|
|
Note, this is NOT fully functioning. It's buggy, flickers, and won't take the clicks on the checkbox (or move the checkbox) except every other time. I think it's a matter of what has focus (the text box or the checkbox). I post my progress - hopefully someone with more experience can make it work better. Note, the text control starts off hidden (not sure how to fix that) - it's in the top left corner. Hover over it and it will show.
If it doesn't drag, click it again (and it will drag) - like I said, it's buggy.
| Code: | Gui, Add, CheckBox, gControlMove1 vCheckBox1 hwndCheckBox1_hwnd, Text
;Text control used to move the checkbox
;(occupies the same location and moves with the checkbox)
Gui, Add, Text, xp yp wp hp gControlMove1 vText1 hwndText1
Gui, Show, w300 h300, Click'N'Drag the Icons!
Return
ControlMove1:
{
Count++
MouseGetPos, PrevX, PrevY, , sHwnd, 2
GuiControlGet, FocusedControl, FocusV
ToolTip, % Count . " " . (sHwnd = Text1 ? "Text" : "Checkbox")
PostMessage, 0x112,0xF012,0,,ahk_id %sHwnd% ; [ WM_SYSCOMMAND+SC_MOVE ]
Winset,Redraw,,ahk_id %sHwnd% ; Thanks to adamrgolf
;necessary
Sleep, 50
MouseGetPos, NewX, NewY
GuiControlGet, ControlPos, Pos, Text1
GuiControl, MoveDraw, Text1, % "x" . ControlPosX + (NewX - PrevX)
. "y" . ControlPosY + (NewY - PrevY)
return
}
GuiEscape:
GuiClose:
ExitApp |
_________________ As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Fri Mar 27, 2009 2:54 am Post subject: |
|
|
GOT IT! I modified majkinetor's Drag for Any Control and got it working great. The refreshing is a little buggy (when a control is dragged over another control). I'm not sure the cause of this (update - it's the keyboard focus), but it doesn't seem to be caused by the drag.
Ex: Have the controls overlap (some); then, move the mouse (don't drag) over the controls - you'll see what I mean.
Setup
Specify the list of dragable controls in OnMouseDown. Note, the draggable controls MUST exist (i.e. be created) when the script is created - doesn't support dynamic creation of draggable controls. The HWND value is retrieved when the first mouse click is performed (done only once). So, if the control doesn't exist then, it won't be draggable.
| Code: | ;required
OnMessage(0x200, "OnMouseMove") ;WM_MOUSEMOVE := 0x200
OnMessage(0x201, "OnClickDown") ;WM_LBUTTONDOWN := 0x201
OnMessage(0x202, "OnClickUp") ;WM_LBUTTONUP := 0x202
;draggable (MUST store the HWND in a value - see OnClickDown for details)
gui add, Checkbox, x50 y50 w80 h30 hwndMyControl_HWND, MyControl
gui add, Checkbox, x50 y100 w80 h30 hwndMyControl2_HWND, MyControl2
;not draggable
gui add, Checkbox, x150 y100 w80 h30, MyControl3
Gui Show, h300 w300
return
GuiEscape:
GuiClose:
ExitApp
OnClickDown()
{
global
;list of controls to make draggable
static ListOfDraggableControls
local ThisControl
if (!ListOfDraggableControls)
{
;done only once
;these are the HWNDs for the draggable controls
ListOfDraggableControls =
(LTrim Comments
%MyControl_HWND%
%MyControl2_HWND%
)
}
;store the initial Mouse Position - used to move the control relative to the mouse movements.
MouseGetPos, DragAnyControlX, DragAnyControlY, , ThisControl, 2
if (!ThisControl)
return
;DragAnyControl is already empty
Loop, Parse, ListOfDraggableControls, `n
{
if (A_LoopField = ThisControl)
{
DragAnyControl := ThisControl
break
}
}
if (DragAnyControl)
{
;used to detect a drag versus a normal click
DraggedControl := false
Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
;don't send the mouse down (yet) - in case of a drag
return 0
}
}
OnClickUp()
{
global DragAnyControl, DraggedControl
if (DragAnyControl)
{
Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
DragAnyControl := ""
if (!DraggedControl)
{
;send the mouse click (since no drag was performed)
Send, {LButton}
}
;don't send the click up either (handled above)
return 0
}
}
OnMouseMove()
{
global DragAnyControl, DragAnyControlX, DragAnyControlY, DraggedControl
if (DragAnyControl)
{
MouseGetPos, MouseX, MouseY
ControlGetPos, ControlPosX, ControlPosY, , , , ahk_id %DragAnyControl%
ControlMove, , ControlPosX + (MouseX - DragAnyControlX)
, ControlPosY + (MouseY - DragAnyControlY)
, , , ahk_id %DragAnyControl%
Winset,Redraw,,ahk_id %DragAnyControl% ; Thanks to adamrgolf
;update the position
DragAnyControlX := MouseX
DragAnyControlY := MouseY
DraggedControl := true
}
} |
_________________ As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts. |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 549 Location: Berlin / Germany
|
Posted: Fri Mar 27, 2009 12:29 pm Post subject: |
|
|
Drag any control with Ctrl+Click:
| Code: | #NoEnv
WM_MOUSEMOVE := 0x200
WM_LBUTTONDOWN := 0x201
WM_LBUTTONUP := 0x202
; ------------------------------------------------------------------------------
Loop 5
Gui, Add, Picture, Icon%A_Index%, User32.dll
Gui, Add, Text, w200 h30 +0x201 +Border, Static Text Control
Gui, Add, Checkbox, , Checkbox
Gui, Add, Edit, w200 r3, Edit
Gui, Add, DDL, w200 r5, DDL||
Gui, Add, Button, , Move me!
Gui, Show, w400 , Ctrl+Click'N'Drag!
Gui, +LastFound
GuiID := WInExist()
OnMessage(WM_LBUTTONDOWN, "LButtonDown")
Return
; ------------------------------------------------------------------------------
GuiClose:
ExitApp
; ------------------------------------------------------------------------------
LButtonDown(W) {
Global
Static MK_LBUTTON := 0x1
Static MK_CONTROL := 0x8
If (W = (MK_CONTROL + MK_LBUTTON)) {
MouseGetPos, MX, MY, , CH, 2
If (CH) {
ControlGetPos, CX, CY, , , , ahk_id %CH%
DX := CX - MX, DY := CY - MY
OnMessage(WM_LBUTTONDOWN, "")
; WI : WINDOWINFO
NumPut(VarSetCapacity(WI, 68, 0), WI)
DllCall("GetWindowInfo", "UInt", GuiID, "Uint", &WI)
; CR : CLIENTRECT
VarSetCapacity(CR, 16, 0)
NumPut(NumGet(WI, 20), CR), NumPut(NumGet(WI, 24), CR, 4)
NumPut(NumGet(WI, 28), CR, 8), NumPut(NumGet(WI, 32), CR, 12)
DllCall("ClipCursor", "UInt", &CR)
WinGet, CList, ControlListHwnd, ahk_id %GuiID%
Loop, Parse, CList, `n
If (A_LoopField != CH)
Control, Disable, , , ahk_id %A_LoopField%
OnMessage(WM_MOUSEMOVE, "MouseMove")
OnMessage(WM_LBUTTONUP, "LButtonUp")
Return 1 ; Don't pass the Click!
}
}
}
; ------------------------------------------------------------------------------
LButtonUp() {
GLobal
OnMessage(WM_MOUSEMOVE, "")
OnMessage(WM_LBUTTONUP, "")
Loop, Parse, CList, `n
If (A_LoopField != CH)
Control, Enable, , , ahk_id %A_LoopField%
Winset, Redraw, , ahk_id %CH% ; %GuiID%
DllCall("ClipCursor", "UInt", 0)
OnMessage(WM_LBUTTONDOWN, "LButtonDown")
}
; ------------------------------------------------------------------------------
MouseMove() {
Global
Critical
MouseGetPos, MX, MY
ControlMove, , MX + DX, MY + DY, , , ahk_id %CH%
}
; ------------------------------------------------------------------------------ |
_________________ nick  |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Fri Mar 27, 2009 1:56 pm Post subject: |
|
|
Wow! Very vice.
I learned of a new fuction ClipCursor, which I'm sure will be useful. Also, your use of DX instead of recalculating each time, genious. Thank you very much for sharing your code. _________________ As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts. |
|
| 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
|