Sign in to follow this  
Followers 0
SandelPerieanu

Button & _GUICtrlStatusBar_EmbedControl

4 posts in this topic

#1 ·  Posted (edited)

hi,

i try put a button into statusbar, but with _GUICtrlStatusBar_EmbedControl don't work ... MsgBox(262144, '', 'Button is pressed!') will not appear

#include <GuiStatusBar.au3>
Local $aparts[3] = [80, 160, -1]
$hgui = GUICreate("StatusBar Embed Control", 400, 300)
$hstatus = _GUICtrlStatusBar_Create($hgui)
GUISetState()
_GUICtrlStatusBar_SetParts($hstatus, $aparts)
_GUICtrlStatusBar_SetText($hstatus, "Part 1")
_GUICtrlStatusBar_SetText($hstatus, "Part 2", 1)
$button = GUICtrlCreateButton('Ok', 0, 0)
_GUICtrlStatusBar_EmbedControl($hstatus, 2, GUICtrlGetHandle($button))
GUISwitch($hgui)
While 1
   $msg = GUIGetMsg()
   If $msg = $button Then MsgBox(262144, '', 'Button is pressed!')
   If $msg = -3 Then Exit 0
WEnd

without

_GUICtrlStatusBar_EmbedControl($hstatus, 2, GUICtrlGetHandle($button))

it show me the message: 'Button is pressed!'

thanks

Edited by psandu.ro

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I tried displaying an array coming back from GuiGetMsg and I don't see any kind of msg being returned when that message comes up.

Maybe someone who's done this before will have some ideas.

For now you could just embed a label and then position the button in the right part of the status bar over it?

As long as the window isn't resized that is.

Kenny

Edited by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hi,

i try put a button into statusbar, but with _GUICtrlStatusBar_EmbedControl don't work ... MsgBox(262144, '', 'Button is pressed!') will not appear

#include <GuiStatusBar.au3>
Local $aparts[3] = [80, 160, -1]
$hgui = GUICreate("StatusBar Embed Control", 400, 300)
$hstatus = _GUICtrlStatusBar_Create($hgui)
GUISetState()
_GUICtrlStatusBar_SetParts($hstatus, $aparts)
_GUICtrlStatusBar_SetText($hstatus, "Part 1")
_GUICtrlStatusBar_SetText($hstatus, "Part 2", 1)
$button = GUICtrlCreateButton('Ok', 0, 0)
_GUICtrlStatusBar_EmbedControl($hstatus, 2, GUICtrlGetHandle($button))
GUISwitch($hgui)
While 1
   $msg = GUIGetMsg()
   If $msg = $button Then MsgBox(262144, '', 'Button is pressed!')
   If $msg = -3 Then Exit 0
WEnd

without

_GUICtrlStatusBar_EmbedControl($hstatus, 2, GUICtrlGetHandle($button))

it show me the message: 'Button is pressed!'

thanks

@psandu.ro

_GUICtrlStatusBar_Create() (CreateWindowEx API child window) is not a native AutoIt control, so it does not have its messages

processed by the MessageLoop or OnEvent mode.

you have to subclass the StatusBar window to receive messages from any embedded controls

otherwise you have to read the control directly by control ID (GuiCtrlRead()) or by handle.

try this example

Cheers

Edit replaced first example with code to handle button repaint and resizing

as there are issues with embedded controls not being repainted or resized with parent gui

;the usual paint and resize issues apply with the StatusBar not being native AutoIt code
;Note: if using a resizable gui you need to recalculate StatusBar parts
#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

#include <GuiStatusBar.au3>
#include <GuiButton.au3>

Local $aparts[3] = [80, 160, -1]
$hgui = GUICreate("StatusBar Embed Control", 400, 300, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX,$WS_MAXIMIZEBOX))
$button = GUICtrlCreateButton('Ok', 0, 0, 100, 20)

$hstatus = _GUICtrlStatusBar_Create($hgui)
_GUICtrlStatusBar_SetParts($hstatus, $aparts)
_GUICtrlStatusBar_SetText($hstatus, "Part 1")
_GUICtrlStatusBar_SetText($hstatus, "Part 2", 1)

;$hBtnStatusBar = _GUICtrlButton_Create($hgui, "Ok", 0, 0, 0, 0)
$cBtnStatusBar = GUICtrlCreateButton('Ok', 0, 0)
$hBtnStatusBar = GUICtrlGetHandle($cBtnStatusBar)
$cBtnDummy = GUICtrlCreateDummy()
_GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar)

; subclass StatusBar window:
$wProcNew = DllCallbackRegister("_StatusBarWindowProc", "int", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ;Delete StatusBar window callback function
            _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, $wProcOld)
            DllCallbackFree($wProcNew)
            Exit 0
        Case $button
            MsgBox(262144, '', 'Main form button is pressed!')
        Case $cBtnDummy
            MsgBox(262144, '', 'StatusBar button is pressed!')
    EndSwitch
WEnd

Func _WM_SIZE()
    _GUICtrlStatusBar_Resize($hstatus)
    Return $GUI_RUNDEFMSG
EndFunc

Func _StatusBarWindowProc($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)

    Switch $Msg
        Case $WM_COMMAND
            Switch $lParam
                Case $hBtnStatusBar
                    ;ConsoleWrite('-$nID = ' & $nID & @crlf) 
                    ;ConsoleWrite('-$nNotifyCode = ' & $nNotifyCode & @crlf) 
                    Switch $nNotifyCode
                        Case $BN_CLICKED
                            GUICtrlSendToDummy($cBtnDummy)
                            ;ConsoleWrite("$BN_CLICKED" & @CRLF)
                    EndSwitch
            EndSwitch
        Case $WM_NCPAINT ;update button position when StatusBar repainted (when gui resized or restored from minimized)
            ;must be better way of doing this
            _GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar)
    EndSwitch
    ; pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>_NewWindowProc
Edited by rover
1 person likes this

I see fascists...

Share this post


Link to post
Share on other sites

@psandu.ro

_GUICtrlStatusBar_Create() (CreateWindowEx API child window) is not a native AutoIt control, so it does not have its messages

processed by the MessageLoop or OnEvent mode.

you have to subclass the StatusBar window to receive messages from any embedded controls

otherwise you have to read the control directly by control ID (GuiCtrlRead()) or by handle.

try this example

Cheers

Edit replaced first example with code to handle button repaint and resizing

as there are issues with embedded controls not being repainted or resized with parent gui

;the usual paint and resize issues apply with the StatusBar not being native AutoIt code
;Note: if using a resizable gui you need to recalculate StatusBar parts
#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

#include <GuiStatusBar.au3>
#include <GuiButton.au3>

Local $aparts[3] = [80, 160, -1]
$hgui = GUICreate("StatusBar Embed Control", 400, 300, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX,$WS_MAXIMIZEBOX))
$button = GUICtrlCreateButton('Ok', 0, 0, 100, 20)

$hstatus = _GUICtrlStatusBar_Create($hgui)
_GUICtrlStatusBar_SetParts($hstatus, $aparts)
_GUICtrlStatusBar_SetText($hstatus, "Part 1")
_GUICtrlStatusBar_SetText($hstatus, "Part 2", 1)

;$hBtnStatusBar = _GUICtrlButton_Create($hgui, "Ok", 0, 0, 0, 0)
$cBtnStatusBar = GUICtrlCreateButton('Ok', 0, 0)
$hBtnStatusBar = GUICtrlGetHandle($cBtnStatusBar)
$cBtnDummy = GUICtrlCreateDummy()
_GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar)

; subclass StatusBar window:
$wProcNew = DllCallbackRegister("_StatusBarWindowProc", "int", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ;Delete StatusBar window callback function
            _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, $wProcOld)
            DllCallbackFree($wProcNew)
            Exit 0
        Case $button
            MsgBox(262144, '', 'Main form button is pressed!')
        Case $cBtnDummy
            MsgBox(262144, '', 'StatusBar button is pressed!')
    EndSwitch
WEnd

Func _WM_SIZE()
    _GUICtrlStatusBar_Resize($hstatus)
    Return $GUI_RUNDEFMSG
EndFunc

Func _StatusBarWindowProc($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)

    Switch $Msg
        Case $WM_COMMAND
            Switch $lParam
                Case $hBtnStatusBar
                    ;ConsoleWrite('-$nID = ' & $nID & @crlf) 
                    ;ConsoleWrite('-$nNotifyCode = ' & $nNotifyCode & @crlf) 
                    Switch $nNotifyCode
                        Case $BN_CLICKED
                            GUICtrlSendToDummy($cBtnDummy)
                            ;ConsoleWrite("$BN_CLICKED" & @CRLF)
                    EndSwitch
            EndSwitch
        Case $WM_NCPAINT ;update button position when StatusBar repainted (when gui resized or restored from minimized)
            ;must be better way of doing this
            _GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar)
    EndSwitch
    ; pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>_NewWindowProc
thank you..

i understand now...

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