Jump to content

$GUI_WS_EX_PARENTDRAG and GUICtrlSetOnEvent


Recommended Posts

Greetings,

I have a GUI on which are GUICtrlCreateLabels appended with $GUI_WS_EX_PARENTDRAG because I want to be able to use them to click-and-drag my GUI. They used to be buttons, but buttons do not allow for $GUI_WS_EX_PARENTDRAG, so now they are labels masquerading as buttons. These labels, who in their soul are buttons, are invigorated with GUICtrlSetOnEvent, so they do a thing when they are clicked.

My trouble is that when I drag my GUI with one of the GUICtrlCreateLabels, it also activates the GUICtrlSetOnEvent. I want the GUICtrlSetOnEvent to only activate if my click does not drag the GUI.

I tried having the function called by GUICtrlSetOnEvent look at where the GUI is, but it only checks that after I let go of the click, so it doesn't fix it.

Any ideas?

Thanks!

Link to comment
Share on other sites

  • Moderators

baconaise,

How about providing a small runnable example script showing the problem so we can see exactly what you are doing - otherwise we risk not reproducing your case correctly.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)

Create_GUI()

While 1
   Sleep(10)
WEnd

Func Create_GUI()
   Global $GUI_Main = GUICreate("Main GUI", 200, 100)
   Global $GUI_Main_Button = GUICtrlCreateLabel("Button", 0, 0, 200, 100, BitOR($SS_CENTERIMAGE, $SS_CENTER, $SS_RIGHTJUST), $GUI_WS_EX_PARENTDRAG)
   GUICtrlSetOnEvent($GUI_Main_Button, "Button_Function")
   GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function")
   GUISetState(@SW_SHOW, $GUI_Main)
EndFunc

Func Button_Function()
   MsgBox($MB_OK,"You did the thing", "I only want the thing done if I didn't use the label/button to drag the GUI")
EndFunc

Func Exiting_Function()
   Exit
EndFunc

 

Link to comment
Share on other sites

You should probably be using a Message Handler rather than an OnEvent message. 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I see your point. What you see is an excerpt of a ~25,000 line script, and other portions rely pretty heavily on the OnEvent functionality. I'd really prefer to find a way to get this to work without trying to rework so much.

Link to comment
Share on other sites

Not easy but this might work
BTW declaring global variables inside a func is not nice  :)

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)

Create_GUI()

While 1
   Sleep(10)
WEnd

Func Create_GUI()
   Global $GUI_Main = GUICreate("Main GUI", 200, 100)
   Global $GUI_Main_Button = GUICtrlCreateLabel("Button", 0, 0, 200, 100, BitOR($SS_CENTERIMAGE, $SS_CENTER, $SS_RIGHTJUST))    ;, $GUI_WS_EX_PARENTDRAG)
   GUICtrlSetOnEvent($GUI_Main_Button, "Drag")
   GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function")
   GUISetState(@SW_SHOW, $GUI_Main)
EndFunc

Func Drag()
   $pos = WinGetPos($GUI_Main)
   DllCall("user32.dll", "int", "ReleaseCapture")
   DllCall("user32.dll", "int", "SendMessage", "hWnd", $GUI_Main, "int", 0xA1, "int", 2, "int", 0) ;WM_NCLBUTTONDOWN
   Sleep(10)
   $pos2 = WinGetPos($GUI_Main)
   If $pos[0] = $pos2[0] and $pos[1] = $pos2[1] Then Button_Function()
EndFunc

Func Button_Function()
   MsgBox($MB_OK,"You did the thing", "I only want the thing done if I didn't use the label/button to drag the GUI")
EndFunc

Func Exiting_Function()
   Exit
EndFunc

 

Link to comment
Share on other sites

Thanks
An other flavour

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
Opt("GUIOnEventMode", 1)

Global Const $SC_DRAGMOVE = 0xF012

Create_GUI()

While 1
   Sleep(10)
WEnd

Func Create_GUI()
   Global $GUI_Main = GUICreate("Main GUI", 200, 100)
   Global $GUI_Main_Button = GUICtrlCreateLabel("Button", 0, 0, 200, 100, BitOR($SS_CENTERIMAGE, $SS_CENTER, $SS_RIGHTJUST))    
   GUICtrlSetOnEvent($GUI_Main_Button, "Drag")
   GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function")
   GUISetState(@SW_SHOW, $GUI_Main)
EndFunc

Func Drag()
   $pos = WinGetPos($GUI_Main)
  _SendMessage($GUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
   Sleep(10)
   $pos2 = WinGetPos($GUI_Main)
   If $pos[0] = $pos2[0] and $pos[1] = $pos2[1] Then Button_Function()
EndFunc

Func Button_Function()
   MsgBox($MB_OK,"You did the thing", "I only want the thing done if I didn't use the label/button to drag the GUI")
EndFunc

Func Exiting_Function()
   Exit
EndFunc

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...