Jump to content
Sign in to follow this  
jennico

please help with embedded control in the statusbar of a sizeable GUI

Recommended Posts

jennico

please help and see my example.

when you size or minimize the gui, the embedded progress bar vanishes. i tried some things in WM_Size, but don't know further. maybe just recreate it all the time ?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiStatusBar.au3>
#include <ProgressConstants.au3>

Global Const $S32 = "shell32.dll", $K32 = "Kernel32.dll", $U32 = "User32.dll", $INT = "int", $HWN = "hwnd", $STR = "str", $LPA = "lparam", $WPA = "wparam", $PTR = "ptr", $UIN = "uint" 
Global Const $aParts[6] = [83, 173, 270, 375, 455, -1]

;gui
$Child = GUICreate("resize embedded progressbar", 371, 245, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_MAXIMIZEBOX), $WS_EX_ACCEPTFILES)

;statusbar
$hInstance = DllCall($K32, $HWN, "GetModuleHandle", $PTR, 0)
$StatusBar = DllCall($U32, $HWN, "CreateWindowEx", $INT, 0, _;ExStyle
        $STR, "msctls_statusbar32", $STR, "", $INT, BitOR($__STATUSBARCONSTANT_WS_CHILD, $__STATUSBARCONSTANT_WS_VISIBLE), _;Style
        $INT, 0, $INT, 0, $INT, 0, $INT, 0, $HWN, $Child, $HWN, 10000, $HWN, $hInstance[0], $PTR, 0)

;parts
$struct_parts = DllStructCreate("int[" & UBound($aParts) & "]")
For $i = 0 To UBound($aParts) - 1
    DllStructSetData($struct_parts, 1, $aParts[$i], $i + 1)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $SB_SETPARTS, $WPA, $i + 1, $PTR, DllStructGetPtr($struct_parts))
Next

;progress
$Progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress)
DllCall($U32, $LPA, "SendMessage", $HWN, $hProgress, $INT, $PBM_SETMARQUEE, $WPA, 1, $LPA, 200)
DllCall($U32, $HWN, "SetParent", $HWN, $hProgress, $HWN, $StatusBar[0])
DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

GUISetState()

Do
Until GUIGetMsg()=-3

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
;   that's what i have tried    
    DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)
    GUICtrlSetState($Progress,16)
;
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_SIZE

thx j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
BrettF
jennico

hi brett, maybe u missed, that i have statusbar resize in WM_Size function !

DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)

i found a solution meanwhile. instead of WM_Size i have to use WM_ExitSizeMove (much better) !!! :

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiStatusBar.au3>
#include <ProgressConstants.au3>

Global Const $S32 = "shell32.dll", $K32 = "Kernel32.dll", $U32 = "User32.dll", $INT = "int", $HWN = "hwnd", $STR = "str", $LPA = "lparam", $WPA = "wparam", $PTR = "ptr", $UIN = "uint" 
Global Const $aParts[6] = [83, 173, 270, 375, 455, -1]
Global Const $WM_EXITSIZEMOVE=0x0232
Global $StaBarIcon[6]

;gui
$Child = GUICreate("resize embedded progressbar", 371, 245, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_MAXIMIZEBOX), $WS_EX_ACCEPTFILES)

;statusbar
$hInstance = DllCall($K32, $HWN, "GetModuleHandle", $PTR, 0)
$StatusBar = DllCall($U32, $HWN, "CreateWindowEx", $INT, 0, _   ;ExStyle
        $STR, "msctls_statusbar32", $STR, "", $INT, BitOR($__STATUSBARCONSTANT_WS_CHILD, $__STATUSBARCONSTANT_WS_VISIBLE), _    ;Style
        $INT, 0, $INT, 0, $INT, 0, $INT, 0, $HWN, $Child, $HWN, 10000, $HWN, $hInstance[0], $PTR, 0)

;parts
$struct_parts = DllStructCreate("int[" & UBound($aParts) & "]")
For $i = 0 To UBound($aParts) - 1
    DllStructSetData($struct_parts, 1, $aParts[$i], $i + 1)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $SB_SETPARTS, $WPA, $i + 1, $PTR, DllStructGetPtr($struct_parts))
Next

;progress
$Progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress)
DllCall($U32, $LPA, "SendMessage", $HWN, $hProgress, $INT, $PBM_SETMARQUEE, $WPA, 1, $LPA, 200)
DllCall($U32, $HWN, "SetParent", $HWN, $hProgress, $HWN, $StatusBar[0])
DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)

;GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_EXITSIZEMOVE")

GUISetState()

Do
Until GUIGetMsg()=-3
    
For $i = 0 To 5
    DllCall($U32, $INT, "DestroyIcon", $HWN, $StaBarIcon[$i])
Next

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
;   that's what i have tried    
    DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)
    GUICtrlSetState($Progress,16)
;
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func WM_EXITSIZEMOVE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
    DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)
    Return $GUI_RUNDEFMSG
EndFunc

but it still vanishes on minimize-maximimize action....

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
BrettF

Why aren't you using the UDF?

Its all there available for you to use under _GUICtrlStatusBar_*...

I don't ever see the point of doing it the hard way, when the easier way is better.

Cheers,

Brett

Share this post


Link to post
Share on other sites
jennico

the question is, why use the udf if you can do it the easier way without ? :)

but seriously, if you examine my script you will find one and another reasons for not using the udf in a script. i regard them rather as interesting tutorials.

but maybe anyone to help with the minimax issue ?

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
jennico

got another solution:

i need them all:

WM_Size

WM_ExitSizeMove

$gui_event_maximize

$gui_event_restore

$gui_event_resized ?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiStatusBar.au3>
#include <ProgressConstants.au3>

Opt("GUIOnEventMode", 1)

Global Const $S32 = "shell32.dll", $K32 = "Kernel32.dll", $U32 = "User32.dll", $INT = "int", $HWN = "hwnd", $STR = "str", $LPA = "lparam", $WPA = "wparam", $PTR = "ptr", $UIN = "uint" 
Global Const $aParts[6] = [83, 173, 270, 375, 455, -1]
Global Const $WM_EXITSIZEMOVE = 0x0232
Global $StaBarIcon[6]

;gui
$Child = GUICreate("resize embedded progressbar", 371, 245, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_MAXIMIZEBOX), $WS_EX_ACCEPTFILES)

;statusbar
$hInstance = DllCall($K32, $HWN, "GetModuleHandle", $PTR, 0)
$StatusBar = DllCall($U32, $HWN, "CreateWindowEx", $INT, 0, _   ;ExStyle
        $STR, "msctls_statusbar32", $STR, "", $INT, BitOR($__STATUSBARCONSTANT_WS_CHILD, $__STATUSBARCONSTANT_WS_VISIBLE), _    ;Style
        $INT, 0, $INT, 0, $INT, 0, $INT, 0, $HWN, $Child, $HWN, 10000, $HWN, $hInstance[0], $PTR, 0)

;parts
$struct_parts = DllStructCreate("int[" & UBound($aParts) & "]")
For $i = 0 To UBound($aParts) - 1
    DllStructSetData($struct_parts, 1, $aParts[$i], $i + 1)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $SB_SETPARTS, $WPA, $i + 1, $PTR, DllStructGetPtr($struct_parts))
Next

;progress
$Progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_MARQUEE)
$hProgress = GUICtrlGetHandle($Progress)
DllCall($U32, $LPA, "SendMessage", $HWN, $hProgress, $INT, $PBM_SETMARQUEE, $WPA, 1, $LPA, 200)
DllCall($U32, $HWN, "SetParent", $HWN, $hProgress, $HWN, $StatusBar[0])
DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)

GUIRegisterMsg($WM_SIZE, "WM_EXITSIZEMOVE")
GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_EXITSIZEMOVE")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "WM_EXITSIZEMOVE");= -6
GUISetOnEvent($GUI_EVENT_RESTORE, "WM_EXITSIZEMOVE"); = -5
;$GUI_EVENT_RESIZED = -12

GUISetState()

Do
Until GUIGetMsg() = -3

For $i = 0 To 5
    DllCall($U32, $INT, "DestroyIcon", $HWN, $StaBarIcon[$i])
Next

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
    ;   that's what i have tried
    DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)
    GUICtrlSetState($Progress, 16)
    ;
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func WM_EXITSIZEMOVE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar[0], $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
    DllCall($U32, $INT, "MoveWindow", $HWN, $hProgress, $INT, $aParts[1] + 3, $INT, 3, $INT, $aParts[2] - $aParts[1] - 3, $INT, 16, $INT, 1)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_EXITSIZEMOVE

but i would prefer a more universal solution (without oneventmode).

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
rasim

@jennico

Example:

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

Global $iResize = 0

Dim $aPartsEdge[2] = [100, 100]
Dim $aPartsText[1] = ["MyStatusBar"]

$hGUI = GUICreate("Test GUI", 300, 200, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))

$hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartsEdge, $aPartsText)

$cProgressBar = GUICtrlCreateProgress(0, 0, -1, -1)
GUICtrlSetData(-1, 50)
$hProgressBar = GUICtrlGetHandle($cProgressBar)

_GUICtrlStatusBar_EmbedControl($hStatusBar, 1, $hProgressBar)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

GUISetState()

Do
    If $iResize Then
        $iResize = 0
        _GUICtrlStatusBar_EmbedControl($hStatusBar, 1, $hProgressBar)
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    $iResize = 1
    _GUICtrlStatusBar_Resize($hStatusBar)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

:)

Share this post


Link to post
Share on other sites
jennico

i will try that in my - more complicated - main script, thx. :)

no, my last attempt was better. the control doesn't stay stable on dropevent. :o

no, not working at all.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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  

×