Jump to content

Clickable Objecs in Statusbar [solved]


BAM5
 Share

Recommended Posts

I've looked through the forums and the help file, but I can't figure out why the button or pic objects that work out of the status bar in the gui don't work while in the status bar.

Neither events nor GUIGetMsg works.

Could someone explain what's happening here?

Edited by BAM5

[center]JSON Encoding UDF[/center]

Link to comment
Share on other sites

I'll write one up right now.

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

;~ Opt("GUIOnEventMode", 1)

Dim $parts[1] = [-1]

$main = GUICreate("Statusbar clicking", 377, 80, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$status = _GUICtrlStatusBar_Create($main)
_GUICtrlStatusBar_SetMinHeight($status, 27)
_GUICtrlStatusBar_SetParts($status, $parts)
$_button = GUICtrlCreateButton("This CAN'T trigger anything", 0, 0, 150, 22)
;~ GUICtrlSetOnEvent(-1, "click")
$_hndl = GUICtrlGetHandle($_button)
_GUICtrlStatusBar_EmbedControl($status, 0, $_hndl, 3)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)

    Switch GUIGetMsg()
        Case $_button
            MsgBox(0, "Awesome", "This works"); doesn't actually work :(

        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func close()
    Exit
EndFunc

Func click()
    MsgBox(0, "Awesome", "This works"); doesn't actually work :(
EndFunc

I included both methods, GUIGetMsg and Events.

Edited by BAM5

[center]JSON Encoding UDF[/center]

Link to comment
Share on other sites

I see now. The problem is that messages from the button are going to the status bar process, which is separate from the GUI's. You have to subclass the status bar, which tells it to send messages to a function in your script. Here's a working example by rover:

;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 PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...