Jump to content

Moving window without title with other static controls in it?


 Share

Go to solution Solved by pixelsearch,

Recommended Posts

Hello.

Example in the Moving and Resizing PopUp GUIs works well when dragged an empty window but when dragged a static control (label) - it doesn't move the window.

 

#include <Windowsconstants.au3>
#include <SendMessage.au3>

HotKeySet("{ESC}", "On_Exit")

$hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP)
GUISetBkColor(0x009F00)

$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50)
GUICtrlsetBkColor(-1, 0x9F0000)

GUISetState()

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")  

While 1
  Sleep(10)
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
  _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc

Func On_Exit()
  Exit
EndFunc

In the example above only dragging green part moves the window.

 

Then I've tried adopt PhoenixXL's example that forwards events from control to main GUI, but that moves window away from the cursor when clicked on red:

 

#include <Windowsconstants.au3>
#include <SendMessage.au3>
#include <WinAPIDlg.au3>

HotKeySet("{ESC}", "On_Exit")

$hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP)
GUISetBkColor(0x00FF00)

$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 50)
$hLabel = GUIctrlgethandle($hLabel)
GUICtrlsetBkColor(-1, 0xFF0000)

GUISetState()
DeclareGlobals()

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")  

While 1
  Sleep(10)
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
  _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc

Func On_Exit()
  Exit
EndFunc


Func DeclareGlobals()

    ;used this to declare the globals required for the subclass.
    ;only to make the script look good.


    ;the function to release the resources upon exit
    OnAutoItExitRegister("Cleanup")

    ;callback
    Global $hStub = DllCallbackRegister("_WndProc", "long", "hwnd;uint;wparam;lparam")
    ;old window procedure
    Global $lpOldWndProc = _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, DllCallbackGetPtr($hStub))

EndFunc   ;==>DeclareGlobals


Func _WndProc($hWnd, $iMsg, $iwParam, $ilParam)

    ;proceed the message to the parent
    Switch $iMsg
        Case $WM_LBUTTONDOWN

            Local $hParent = _WinAPI_GetParent($hWnd)

            Local $tPoint = DllStructCreate($tagPOINT)
            DllStructSetData($tPoint, 1, _WinAPI_LoWord($ilParam))
            DllStructSetData($tPoint, 2, _WinAPI_HiWord($ilParam))

            ;convert the points of the picture with respect to that of the parent.
            _WinAPI_ClientToScreen($hWnd, $tPoint)
            _WinAPI_ScreenToClient($hParent, $tPoint)

            ;make the new ilParam.
            $ilParam = _WinAPI_MakeLong(DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))

            ;send the message to the main GUI.
            _WinAPI_PostMessage($hParent, $WM_LBUTTONDOWN, $iwParam, $ilParam)

            Return 1 ;block the default processing
    EndSwitch

    Return _WinAPI_CallWindowProc($lpOldWndProc, $hWnd, $iMsg, $iwParam, $ilParam)

EndFunc   ;==>_WndProc

;release the resources
Func Cleanup()
    _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $lpOldWndProc)
    DllCallbackFree($hStub)
EndFunc   ;==>Cleanup

 

Any tips how to move window when clicked anywhere inside of it?

Thank you.

Edited by VAN0
Link to comment
Share on other sites

Glad you liked the simple way :)
You may be interested with another way (which doesn't register messages). It allows you to drag a popup window even if you don't click on a static label. This way of scripting isn't really recommended in case you'll deal with child GUI's one day :

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

HotKeySet("{ESC}", "On_Exit")

$hGUI = GUICreate("X", 100, 100, -1, -1, $WS_POPUP, $WS_EX_CONTROLPARENT)
GUISetBkColor(0x00FF00, $hGUI)

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

While 1
    Switch GUIGetMsg()
        Case $hButton
            On_Button()
    EndSwitch
WEnd

Func On_Button()
    MsgBox(0, "Hi", "Button Pressed")
EndFunc   ;==>On_Button

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

 

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...