jolumaoj Posted August 24, 2012 Share Posted August 24, 2012 Hello, I need to make a GUI where I can move some elements (like a label) to a target area, like making a puzzle. Furthermore, I would like that the target area could recognize what elements has been released over it. Could anyone say me if this is possible? Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2012 Moderators Share Posted August 24, 2012 jolumaoj, Welcome to the AutoIt forum. Yes it is quite possible - as you can see here: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ; Mouse coords relative to GUI client area Opt("MouseCoordMode", 2) ; Set target coords Global $iTgt_Left = 10, $iTgt_Right = 210, $iTgt_Top = 10, $iTgt_Bot = 110 ; Create GUI $hGUI = GUICreate("Test", 300, 200) $cTarget = GUICtrlCreateLabel("", $iTgt_Left, $iTgt_Top, $iTgt_Right - $iTgt_Left, $iTgt_Bot - $iTgt_Top, $SS_BLACKFRAME) GUICtrlSetState(-1, $GUI_DISABLE) $cLabel = GUICtrlCreateLabel("Move me", 10, 150, 60, 20) GUICtrlSetBkColor(-1, 0x00FF00) $cButton = GUICtrlCreateButton("Me too", 110, 150, 80, 23) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN ; If the mouse button is pressed - get info about where $cInfo = GUIGetCursorInfo($hGUI) ; Is it over a control $iControl = $cInfo[4] Switch $iControl ; If it is a control we want to move Case $cLabel, $cButton ; Work out offset of mouse on control $aPos = ControlGetPos($hGUI, "", $iControl) $iSubtractX = $cInfo[0] - $aPos[0] $iSubtractY = $cInfo[1] - $aPos[1] ; And then move the control until the mouse button is released Do $cInfo = GUIGetCursorInfo($hGUI) ControlMove($hGUI, "", $iControl, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) Until Not $cInfo[2] ; See if the mouse was released over the target $aMPos = MouseGetPos() If $aMPos[0] > $iTgt_Left And $aMPos[0] < $iTgt_Right Then If $aMPos[1] > $iTgt_Top And $aMPos[1] < $iTgt_Bot Then Switch $iControl Case $cLabel $sItem = "label" Case $cButton $sItem = "button" EndSwitch MsgBox(0, "Info", "Over target with " & $sItem) EndIf EndIf EndSwitch EndSwitch WEnd Please ask if you have any questions. M23 pixelsearch and robertocm 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jolumaoj Posted August 24, 2012 Author Share Posted August 24, 2012 Melba, thank you very much. This is just what I need. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2012 Moderators Share Posted August 24, 2012 jolumaoj, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mechaflash Posted August 24, 2012 Share Posted August 24, 2012 (edited) An idea to make it look cooler After the ControlGetPos() use GDI to draw an outline of the button, and on mouse move event, redraw the image to make it look like you're dragging it XD ooo and disable the control so its grayed out while you're moving it. Edited August 24, 2012 by mechaflash213 Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
roleku Posted February 12, 2014 Share Posted February 12, 2014 Thank you Melba23 for the script. . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now