Jump to content

help with border !!!!


AlienStar
 Share

Recommended Posts

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

This is the easiest way:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))
GUICtrlCreateLabel("", 0, 0, 250, 100, -1, $GUI_WS_EX_PARENTDRAG)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$w = 250 + 14
$h = 100 + 14
$hGUI = GUICreate("", $w - 14, $h - 14, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))
GUICtrlCreateLabel("", 0, 0, $w - 14, $h - 14, -1, $GUI_WS_EX_PARENTDRAG)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_GETMINMAXINFO, "")
            Exit
    EndSwitch
WEnd

Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $w) ; min width
    DllStructSetData($minmaxinfo, 8, $h) ; min height
    DllStructSetData($minmaxinfo, 9, $w) ; max width
    DllStructSetData($minmaxinfo, 10, $h) ; max height
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_GETMINMAXINFO

I don't know why I've to add 14 to width and height of GUI otherwise the GUI size will be changed only one time (smaller).

Happy new year,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I don't know why I've to add 14 to width and height of GUI otherwise the GUI size will be changed only one time (smaller).

I was first who introduced WM_GETMINMAXINFO API into Autoit in 2006 so I know why ;-)

It's because width/height in GUICreate defines only ClientSize, i.e. without size of TitleBar/Frame

But in WM_GETMINMAXINFO you need size of whole window so you must use WinGetPos like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $w, $h

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))
GUICtrlCreateLabel("", 0, 0, 250, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState(@SW_SHOW)

$size = WinGetPos($hGUI)
$w = $size[2] ; width of window (GUICreate is ClientSize)
$h = $size[3] ; height of window (GUICreate is ClientSize)
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_GETMINMAXINFO, "")
            Exit
    EndSwitch
WEnd

Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $w) ; min width
    DllStructSetData($minmaxinfo, 8, $h) ; min height
    DllStructSetData($minmaxinfo, 9, $w) ; max width
    DllStructSetData($minmaxinfo, 10, $h) ; max height
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_GETMINMAXINFO

And constant 14 is bad for various OS visual settings Classic/XP theme and so on

so instead of using constants in such situation you should call

DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)
Edited by Zedna
Link to comment
Share on other sites

Thanks Zedna for the information but I've kind of guessed, but it was too late :x to search for the reason!

Now I know it!

Happy new year,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Ok, so I thought about this all of last night (or tried to anyway...) as I knew there was a way to let you use the border to move the window. It came to me as soon as I woke up of course :P Process WM_NCHITTEST and tell the window that the caption is being clicked :x 4 lines of code in the end (plus a blank line and a #forceref line).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

If you want to process clicks in the client area as normal, then you need to call DefWndProc to see if it's in a size border.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    Local $iDef = _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)

    Switch $iDef
        Case $HTBOTTOM, $HTBOTTOMLEFT, $HTBOTTOMRIGHT, $HTLEFT, $HTRIGHT, $HTTOP, $HTTOPLEFT, $HTTOPRIGHT
            Return $HTCAPTION
    EndSwitch

    Return $iDef
EndFunc   ;==>WM_NCHITTEST

Mat

Link to comment
Share on other sites

Nice small solution Mat :x

My solution is rather a brute force solution compared to yours!

Happy new year,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I couldn't get the system menu to show on right click by using WM_SYSCOMMAND, so here's a workaround. It doesn't work when pressing the app key... only by using the right mouse button.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <MenuConstants.au3>
#include <GUIMenu.au3>

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))

$hMenu = _GUICtrlMenu_GetSystemMenu($hGUI)
_GUICtrlMenu_SetItemState($hMenu, $SC_RESTORE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_SIZE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_MINIMIZE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_MAXIMIZE, $MFS_DISABLED, True, False)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_NCRBUTTONUP, "WM_NCRBUTTONUP")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    Local $iDef = _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)

    Switch $iDef
        Case $HTBOTTOM, $HTBOTTOMLEFT, $HTBOTTOMRIGHT, $HTLEFT, $HTRIGHT, $HTTOP, $HTTOPLEFT, $HTTOPRIGHT
            Return $HTCAPTION
    EndSwitch

    Return $iDef
EndFunc   ;==>WM_NCHITTEST

Func WM_NCRBUTTONUP($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    If ($wParam = $HTCAPTION) Then
        Local $iCmd = _GUICtrlMenu_TrackPopupMenu(_GUICtrlMenu_GetSystemMenu($hWnd), $hWnd, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam), 1, 1, 2, 1)

        If ($iCmd <> 0) Then _SendMessage($hWnd, $WM_SYSCOMMAND, $iCmd, $lParam)
    EndIf

    Return 0
EndFunc   ;==>WM_NCRBUTTONUP
Link to comment
Share on other sites

I couldn't get the system menu to show on right click by using WM_SYSCOMMAND, so here's a workaround. It doesn't work when pressing the app key...

Using Zedna's nifty idea of assigning Accelerators to dummy controls (), this adds app key functionality

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <MenuConstants.au3>
#include <GUIMenu.au3>
Global Const $SM_CXFIXEDFRAME = 7

$hGUI = GUICreate("", 250, 100, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP))
$AppKey = GUICtrlCreateDummy()
Dim $aAccelKeys[1][2] = [["{APPSKEY}", $AppKey]]


GUISetAccelerators($aAccelKeys)

$hMenu = _GUICtrlMenu_GetSystemMenu($hGUI)
_GUICtrlMenu_SetItemState($hMenu, $SC_RESTORE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_SIZE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_MINIMIZE, $MFS_DISABLED, True, False)
_GUICtrlMenu_SetItemState($hMenu, $SC_MAXIMIZE, $MFS_DISABLED, True, False)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_NCRBUTTONUP, "WM_NCRBUTTONUP")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $AppKey
            $aWinPos = WinGetPos($hGUI)
            $iBorderOffset = _WinAPI_GetSystemMetrics($SM_CXFIXEDFRAME)
            $lParam = _WinAPI_MakeLong($aWinPos[0] + $iBorderOffset, $aWinPos[1] + $iBorderOffset)
            WM_NCRBUTTONUP($hGUI, $WM_NCRBUTTONUP, $HTCAPTION, $lParam)
    EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam

    Local $iDef = _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)

    Switch $iDef
        Case $HTBOTTOM, $HTBOTTOMLEFT, $HTBOTTOMRIGHT, $HTLEFT, $HTRIGHT, $HTTOP, $HTTOPLEFT, $HTTOPRIGHT
            Return $HTCAPTION
    EndSwitch

    Return $iDef
EndFunc   ;==>WM_NCHITTEST

Func WM_NCRBUTTONUP($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    If ($wParam = $HTCAPTION) Then
        Local $iCmd = _GUICtrlMenu_TrackPopupMenu(_GUICtrlMenu_GetSystemMenu($hWnd), $hWnd, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam), 1, 1, 2, 1)
        If ($iCmd <> 0) Then _SendMessage($hWnd, $WM_SYSCOMMAND, $iCmd, $lParam)
    EndIf

    Return 0
EndFunc   ;==>WM_NCRBUTTONUP
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...