JakeJohnson74

2 GUI Issues I can't seem to iron out!

7 posts in this topic

#1 ·  Posted (edited)

Hey Guys, this is somewhat related to another post in here but my specific question was "answered" and so I thought I would make a new post that is referencing the same code, with slightly different issues. 

Problem 1

Setup: I am using a label docked to the main GUI to set the size of a child GUI. 

Issue: When I slowly drag the borders, I can see my green label kind of peeking out from behind the GUI, not a huge problem I guess. If I drag the border very quicky I can get the offset to be really big (200-300 pixels)

** Edit - I just realized that the child of the child GUI actually does not display this same "lag" or difference in sizing. hmmmm

Problem 2

*discaimer! - Melba if you see this, I know you have Aero disabled so I understand if you don't want anything to do with this one! haha

Setup: Using windows message WM_WINDOWPOSCHANGING. This should give me a message "While" the window is changing. There is a WM_WINDOWPOSCHANGED, which should fire after the change happens. 

Issue: Upon a normal maximize/restore methods (double clicking title bar, or using the buttons) the window behaves. Upon an Aero Snap maximize/restore the update only happens AFTER I let go of my left click. So while dragging the window down from its maximized state the child GUI's remain maximized until I let go of the left click  mouse button and it resizes. I really want this to resize the second it unsnaps from the maximized state. 

**Edit - This is due to the way I am handling the flags parameter of the WINDOWPOS Struct. I'm masking only using 1 of the members and it only sees that once the LMB is released. So I am basically misusing the message because im not very familiar with it :( I have experimented with bitOR(member1, member2, member3) because im thinking SWP_FRAMECHANGED is not the only member I should be masking against "flags" (although it works somewhat)

Here is my code. 

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

$iGuiWidth = 660
$iGUIHeight = 320
$DividerOffset = 244

Global $aGUIPos[6]
Global $hgui, $hgui1, $hguiInner1, $cLabel_1, $cLabel_2, $cLabel_3, $iOFfset_X1, $iOFfset_Y1
Global $bSysMsg = False

GUI()
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WM_WINDOWPOSCHANGING")


Func GUI()
    $hgui = GUICreate("test", $iGuiWidth, $iGUIHeight, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_POPUP))
    GUISetBkColor(0x666666)

    $cLabel_1 = GUICtrlCreateLabel("I am the label", 4, 65, $iGuiWidth - 7, 250)
    GUICtrlSetBkColor(-1, 0x00FF00)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH, $GUI_DOCKRIGHT))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState()

    $hgui1 = GUICreate("", $iGuiWidth - 7, $iGUIHeight - 70, -1, 60, $WS_POPUP, $WS_EX_MDICHILD, $hgui)
    GUISetBkColor(0x888888)
    GUISetState()

    $Divider = GUICtrlCreateLabel('', $DividerOffset, 0, 5, 250)
    GUICtrlSetBkColor(-1, 0xFF0000)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKWIDTH, $GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM))
    GUICtrlSetCursor(-1, 13)
    GUISetState()

    $cLabel_2 = GUICtrlCreateLabel("I am the label", 249, 25, 403, 225)
    GUICtrlSetBkColor(-1, 0x0000FF)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH, $GUI_DOCKRIGHT))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState()

    $hGuiInner1 = GUICreate("",  403, 225, 252,28, $WS_POPUP, $WS_EX_MDICHILD, $hgui1)
    GUISetBkColor(0x555555)
    GUISetState()

    _GetGuiPos($hgui,0,1)
    _GetGuiPos($hgui1,2,3)
;~  _GetGuiPos(hgui2,3,4)

For $i = 0 to 5
    ConsoleWrite("$aguipos[" & $i & "]:=" & $aguipos[$i] &  @LF)
Next


EndFunc   ;==>GUI

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Quit()
    EndSwitch

    If $bSysMsg Then
        $bSysMsg = False
        _Resize_GUIs()
    EndIf

WEnd

Func Quit()
    Exit
EndFunc   ;==>Quit

Func _Resize_GUIs()
    ;GUI1
    $aWin1 = WinGetPos($hgui)
    $aRet1 = ControlGetPos($hgui, "", $cLabel_1)
    WinMove($hgui1, "", $aWin1[0] + $aGUIPos[0] + $aRet1[0], $aWin1[1] + $aGUIPos[1] + $aRet1[1], $aRet1[2], $aRet1[3])
    $aWin2 = WinGetPos($hgui1)
    $aRet2 = ControlGetPos($hgui1, "", $cLabel_2)
    WinMove($hguiInner1, "", $aWin2[0] + $aGUIPos[2] + $aRet2[0], $aWin2[1] + $aGUIPos[3] + $aRet2[1], $aRet2[2], $aRet2[3])
;~  $aWin3 = WinGetPos($hgui)
;~     $aRet3 = ControlGetPos($hgui, "", $cLabel_3)
;~     WinMove($hgui1, "", $aWin3[0] + $aGUIPos[4] + $aRet3[0], $aWin3[1] + $aGUIPos[5] + $aRet3[1], $aRet3[2], $aRet3[3])

EndFunc   ;==>_Resize_GUIs

func _WM_WINDOWPOSCHANGING($hWnd, $msg, $wParam, $lParam)
   Local $winpos_Struct = DllStructCreate("hwnd hwnd;hwnd hwndInsertAfter;int x;int y;int cx;int cy;uint flags", $lParam)
   $MaximizeOrRestore = bitand(DllStructGetData($winpos_Struct, "flags"), $SWP_FRAMECHANGED)
   if $MaximizeOrRestore > 0 then
      $bSysMsg = True
   endif
EndFunc

Func _WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_GUIs()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_SIZE

Func _Exit($s_Msg)
    MsgBox(0, "Error", $s_Msg)
    Exit
EndFunc

Func _GetGuiPos($hTargGUI,$iArrayEle1,$iArrayEle2)
    $aWin = WinGetPos($hTargGUI)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)
    _WinAPI_ClientToScreen($hTargGUI, $tPoint)
    $aGUIPos[$iArrayEle1] = DllStructGetData($tPoint, "X") -  $aWin[0]
    $aGUIPos[$iArrayEle2] = DllStructGetData($tPoint, "Y") -  $aWin[1]
EndFunc
Edited by JakeKenmode

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok Problem 1 Solved: 

It seems messy to me, but this worked by some stroke of luck in my experimenting.

WM_WINDOWPOSCHANGING fires when anything happens. So altering my mask I was able to catch resizes as well as maximizes and minimizes. 

WM_SIZE handles the "live" sizing while you are dragging, but then at the end if there was any mismatch I am using WM_WINDOWPOSCHANGING to give it one last update at the end that perfectly sizes my child GUI to the green label under it. 

Why WM_SIZE on its own could be tricked? I don't know, but changing WM_WINDOWPOSCHANGING's  the mask to: 

bitand(DllStructGetData($winpos_Struct, "flags"), bitor($SWP_FRAMECHANGED,$SWP_NOMOVE,$SWP_NOZORDER))

allowed me to catch window resizes once I let go of the LMB at the end of a resize. 

Like I said - messy. Also - This message "should" be firing events AS the window is moving as the description on MSDN suggests. This leads me to believe I am still using it wrong because the events are firing after all the moves and I let go of LMB on a drag. 

So I'm closer - Issue 2 still exists 

Edited by JakeKenmode

Share this post


Link to post
Share on other sites

JakeKenmode,

Fine, I will limit my comments to problem 1 only! :D

Just make the label transparent (look in the Help file to see how) as this has no effect on the label resizing but means it does not show when the resizing is taking place. ;)

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

#4 ·  Posted (edited)

In the main app - it will be transparent, I'm just using the test code up there to simplify and show me the labels, so I can see that it is performing correctly. 

Here is an image showing the result of quickly dragging the right edge of the form very fast. 

post-87120-0-00465800-1424285378_thumb.j

I referenced your resize script with the 3 list views and only edited the background colors and on a really fast drag of the window you can achieve the same effects where the labels size / position goes out of whack

post-87120-0-77161500-1424285942_thumb.j

 

Edited by JakeKenmode

Share this post


Link to post
Share on other sites

JakeKenmode,

AutoIt is an interpreted language - you will never get the speed of response that you get with fully compiled languages. We are already using a trick to get the non-AutoIt generated controls resized so it seems a little ungracious to complain that AutoIt lags a little when asked to cope. ;)

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

#6 ·  Posted (edited)

I have OCD! haha it must be perfect! Ok ok not perfect, but I would expect it to behave "like" a proper windows form would. 

Digging around in the forums I have unearthed a post! all credit here goes to user "binhnx"

My test script works perfectly - on resizes, maximizes and restores. It also handles the Windows 7 Aero interface snaps :)

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

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

$hgui = GUICreate("test", 300, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_POPUP))
GUISetState()
$hgui1 = GUICreate("", 280, 280, 5, 5, $WS_POPUP, $WS_EX_MDICHILD, $hgui)
GUISetBkColor(0x444444)
GUISetState()
$hgui2 = GUICreate("", 265, 265, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hgui1)
GUISetBkColor(0x666666)
GUISetState()
$hgui3 = GUICreate("", 250, 250, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hgui2)
GUISetBkColor(0x888888)
GUISetState()
$hgui4 = GUICreate("", 235, 235, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hgui3)
GUISetBkColor(0xaaaaaa)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            exit
    EndSwitch
WEnd

Func WM_SIZE($hwnd, $uMsg, $wParam, $lParam)
    ;hardcoded my offsets for simiplicty of the example
    _WinAPI_SetWindowPos($hgui1, 0, 0, 0, _WinAPI_LoWord($lParam)-20, _WinAPI_HiWord($lParam)-20,BitOR($SWP_NOMOVE, $SWP_NOZORDER))
    _WinAPI_SetWindowPos($hgui2, 0, 0, 0, _WinAPI_LoWord($lParam)-35, _WinAPI_HiWord($lParam)-35,BitOR($SWP_NOMOVE, $SWP_NOZORDER))
    _WinAPI_SetWindowPos($hgui3, 0, 0, 0, _WinAPI_LoWord($lParam)-50, _WinAPI_HiWord($lParam)-50,BitOR($SWP_NOMOVE, $SWP_NOZORDER))
    _WinAPI_SetWindowPos($hgui4, 0, 0, 0, _WinAPI_LoWord($lParam)-65, _WinAPI_HiWord($lParam)-65,BitOR($SWP_NOMOVE, $SWP_NOZORDER))
    Return 1
EndFunc
Edited by JakeKenmode

Share this post


Link to post
Share on other sites

JakeKenmode,

Bravo!! :thumbsup:

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

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

  • Similar Content

    • drego
      By drego
      It's been requested in the past to have multithreading to which the response was "It would take too much redesigning of Autoit" but what about Async? Multithreading and Async are two different things. This way we could put tasks in the background without having to fork processes. Right? Also better event handling would be nice rather than throwing everything in a while loop we could have some functionality like javascript which seems to be far more responsive and reliable as the more you add to your while loop the less change there is of your "event" getting caught for some reason (At least in my experience).
    • lbsl
      By lbsl
      Hi folks,
      I've been happily abusing this forum resources (and many others as well) for over three years now to get stuff done in AutoIT3.
      I'm currently stuck at a point where i need to fake some sort of multithreading.
      I know AutoIT3 does not and will not support it, but if there only was a good way to tap into the full event trapping cycle of the AU3 engine, i could at least add in some of the routines that need a checkup.
      I figured so far that using the GuiOnEventMode and TrayOnEventMode should allow me to give me this opportunity, but unfortunately, it doesn't.
      I have extended the existing Au3 examples for both options with a counter to show what i mean:
      #include <GUIConstantsEx.au3> #include <Constants.au3> #NoTrayIcon Global $x = 1 Example() Func Example() Opt("GUICoordMode", 2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_SECONDARYDOUBLE, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, "SpecialEvent") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "SpecialEvent") TraySetState() Local $WinHandle = GUICreate("Parent1") ConsoleWrite("WinHandle:" & Hex($WinHandle, 8) & @CRLF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlCreateButton("OK", 10, 30, 50) GUICtrlSetOnEvent(-1, "OKPressed") GUICtrlCreateButton("Cancel", 0, -1) GUICtrlSetOnEvent(-1, "CancelPressed") GUICtrlCreateEdit("A small text box with some text in it to test the scrollbar clicking" & @CRLF & @CRLF & @CRLF & @CRLF & "and a couple of lines, click and drag the scrollbars to stop the counter", 80, 80, 180, 100) GUICtrlSetOnEvent(-1, "EditTouched") GUISetState(@SW_SHOW) ; Just idle around While 1 Sleep(500) ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 WEnd EndFunc ;==>Example Func EditTouched() ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle) EndFunc ;==>EditTouched Func OKPressed() ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle) EndFunc ;==>OKPressed Func CancelPressed() ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle) EndFunc ;==>CancelPressed Func SpecialEvents() ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Case @GUI_CtrlId = $GUI_EVENT_RESTORE ConsoleWrite("Testing message loop:" & $x & @CRLF) $x += 1 MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) EndSelect EndFunc ;==>SpecialEvents Func SpecialEvent() Select Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOUBLE MsgBox(64, "SpecialEvent-Info", "Primary mouse button double clicked.") Case @TRAY_ID = $TRAY_EVENT_SECONDARYUP MsgBox(64, "SpecialEvent-Info", "Secondary mouse button clicked.") EndSelect EndFunc ;==>SpecialEvent Func ExitEvent() Exit EndFunc ;==>ExitEvent The counter keeps updating the console output, until you hover above a Tray context menu or you click and hold down any of the scrollbars.
      The counter that i am running in the background here is in my real life a network process that needs to clear a message buffer from time to time.
      I have two applications in Autoit3 running, one server that is doing all the network activity and no GUI related stuff at all and i attach a client to it that has to exchange messages with the server to at least be able to command it up to some level.
      However whenever that message buffer of this client stalls, the server that is broadcasting the ACK messages will also stall eventually because his buffers do not get cleared.
      I have considered using an Sqlite database in WAL mode to exchange messages between the two apps and even if that can work mighty fast, it looks clumsy, but it ensures me that my client app will not crash on partial messages or miss out on messages.
      But if anyone can guide me to a trick where i could at least have all functions called in a processing loop without the AutoIT engine being able to stall that process, in other words:how can i keep that counter "running" at all cost?
      Thanks in advance!
    • Anepopane
      By Anepopane
      Hi,   this is the example code for function GUICtrlSetResizing: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Example() Func Example() Local $nEdit, $nOk, $nCancel, $msg Opt("GUICoordMode", 2) GUICreate("My InputBox", 190, 114, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) ; start the definition GUISetIcon("Eiffel Tower.ico") GUISetFont(8, -1, "Arial") GUICtrlCreateLabel("Prompt", 8, 7) ; add prompt info GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP) $nEdit = GUICtrlCreateInput("Default", -1, 3, 175, 20, $ES_PASSWORD) ; add the input area GUICtrlSetState($nEdit, $GUI_FOCUS) GUICtrlSetResizing($nEdit, $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT) $nOk = GUICtrlCreateButton("OK", -1, 3, 75, 24) ; add the button that will close the GUI GUICtrlSetResizing($nOk, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE + $GUI_DOCKHCENTER) $nCancel = GUICtrlCreateButton("Annuler", 25, -1) ; add the button that will close the GUI GUICtrlSetResizing($nCancel, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE + $GUI_DOCKHCENTER) GUISetState() ; to display the GUI ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc   ;==>Example Is it somehow possible to make a GUI resizable, but to define a size which is the minimum?
      I want to make a GUI similar to the one in the example which is resizable but would not get so small that some of the elements wouldn't be visible anymore. I am out of ideas ...
      Thanks for any help.