Jump to content
Sign in to follow this  
rahoolm

Drag & Drop a GUI popup window

Recommended Posts

rahoolm

Hello,

I want to write a script which will drag and drop the GUI window with popup style.

Following is my code.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GUIFade.au3>


Opt("GUIOnEventMode", 1)
Global $max_trans = 240 ; How transparent do you want the window, 0 = hidden, 255 = fully shown
Global $pos[2]
$width = 480
$height = 250
$pos[0] = @DesktopWidth / 2 - $width / 2 ; X (left) position of window
$pos[1] = @DesktopHeight / 2 - $height / 2 ; Y (top) Position of window

#region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("", $width, $height, $pos[0], $pos[1], _
BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP,$WS_BORDER, $WS_EX_ACCEPTFILES))
Global $line = 1
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")

Global $List1 = GUICtrlCreateList("", 40, 40, 381, 123);, $LBS_EXTENDEDSEL)

GUICtrlSetOnEvent($List1, "List1Click")

Global $Button1 = GUICtrlCreateButton("Create Settings && Shortcuts", 200, 190, 151, 41, $WS_GROUP)

GUICtrlSetOnEvent($Button1, "Button1Click")

Global $btnExit = GUICtrlCreateButton("E&xit", 120, 190, 41, 41, $WS_GROUP)

GUICtrlSetOnEvent($btnExit, "MyExit")

Global $Label1 = GUICtrlCreateLabel("Select any one setup from the following", 40, 20, 189, 17)

_FadeGUIIn($Form1,$max_trans)
;~ GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

I want that the after clicking on the body of the form, i should be able to drag the Form1

Please can anybody help me out?

Thanks in advance!!

Share this post


Link to post
Share on other sites
Melba23

rahulmraut,

You can do it like this: :idea:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
;#include <GUIFade.au3>

#include <SendMessage.au3>  ; <<<<<<<<<<<<<<<<<<<<<<<<<

Opt("GUIOnEventMode", 1)
Global $max_trans = 240 ; How transparent do you want the window, 0 = hidden, 255 = fully shown
Global $pos[2]
$width = 480
$height = 250
$pos[0] = @DesktopWidth / 2 - $width / 2 ; X (left) position of window
$pos[1] = @DesktopHeight / 2 - $height / 2 ; Y (top) Position of window

#region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("", $width, $height, $pos[0], $pos[1], _
BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_POPUP,$WS_BORDER, $WS_EX_ACCEPTFILES))
Global $line = 1
;GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
;GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
;GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
;GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Drag_Window")  ; <<<<<<<<<<<<<<<<<<<<<<<<<

Global $List1 = GUICtrlCreateList("", 40, 40, 381, 123);, $LBS_EXTENDEDSEL)

;GUICtrlSetOnEvent($List1, "List1Click")

Global $Button1 = GUICtrlCreateButton("Create Settings && Shortcuts", 200, 190, 151, 41, $WS_GROUP)

;GUICtrlSetOnEvent($Button1, "Button1Click")

Global $btnExit = GUICtrlCreateButton("E&xit", 120, 190, 41, 41, $WS_GROUP)

;GUICtrlSetOnEvent($btnExit, "MyExit")

Global $Label1 = GUICtrlCreateLabel("Select any one setup from the following", 40, 20, 189, 17)

;_FadeGUIIn($Form1,$max_trans)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    Sleep(10)
WEnd

Func Drag_Window()    ; <<<<<<<<<<<<<<<<<<<<<<<<<
    _SendMessage($Form1, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc

Look for the <<<<<<<<<<<< lines.

M23

P.S. If you post code, please make it able to run "out of the box". Having to comment out non-existent functions is a pain and does not help your chances of getting a reply. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
GEOSoft

Although M23's code is by far the best, an alternate easy method is this

#Include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>
$Frm_Test = GUICreate("", 200, 400, -1, -1, $WS_POPUP)
GUICtrlCreateLabel("", 0, 0, 200, 400, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreateEdit("", 20, 20, 100, 200)
GUISetState()

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

It will allow you to click anyplace inside the window and drag it including on a control, in this case the edit.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Melba23

George,

You know how I hate to pick holes in your code, but........... :idea:

With your method you cannot have any controls in the GUI which need need to respond - they would overlap with the label and become blocked. :)

#Include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>

$Frm_Test = GUICreate("", 200, 400, -1, -1, $WS_POPUP)
GUICtrlCreateLabel("", 0, 0, 200, 400, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreateEdit("", 20, 20, 100, 200)
$hButton = GUICtrlCreateButton("Test", 60, 350, 80, 30) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "", "Button pressed")
    EndSwitch
WEnd

And if you disable the label to allow the controls to respond to GUIGetMsg, then the dragging does not work. :(

#Include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>

$Frm_Test = GUICreate("", 200, 400, -1, -1, $WS_POPUP)
GUICtrlCreateLabel("", 0, 0, 200, 400, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState(-1, $GUI_DISABLE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlCreateEdit("", 20, 20, 100, 200)
$hButton = GUICtrlCreateButton("Test", 60, 350, 80, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "", "Button pressed")
    EndSwitch
WEnd

Just though I would point it out before we get further question asking why the controls do not work! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
GEOSoft

George,

You know how I hate to pick holes in your code, but........... :idea:

I was starting to feel sorry for you. You needed a chance to get back at me for previous posts. That was your one and only chance so I'll admit that it's valid enough to count.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Melba23

George & rahulmraut,

I do know another way as well! :idea:

#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc

$hGUI = GUICreate("X", 300, 100, -1, -1, BitOR($WS_POPUP,$WS_BORDER))

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "", "Button pressed")
    EndSwitch
WEnd

Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam)
    If $hWnd = $hGUI Then
        Local $aPos = WinGetPos($hWnd)
        If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 100 Then Return $HTCAPTION
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
rahoolm

THANK YOU VERY MUCH ""Melba23""

Regards,

Rahool

George & rahulmraut,

I do know another way as well! :idea:

#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc

$hGUI = GUICreate("X", 300, 100, -1, -1, BitOR($WS_POPUP,$WS_BORDER))

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "", "Button pressed")
    EndSwitch
WEnd

Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam)
    If $hWnd = $hGUI Then
        Local $aPos = WinGetPos($hWnd)
        If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 100 Then Return $HTCAPTION
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

M23

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.