Sign in to follow this  
Followers 0
Jack023

How to "freeze" a gui?

6 posts in this topic

Hey all,

I'm making an api for a website and make my own gui with it.

I read from website and that changes the labels inside the gui, but because it can't run at same time all the labels will change after each other - IMO this is ugly.

Is there a way to freeze the gui?

And when all the fuctions are done it will unfreeze it so all labels change in 1 time?

Got it what i mean?

Greets,

Jack

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Share this post


Link to post
Share on other sites

Thanks, i will check this out tommorow ! Thanks mate

Share this post


Link to post
Share on other sites

Nope tried it but even when it's locked it will change the labels

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hmm, some of the other controls allow you to lock them while updates are made and then unlock them (_GUICtrlComboBox_BeginUpdate, _GUICtrlEdit, GUICtrlListBox, etc.) , but there does not appear to be a UDF for this func with Label controls. 

Maybe you could collect the info first then apply it to the labels quickly at the end?

I'll look at the UDFs for the func I mentioned and see if that is something that can be adapted to labels.

 

edit:

I tried crafting a BeginUpdate and EndUpdate func for the labels but it's not very good.  When I update the "locked" label it goes blank and I have to forcibly refresh/redraw it after unlock.  Ther's prob a more ekegant way to do this, but considering even if the lock/unlock worked differently I'd probably opt to update all the labels at once anyways.

Someone else want to chime in?

 

Here's my lousy example.

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

#include <SendMessage.au3>
Global Const $__LABELCONSTANT_WM_SETREDRAW = 0x000B

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 200, 264, 161, 57)
$Label1 = GUICtrlCreateLabel("This is my label", 112, 48, 283, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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


Func _UpdateLabel()
    $msg = InputBox("Change Label","","This is my updated label")
    If Not $msg Then Return 0
    MsgBox(0,"Freezing Label Control","")
    _GUICtrlLabel_BeginUpdate($Label1)
    MsgBox(0,"Setting new text for label control","")
    GUICtrlSetData($Label1, $msg)
    MsgBox(0,"Click OK to Unfrezze label control","")
    _GUICtrlLabel_EndUpdate($Label1)
    MsgBox(0,"Redraw Label Control","")
    GUICtrlSetData($Label1, GUICtrlRead($Label1))
EndFunc

Func _GUICtrlLabel_BeginUpdate($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Return _SendMessage($hWnd, $__LABELCONSTANT_WM_SETREDRAW) = 0
EndFunc

Func _GUICtrlLabel_EndUpdate($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Return _SendMessage($hWnd, $__LABELCONSTANT_WM_SETREDRAW, 1) = 0
EndFunc

Edited by spudw2k

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It's easier to just stop painting the entire window, rather than aiming the $WM_SETREDRAW (already defined in WindowsConstants) at an individual label...

_SendMessage($Form1, $WM_SETREDRAW, False)
; ...
_SendMessage($Form1, $WM_SETREDRAW, True)
_WinAPI_RedrawWindow($Form1)

This works fine for multiple control updates or whatever, though if (for example) you physically resize a non-drawing window larger than the old client area, the window will resize (even though it won't paint), so the "new" area will look oddly black until the final API redraw kicks it back into action.  But that's the only real caveat I've run into.  That said, a non-redrawing window is also more susceptible to losing its z-order when focus is lost (as in your example above using msgbox's), so disabling redraw for extended periods (or when other windows are spawned) wouldn't be recommended.

Edited by Kilmatead

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  
Followers 0