Jump to content

Status Bar


rysiora
 Share

Recommended Posts

A nice StatusBar window in AutoIT. Help me figure out how to Set and Get the StatusBar text.

#include <GUIConstants.au3>
Const $CCS_TOP = 0x1
Const $SBARS_SIZEGRIP = 0x100
Const $SB_SETTEXT = 0x0401
Const $SB_GETTEXT = 0x0402

$Main = GUICreate("StatusBar GUI")
GUISetState (@SW_SHOW)

$StatusBar = DllCall("comctl32.dll","long", "CreateStatusWindow", "long", BitOR($WS_CHILD,$WS_VISIBLE,$SBARS_SIZEGRIP), "str", "AutoIt Status Bar","hwnd",$Main,"int",0)
MsgBox(0,'StatusBar Handle',$StatusBar[0])

GUICtrlSendMsg($StatusBar[0],$SB_SETTEXT,0,"New Text"); does not work.
$ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_SETTEXT, "int", 0, "str", "New Text"); does not work.
$pet = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_GETTEXT, "int", 0, "int", 0); does not work.

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

a bit easier

#include <GUIConstants.au3>
$Main = GUICreate("StatusBar GUI")
$in = GUICtrlCreateInput("type new StatusBar text here", 50, 50, 200, 20)
$set = GUICtrlCreateButton("set text", 270, 50, 80, 20)
$label = GUICtrlCreateLabel("StatusBar Text", 0, 380, 400, 20, $SS_SUNKEN + $SS_CENTER)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $set Then GUICtrlSetData($label, (GUICtrlRead($in)))
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

8

NEWHeader1.png

Link to comment
Share on other sites

@rysiora

:P Nice script.

I was looking for some way to display the Status Bar control through API. While I got many Visual Basic examples, I could not convert them to AutoIt because I'm not very good with the DLLStruct stuff.

The line to set the status bar text works. (WinXP Pro SP2)

The next line to get the status bar text does not work. This probably need use of DllStruct to create a buffer to recieve the Status Bar text. Also it requires that you specify the Status Bar panel number from where you want to retrieve the text.

As I said, I cannot help you with this. I'm sure other advanced members will be able to come up with some sort of UDF to wrap the API DllCalls for the Status Bar functions.

Thanks for the excellent script. I'll look into it in more detail in the next few days.

Regards,

Tonedeaf

Link to comment
Share on other sites

  • Developers

$StatusBar = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD, $WS_VISIBLE, $SBARS_SIZEGRIP), "str", "AutoIt Status Bar", "hwnd", $Main, "int", 0)
sleep(3000)
$ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_SETTEXT, "int", 0, "strptr", "New Text"); does work !!!!.

Edit: And this will read it:

$pet = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_GETTEXT, "int", 0, "strptr", ""); does not work.
For $x = 1 to 4
    ConsoleWrite('@@ Debug(12) : $pet[' &$x &'] = ' & $pet[$x] & @lf)
Next
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

a bit easier

#include <GUIConstants.au3>
$Main = GUICreate("StatusBar GUI")
$in = GUICtrlCreateInput("type new StatusBar text here", 50, 50, 200, 20)
$set = GUICtrlCreateButton("set text", 270, 50, 80, 20)
$label = GUICtrlCreateLabel("StatusBar Text", 0, 380, 400, 20, $SS_SUNKEN + $SS_CENTER)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $set Then GUICtrlSetData($label, (GUICtrlRead($in)))
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

I love this code.

nice job.

8

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

@JdeB

It works very nice, thanks! Works in beta (tested in 3.1.1 and doesn't work...)

Check it out:

#include <GuiConstants.au3>
#include <GuiListView.au3>

Const $CCS_TOP = 0x1
Const $SBARS_SIZEGRIP = 0x100
Const $SB_SETTEXT = 0x401
Const $SB_GETTEXT = 0x402
Const $SB_GETTEXTLENGTH = 0x403
Const $SB_SETPARTS = 0x404
Const $SB_GETPARTS = 0x406

$Main = GUICreate("ListView Get Hot Item", 392, 322)
$StatusBar = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD,$WS_VISIBLE), "str", "AutoIt Status Bar", "hwnd", $Main, "int", 0)

$ListView = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149, BitOR($LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_NOSORTHEADER), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_REGIONAL))
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)
$Btn_Exit = GUICtrlCreateButton("Exit", 150, 260, 70, 30)
$Current = _GUICtrlListViewGetHotItem($ListView)
GUISetState()

While 1
$msg = GUIGetMsg()
$Item = _GUICtrlListViewGetHotItem($ListView)
Select
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
        ExitLoop
    Case Else
        $pos = GUIGetCursorInfo()
        If ($pos[4] == $listview) Then
            If ($Current <> $Item And $Item >= 0) Then
                DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_SETTEXT, "int", 0, "strptr", "Hot Item: " & $Item)
                $Current = $Item
            ElseIf ($Item == -1) Then
                DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar[0], "int", $SB_SETTEXT, "int", 0, "strptr", "")
                $Current = -1
            EndIf
        EndIf
EndSelect
Sleep(1)
WEnd
Edited by rysiora
Link to comment
Share on other sites

By default, the status bar panel has only one part and the width is equal to the entire Status Bar.

I tried to add multiple parts, but failed again in DllStuct and DllCall. :P

Anyway I modified the script to specify the width of the first part

Opt("MustDeclareVars", 1)

#include <GUIConstants.au3>
#include <Array.au3>

Global Const $CCS_TOP = 0x1
Global Const $SBARS_SIZEGRIP = 0x100
Global Const $SB_SETTEXT = 0x0401
Global Const $SB_GETTEXT = 0x0402
Global Const $SB_SETPARTS = 0x0404

Local $gui, $StatusBar1, $ret1, $msg
Local $sStatusText, $iPartWidth

$iPartWidth = 100

$gui = GUICreate("StatusBar GUI")
GUISetState (@SW_SHOW)

$StatusBar1 = DllCall("comctl32.dll","long", "CreateStatusWindow", "long", BitOR($WS_CHILD,$WS_VISIBLE,$SBARS_SIZEGRIP), "str", "AutoIt Status Bar","hwnd",$gui,"int",0)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETPARTS, "int", 2, "int_ptr", $iPartWidth)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETTEXT, "int", 0, "str", "New Text")

$ret1 = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_GETTEXT, "int", 0, "strptr", "")

MsgBox(0, "Status Bar Example", "Status Bar handle: " & $StatusBar1[0] & @CRLF & _
        "Status Bar text: " & $ret1[4])

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by tonedeaf
Link to comment
Share on other sites

opt("MustDeclareVars", 1)

#include <GUIConstants.au3>
#include <Array.au3>

Global Const $CCS_TOP = 0x1
Global Const $SBARS_SIZEGRIP = 0x100
Global Const $SB_SETTEXT = 0x0401
Global Const $SB_GETTEXT = 0x0402
Global Const $SB_SETPARTS = 0x0404

Local $gui, $StatusBar1, $ret1, $msg, $ret2
Local $sStatusText, $iPartWidth

$iPartWidth = 100

$gui = GUICreate("StatusBar GUI")
GUISetState(@SW_SHOW)

$StatusBar1 = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD, $WS_VISIBLE, $SBARS_SIZEGRIP), "str", "AutoIt Status Bar", "hwnd", $gui, "int", 0)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETPARTS, "int", 2, "int_ptr", $iPartWidth)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETTEXT, "int", 0, "str", "New Text")
DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETTEXT, "int", 1, "str", "More Text")

$ret1 = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_GETTEXT, "int", 0, "strptr", "")
$ret2 = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_GETTEXT, "int", 1, "strptr", "")

MsgBox(0, "Status Bar Example", "Status Bar handle: " & $StatusBar1[0] & @CRLF & _
      "Status Bar text index(0): " & $ret1[4] & @CRLF & "Status Bar text index(1): " & $ret2[4])

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If you want to use StatusBar in GUI that has sizing box...

#include <GUIConstants.au3>

Global Const $CCS_TOP = 0x1
Global Const $CCS_NOMOVEY = 0x2
Global Const $CCS_BOTTOM = 0x3
Global Const $CCS_NORESIZE = 0x4
Global Const $CCS_NOPARENTALIGN = 0x8
Global Const $CCS_NOHILITE = 0x10
Global Const $CCS_ADJUSTABLE = 0x20
Global Const $CCS_NODIVIDER = 0x40

Global Const $SBARS_SIZEGRIP = 0x100
Global Const $SB_SETTEXT = 0x401
Global Const $SB_GETTEXT = 0x402
Global Const $SB_GETTEXTLENGTH = 0x403
Global Const $SB_SETPARTS = 0x404
Global Const $SB_GETPARTS = 0x406
Global Const $SB_GETBORDERS = 0x407
Global Const $SB_SETMINHEIGHT = 0x408
Global Const $SB_SIMPLE = 0x409
Global Const $SB_GETRECT = 0x40A
Global Const $SB_ISSIMPLE = 0x40E

$iPartWidth = 100

$gui = GUICreate("StatusBar GUI", -1, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$StatusBar1 = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD, $WS_VISIBLE, $SBARS_SIZEGRIP, $CCS_BOTTOM), "str", "AutoIt Status Bar", "hwnd", $gui, "int", 0)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETPARTS, "int", 2, "int_ptr", $iPartWidth)

DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETTEXT, "int", 0, "str", "New Text")
DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_SETTEXT, "int", 1, "str", "More Text")

$ret1 = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_GETTEXT, "int", 0, "strptr", "")
$ret2 = DllCall("user32.dll", "long", "SendMessage", "hwnd", $StatusBar1[0], "int", $SB_GETTEXT, "int", 1, "strptr", "")

MsgBox(0, "Status Bar Example", "Status Bar handle: " & $StatusBar1[0] & @CRLF & "Status Bar text index(0): " & $ret1[4] & @CRLF & "Status Bar text index(1): " & $ret2[4])

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $GUI_EVENT_RESIZED Then DllCall("user32.dll", "long", "MoveWindow", "hwnd", $StatusBar1[0], "int", 0, "int", 0, "int", 0, "int", 0)
WEnd

You have to add:

DllCall("user32.dll", "long", "MoveWindow", "hwnd", $StatusBar1[0], "int", 0, "int", 0, "int", 0, "int", 0)

Link to comment
Share on other sites

Well people, I wiped up a udf for the statusbar. Only 1 problem though, I can't seem to figure how to pass the array to $SB_SETPARTS in order to set the size of each part.

here is the Sample prog:

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1++
; Language:    English
; Description:  Statusbar Example
;
; ------------------------------------------------------------------------------


opt("MustDeclareVars", 1)
opt("GUICoordMode", 2)

#include-once
#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>

Local $gui, $StatusBar1, $ret0, $ret1, $msg, $ret2, $retl1, $retcode, $a[3], $asize[1]

$gui = GUICreate("StatusBar GUI", -1, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$a[0] = 200
$a[1] = 300
$a[2] = 350
;$a[3]=-1
;$asize = WinGetClientSize("")
;MsgBox(0, "Active window's client size is (width,height):", $asize[0] & " " & $asize[1],5)


$StatusBar1 = _GuiCtrlCreateStatusBar ($gui);,3,$a)
$retcode = _GuiCtrlStatusBarSetParts ($StatusBar1, 3, $a)

_GuiCtrlStatusBarSetText ($StatusBar1, "New Text", 0)
_GuiCtrlStatusBarSetText ($StatusBar1, "More Text", 1)
_GuiCtrlStatusBarSetText ($StatusBar1, "Even More Text", 2)
$ret0 = _GuiCtrlStatusBarGetText ($StatusBar1, 0)
$ret1 = _GuiCtrlStatusBarGetText ($StatusBar1, 1)
$ret2 = _GuiCtrlStatusBarGetText ($StatusBar1, 2)
$retl1 = _GuiCtrlStatusBarGetTextLength ($StatusBar1, 2)
;_GuiCtrlStatusBarResize($StatusBar1)
MsgBox(4096, "Status Bar Example", "Status Bar handle: " & $StatusBar1 & @CRLF & _
        "Status Bar text index(0): " & $ret0 & @CRLF & "Status Bar text index(1): " & $ret1 & @CRLF _
         & "Status Bar text index(2): " & $ret2 & @CRLF & "Status Bar  text Len index(0): " & $retl1)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_RESIZED
            _GuiCtrlStatusBarResize ($StatusBar1)
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
        ;;;;;
    EndSelect
    
WEnd
Exit
;===============================================================================
;Resize things here not handled by GuiCtrlSetResize
;===============================================================================
Func _ResizeHandler()
    _GuiCtrlStatusBarResize ($StatusBar1)
EndFunc  ;==>_ResizeHandler

and here is the UDF:

opt("MustDeclareVars", 1)
#include-once
#include <Array.au3>
#include <guiconstants.au3>
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1++
; Language:    English
; Description:  Functions that assist with the Statusbar control
;
; ------------------------------------------------------------------------------
;=== Globals
Global $debug = True

Global Const $CCS_TOP = 0x1
Global Const $CCS_NOMOVEY = 0x2
Global Const $CCS_BOTTOM = 0x3
Global Const $CCS_NORESIZE = 0x4
Global Const $CCS_NOPARENTALIGN = 0x8
Global Const $CCS_NOHILITE = 0x10
Global Const $CCS_ADJUSTABLE = 0x20
Global Const $CCS_NODIVIDER = 0x40
;=== Status Bar Styles
Global Const $SBARS_SIZEGRIP = 0x100
;=== uFlags
Global Const $SBT_SUNKEN = 0x0;Default
Global Const $SBT_NOBORDERS = 0x100;The text is drawn without borders.
Global Const $SBT_POPOUT = 0x200; The text is drawn with a border to appear higher than the plane of the window.
Global Const $SBT_RTLREADING = 0x400;SB_SETTEXT, SB_SETTEXT, SB_GETTEXTLENGTH flags only: Displays text using right-to-left reading order on Hebrew or Arabic systems.
Global Const $SBT_OWNERDRAW = 0x1000;The text is drawn by the parent window.
;=== Messages to send to Statusbar
Global Const $SB_SETTEXT = 0x401
Global Const $SB_GETTEXT = 0x402
Global Const $SB_GETTEXTLENGTH = 0x403
Global Const $SB_SETPARTS = 0x404
Global Const $SB_GETPARTS = 0x406
Global Const $SB_GETBORDERS = 0x407
Global Const $SB_SETMINHEIGHT = 0x408
Global Const $SB_SIMPLE = 0x409
Global Const $SB_GETRECT = 0x40A
Global Const $SB_ISSIMPLE = 0x40E
Global Const $LowOrder = 0xFFFF
;=== End Globals

;=== function list
;===============================================================================
;_GuiCtrlCreateStatusBar
;_GuiCtrlStatusBarSetText
;_GuiCtrlStatusBarGetText
;_GuiCtrlStatusBarGetTextLength
;_GuiCtrlStatusBarSetParts
;_GuiCtrlStatusBarGetParts
;_GuiCtrlStatusBarResize
;********** ToDo **************
;_GuiCtrlStatusBarGetBorders
;_GuiCtrlStatusBarSetMinHeight
;_GuiCtrlStatusBarGetRect
;_GUICtrlStatusBarSetExtendedStyle

;~ Private Declare Function GetAddrOf Lib "KERNEL32" Alias "MulDiv" (nNumber As Any, Optional ByVal nNumerator As Long = 1, Optional ByVal nDenominator As Long = 1) As Long
;~  ' This is the dummy function used to get the addres of a VB variable.
Func AddressOf($v_Variable)
;~  Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" _
;~ (Var() as Any) As Long
    Local $pointer
    $pointer = DllCall("KERNEL32.dll", "long", "MulDiv", "ptr", $v_Variable[0])
;$pointer =dllcall("msvbvm60.dll","long","VarPtr","long",$v_Variable[0])
    If @error Then
        If $debug then  msgbox (0, "Error:", "Error:>" & @error & @CRLF)
        Return 0
    Else
        Return $pointer
    EndIf
    
EndFunc  ;==>AddressOf
;===============================================================================
;
; Description:          _GuiCtrlCreateStatusBar
; Parameter(s):     $h_Gui  Handle to parent window
;                   $i_Panels   Nubmer of panesl to create
;                   $i_PanelWidth
; Requirement:
; Return Value(s):  Returns hWhnd if successful, or 0 with error set to 1 otherwise.
; User CallTip:     _GuiCtrlCreateStatusBar($i_Panels,$i_PanelWidth = 100) Creates Statusbar. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func    _GuiCtrlCreateStatusBar ($h_Gui);,$i_Panels,ByRef $a_PanelWidth)
    
    If Not IsHWnd($h_Gui) Then $h_Gui = HWnd($h_Gui)
    Local $hwnd_Bar1, $sta, $ptr, $emsg[6]
    $hwnd_Bar1 = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD, $WS_VISIBLE), "str", "", "hwnd", $h_Gui, "int", 0)
    
;DllCall("user32.dll", "long", "SendMessage", "hwnd", $hwnd_Bar1[0], "int", $SB_SETPARTS, "int", $i_Panels, "long_ptr",$a_PanelWidth[0])
    If Not @error Then Return $hwnd_Bar1[0]
    SetError(1)
    Return 0
EndFunc  ;==>_GuiCtrlCreateStatusBar

;===============================================================================
;
; Description:          _GuiCtrlStatusBarSetText
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $s_Data  The text to display in the panel
;                   $i_Panel  The panel to hold the text
; Requirement:
; Return Value(s):  DllCall return value
; User CallTip:     _GuiCtrlStatusBarSetText($h_Bar,$s_Data="",$i_Panel=0) Set Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarSetText($h_Bar, $s_Data = "", $i_Panel = 0)
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
    Return DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_SETTEXT, "int", $i_Panel, "str", $s_Data)
EndFunc  ;==>_GuiCtrlStatusBarSetText

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetText
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panel  The panel to retreive the text from
; Requirement:
; Return Value(s):  True on success
; User CallTip:     _GuiCtrlStatusBarGetText($h_Bar,$s_Data="",$i_Panel=0) Gets Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetText($h_Bar, $i_Panel = 0)
;== there is a built in function to use for this. See help documentation
    Local $v_Ret
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
    $v_Ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETTEXT, "int", $i_Panel, "strptr", "")
    Return $v_Ret[4]
EndFunc  ;==>_GuiCtrlStatusBarGetText

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetTextLength
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panels   Nubmer of the panesl to retrieve length from
;
; Requirement:
; Return Value(s):  Text Length
; User CallTip:     _GuiCtrlStatusBarGetTextLength ($h_Bar,$i_Panel). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetTextLength($h_Bar, $i_Panel)
    Local   $ret
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
;GetParts = SendMessage(hStatBar, SB_GETPARTS, 0, ByVal 0)
    $ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETTEXTLENGTH, "int", $i_Panel, "int", 0)
    Return $ret[0]
EndFunc  ;==>_GuiCtrlStatusBarGetTextLength 

;===============================================================================
;
; Description:          _GuiCtrlStatusBarSetParts
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panels   Nubmer of panesl to create
;                   $i_PanelWidth
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBarSetParts ($h_Bar,$i_Panels,$i_PanelWidth = 100). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarSetParts($h_Bar, $i_Panels, $a_PanelWidth = "")
    Local $sta, $emsg[6], $ptr, $dll_ret
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
    ;=== Set each panel to be same size and assign the last one the remainder
    If Not IsArray($a_PanelWidth) Then
        Dim $a_PanelWidth[$i_Panels], $panel, $size, $strPanel, $struct_Panel
        $size = WinGetClientSize("")
        For $panel = 0 To $i_Panels - 1
            $a_PanelWidth[$panel] = Int(($size[0] / $i_Panels) * $panel + 1)
        Next
        $a_PanelWidth[$i_Panels - 1] = -1
    EndIf
;== end set sizing
    
    $sta = _CreateStuctFromArray($a_PanelWidth, "int")
    If @error Then Return 0
    
    $emsg[0] = "No Error."
    $emsg[1] = "Struct not a correct struct returned by DllStructCreate."
    $emsg[2] = "Element is out of bounds."
    $emsg[3] = ""
    $emsg[4] = ""
    $emsg[5] = ""
    
    $ptr = DllStructGetPtr($sta, 1)
    If @error Then
        If $debug Then ConsoleWrite("ptr>" & $ptr & @CRLF & "Error:>" & $emsg[@error] & @CRLF)
        SetError(1)
        Return 0
    EndIf
    
    $emsg[0] = "No error."
    $emsg[1] = "Unable to use the DLL file."
    $emsg[2] = ' unknown "return type".'
    
    $dll_ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_SETPARTS, _
            "int", $i_Panels, "int_ptr", $ptr)
    If @error Then
        If $debug Then ConsoleWrite("DllCall Error:>" & $emsg[@error] & @CRLF)
        SetError(1)
        Return 0
    EndIf
;== Sometimes this needs to be called in order to update the status bar.
    _GuiCtrlStatusBarResize($h_Bar)
    Return -1
EndFunc  ;==>_GuiCtrlStatusBarSetParts 

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetParts
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;
;
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBar($h_Bar). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetParts($h_Bar)
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
;GetParts = SendMessage(hStatBar, SB_GETPARTS, 0, ByVal 0)
    Return DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETPARTS, "int", 0, "int", 0)
EndFunc  ;==>_GuiCtrlStatusBarGetParts 

;===============================================================================
;
; Description:          _GuiCtrlStatusBarResize
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBarResize($h_Bar)Resize Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarResize($h_Bar)
    If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
    Return DllCall("user32.dll", "long", "MoveWindow", "hwnd", $h_Bar, "int", 0, "int", 0, "int", 0, "int", 0)
EndFunc  ;==>_GuiCtrlStatusBarResize
;===============================================================================
;
; Description:          CreateStructFromArray
; Parameter(s):     $a_Variable array to create struct with
;                   $structType, the SINGLE type of struct to create.
; Requirement:
; Return Value(s):
; User CallTip:     _CreateStructFromArray
; Author(s):
; Note(s):
;===============================================================================

Func _CreateStuctFromArray($a_Variable, $structType)
    If Not IsArray($a_Variable) Then
        SetError(1)
        Return
    EndIf
    Local $a_ctr, $strVar, $struct, $emsg[6]
    For $a_ctr = 0 To UBound($a_Variable) - 1
        $strVar &= $structType & ";"
    Next
    $strVar = StringTrimRight($strVar, 1)
    $emsg[0] = "No Error."
    $emsg[1] = "Variable passed to DllStructCreate was not a string."
    $emsg[2] = "There is an unknown Data Type in the string passed. "
    $emsg[3] = "Failed to allocate the memory needed for the struct, or Pointer = 0."
    $emsg[4] = "Error allocating memory for the passed string."
    $emsg[5] = ""
    
    $struct = DllStructCreate($strVar)
    If @error Then
        If $debug Then MsgBox(0, "Error:", "Error:>" & $emsg[@error] & @CRLF)
        SetError(1)
        Return 0
    EndIf
    
    $emsg[0] = 'No Error. '
    $emsg[1] = 'Struct not a correct struct returned by DllStructCreate.'
    $emsg[2] = 'Element value out of range. '
    $emsg[3] = 'index would be outside of the struct.'
    $emsg[4] = 'Element data type is unknown'
    $emsg[5] = 'index < 0.'
    For $a_ctr = 0 To UBound($a_Variable) - 1
        DllStructSetData($struct, ($a_ctr) + 1, $a_Variable[$a_ctr])
        If @error Then
            If $debug Then ConsoleWrite("Set>" & $a_ctr & @CRLF & "Error:>" & $emsg[@error] & @CRLF)
            SetError(1)
            Return 0
        EndIf
    Next
    Return $struct
EndFunc  ;==>_CreateStuctFromArray

I have tried sending an array, the first element of an array ($array[0]), the struct, a ptr to the struct and a ptr to the first element of the struct.

The dllcall seems to only be picking up the first element when the first element is referenced.

Could this be a bug in DllCall???

The call is succeeding on some level as the text for the parts can be retrieved. which leads me to think that the part borders are created on top of each other.

eltorro

Link to comment
Share on other sites

@eltorro

:lmao: Nice work on the UDF.

Only 1 problem though, I can't seem to figure how to pass the array to $SB_SETPARTS in order to set the size of each part.

The call is succeeding on some level as the text for the parts can be retrieved. which leads me to think that the part borders are created on top of each other.

That is the same issue i faced. I hope someone can throw light on sending a pointer to an array in DllCall to create multiple parts in Status Bar.

Regards,

Tonedeaf

Link to comment
Share on other sites

opt("MustDeclareVars", 1)
opt("GUICoordMode", 2)

#include-once
#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>

Local $gui, $StatusBar1, $ret0, $ret1, $msg, $ret2, $retl1, $retcode, $asize[1]
Local $a[3] = [100,350,-1]
Local $s[3] = ["New Text","More Text","Even More Text"]
$gui = GUICreate("StatusBar GUI", 500, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$StatusBar1 = _GuiCtrlCreateStatusBar ($gui, $a, $s)

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_RESIZED
         _GuiCtrlStatusBarResize ($StatusBar1)
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        ;;;;;
   EndSelect
   
WEnd
;~ Exit

; second test
$gui = GUICreate("StatusBar GUI", 500, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$StatusBar1 = _GuiCtrlCreateStatusBar ($gui, -1, "testing the status bar")

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_RESIZED
         _GuiCtrlStatusBarResize ($StatusBar1)
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        ;;;;;
   EndSelect
   
WEnd
Exit

;===============================================================================
;Resize things here not handled by GuiCtrlSetResize
;===============================================================================
Func _ResizeHandler()
   _GuiCtrlStatusBarResize ($StatusBar1)
EndFunc  ;==>_ResizeHandler

opt("MustDeclareVars", 1)
#include-once
#include <Array.au3>
#include <guiconstants.au3>
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1++
; Language:    English
; Description:  Functions that assist with the Statusbar control
;
; ------------------------------------------------------------------------------
;=== Globals
Global $debug = True

Global Const $CCS_TOP = 0x1
Global Const $CCS_NOMOVEY = 0x2
Global Const $CCS_BOTTOM = 0x3
Global Const $CCS_NORESIZE = 0x4
Global Const $CCS_NOPARENTALIGN = 0x8
Global Const $CCS_NOHILITE = 0x10
Global Const $CCS_ADJUSTABLE = 0x20
Global Const $CCS_NODIVIDER = 0x40
;=== Status Bar Styles
Global Const $SBARS_SIZEGRIP = 0x100
;=== uFlags
Global Const $SBT_SUNKEN = 0x0;Default
Global Const $SBT_NOBORDERS = 0x100;The text is drawn without borders.
Global Const $SBT_POPOUT = 0x200; The text is drawn with a border to appear higher than the plane of the window.
Global Const $SBT_RTLREADING = 0x400;SB_SETTEXT, SB_SETTEXT, SB_GETTEXTLENGTH flags only: Displays text using right-to-left reading order on Hebrew or Arabic systems.
Global Const $SBT_OWNERDRAW = 0x1000;The text is drawn by the parent window.
;=== Messages to send to Statusbar
Global Const $SB_SETTEXT = 0x401
Global Const $SB_GETTEXT = 0x402
Global Const $SB_GETTEXTLENGTH = 0x403
Global Const $SB_SETPARTS = 0x404
Global Const $SB_GETPARTS = 0x406
Global Const $SB_GETBORDERS = 0x407
Global Const $SB_SETMINHEIGHT = 0x408
Global Const $SB_SIMPLE = 0x409
Global Const $SB_GETRECT = 0x40A
Global Const $SB_ISSIMPLE = 0x40E
Global Const $LowOrder = 0xFFFF
;=== End Globals

;=== function list
;===============================================================================
;_GuiCtrlCreateStatusBar
;_GuiCtrlStatusBarSetText
;_GuiCtrlStatusBarGetText
;_GuiCtrlStatusBarGetTextLength
;_GuiCtrlStatusBarSetParts
;_GuiCtrlStatusBarGetParts
;_GuiCtrlStatusBarResize
;********** ToDo **************
;_GuiCtrlStatusBarGetBorders
;_GuiCtrlStatusBarSetMinHeight
;_GuiCtrlStatusBarGetRect
;_GUICtrlStatusBarSetExtendedStyle

;~ Private Declare Function GetAddrOf Lib "KERNEL32" Alias "MulDiv" (nNumber As Any, Optional ByVal nNumerator As Long = 1, Optional ByVal nDenominator As Long = 1) As Long
;~  ' This is the dummy function used to get the addres of a VB variable.
Func AddressOf($v_Variable)
;~   Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" _
;~ (Var() as Any) As Long
   Local $pointer
   $pointer = DllCall("KERNEL32.dll", "long", "MulDiv", "ptr", $v_Variable[0])
  ;$pointer =dllcall("msvbvm60.dll","long","VarPtr","long",$v_Variable[0])
   If @error Then
      If $debug Then MsgBox(0, "Error:", "Error:>" & @error & @CRLF)
      Return 0
   Else
      Return $pointer
   EndIf
   
EndFunc  ;==>AddressOf
;===============================================================================
;
; Description:          _GuiCtrlCreateStatusBar
; Parameter(s):     $h_Gui   Handle to parent window
;                   $i_Panels   Nubmer of panesl to create
;                   $i_PanelWidth
; Requirement:
; Return Value(s):  Returns hWhnd if successful, or 0 with error set to 1 otherwise.
; User CallTip:     _GuiCtrlCreateStatusBar($i_Panels,$a_PanelWidth, $s_PanelText) Creates Statusbar. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlCreateStatusBar($h_Gui, $a_PanelWidth, $s_PanelText)
   If Not IsArray($a_PanelWidth) Then
      Local $temp_width = $a_PanelWidth
      Dim $a_PanelWidth[1] = [$temp_width]
   EndIf
   If Not IsArray($s_PanelText) Then
      Local $temp_string = $s_PanelText
      Dim $s_PanelText[1] = [$temp_string]
   EndIf
   If Not IsHWnd($h_Gui) Then $h_Gui = HWnd($h_Gui)
   Local $hwnd_Bar1, $sta, $ptr, $emsg[6], $x, $retcode
   $hwnd_Bar1 = DllCall("comctl32.dll", "long", "CreateStatusWindow", "long", BitOR($WS_CHILD, $WS_VISIBLE), "str", "", "hwnd", $h_Gui, "int", 0)
   
   If Not @error Then
      $retcode = _GuiCtrlStatusBarSetParts($hwnd_Bar1[0], UBound($a_PanelWidth), $a_PanelWidth)
      For $x = 0 To UBound($s_PanelText) - 1
         _GuiCtrlStatusBarSetText($hwnd_Bar1[0], $s_PanelText[$x], $x)
      Next
      
      Return $hwnd_Bar1[0]
   EndIf
   SetError(1)
   Return 0
EndFunc  ;==>   _GuiCtrlCreateStatusBar 

;===============================================================================
;
; Description:          _GuiCtrlStatusBarSetText
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $s_Data  The text to display in the panel
;                   $i_Panel  The panel to hold the text
; Requirement:
; Return Value(s):  DllCall return value
; User CallTip:     _GuiCtrlStatusBarSetText($h_Bar,$s_Data="",$i_Panel=0) Set Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarSetText($h_Bar, $s_Data = "", $i_Panel = 0)
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
   Return DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_SETTEXT, "int", $i_Panel, "str", $s_Data)
EndFunc  ;==>_GuiCtrlStatusBarSetText

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetText
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panel  The panel to retreive the text from
; Requirement:
; Return Value(s):  True on success
; User CallTip:     _GuiCtrlStatusBarGetText($h_Bar,$s_Data="",$i_Panel=0) Gets Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetText($h_Bar, $i_Panel = 0)
  ;== there is a built in function to use for this. See help documentation
   Local $v_Ret
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
   $v_Ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETTEXT, "int", $i_Panel, "strptr", "")
   Return $v_Ret[4]
EndFunc  ;==>_GuiCtrlStatusBarGetText

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetTextLength
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panels   Nubmer of the panesl to retrieve length from
;
; Requirement:
; Return Value(s):  Text Length
; User CallTip:     _GuiCtrlStatusBarGetTextLength ($h_Bar,$i_Panel). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetTextLength($h_Bar, $i_Panel)
   Local $ret
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
  ;GetParts = SendMessage(hStatBar, SB_GETPARTS, 0, ByVal 0)
   $ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETTEXTLENGTH, "int", $i_Panel, "int", 0)
   Return $ret[0]
EndFunc  ;==>_GuiCtrlStatusBarGetTextLength

;===============================================================================
;
; Description:          _GuiCtrlStatusBarSetParts
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;                   $i_Panels   Nubmer of panesl to create
;                   $i_PanelWidth
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBarSetParts ($h_Bar,$i_Panels,$i_PanelWidth = 100). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarSetParts($h_Bar, $i_Panels, $a_PanelWidth = "")
   Local $sta, $emsg[6], $ptr, $dll_ret
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
  ;=== Set each panel to be same size and assign the last one the remainder
   If Not IsArray($a_PanelWidth) Then
      Dim $a_PanelWidth[$i_Panels], $panel, $size, $strPanel, $struct_Panel
      $size = WinGetClientSize("")
      For $panel = 0 To $i_Panels - 1
         $a_PanelWidth[$panel] = Int(($size[0] / $i_Panels) * $panel + 1)
      Next
      $a_PanelWidth[$i_Panels - 1] = -1
   EndIf
  ;== end set sizing
   
   $sta = _CreateStuctFromArray($a_PanelWidth, "int")
   If @error Then Return 0
   
   $emsg[0] = "No Error."
   $emsg[1] = "Struct not a correct struct returned by DllStructCreate."
   $emsg[2] = "Element is out of bounds."
   $emsg[3] = ""
   $emsg[4] = ""
   $emsg[5] = ""
   
;~   $ptr = DllStructGetPtr($sta, 1)
;~   If @error Then
;~       If $debug Then ConsoleWrite("ptr>" & $ptr & @CRLF & "Error:>" & $emsg[@error] & @CRLF)
;~       SetError(1)
;~       Return 0
;~   EndIf
   
   $emsg[0] = "No error."
   $emsg[1] = "Unable to use the DLL file."
   $emsg[2] = ' unknown "return type".'
   
   $dll_ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_SETPARTS, _
         "int", $i_Panels, "ptr", DllStructGetPtr($sta))
   If @error Then
      If $debug Then ConsoleWrite("DllCall Error:>" & $emsg[@error] & @CRLF)
      SetError(1)
      Return 0
   EndIf
  ;== Sometimes this needs to be called in order to update the status bar.
   _GuiCtrlStatusBarResize($h_Bar)
   $sta = ""
   Return -1
EndFunc  ;==>_GuiCtrlStatusBarSetParts

;===============================================================================
;
; Description:          _GuiCtrlStatusBarGetParts
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;
;
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBar($h_Bar). (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarGetParts($h_Bar)
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
  ;GetParts = SendMessage(hStatBar, SB_GETPARTS, 0, ByVal 0)
   Return DllCall("user32.dll", "long", "SendMessage", "hwnd", $h_Bar, "int", $SB_GETPARTS, "int", 0, "int", 0)
EndFunc  ;==>_GuiCtrlStatusBarGetParts

;===============================================================================
;
; Description:          _GuiCtrlStatusBarResize
; Parameter(s):     $h_Bar The Control Id (will be converted to hWnd)
;
; Requirement:
; Return Value(s):
; User CallTip:     _GuiCtrlStatusBarResize($h_Bar)Resize Statusbar Text. (required: <GuiStatusBar.au3>)
; Author(s):        rysiora, JdeB, tonedef,
;                   Gary Frost (custompcs@charter.net), Steve Podhajecki <gehossafats@netmdc.com>
; Note(s):
;===============================================================================
Func _GuiCtrlStatusBarResize($h_Bar)
   If Not IsHWnd($h_Bar) Then $h_Bar = HWnd($h_Bar)
   Return DllCall("user32.dll", "long", "MoveWindow", "hwnd", $h_Bar, "int", 0, "int", 0, "int", 0, "int", 0)
EndFunc  ;==>_GuiCtrlStatusBarResize
;===============================================================================
;
; Description:          CreateStructFromArray
; Parameter(s):     $a_Variable array to create struct with
;                   $structType, the SINGLE type of struct to create.
; Requirement:
; Return Value(s):
; User CallTip:     _CreateStructFromArray
; Author(s):
; Note(s):
;===============================================================================

Func _CreateStuctFromArray($a_Variable, $structType)
   If Not IsArray($a_Variable) Then
      SetError(1)
      Return
   EndIf
   Local $a_ctr, $strVar, $struct, $emsg[6]
   For $a_ctr = 0 To UBound($a_Variable) - 1
      $strVar &= $structType & ";"
   Next
   $strVar = StringTrimRight($strVar, 1)
   $emsg[0] = "No Error."
   $emsg[1] = "Variable passed to DllStructCreate was not a string."
   $emsg[2] = "There is an unknown Data Type in the string passed. "
   $emsg[3] = "Failed to allocate the memory needed for the struct, or Pointer = 0."
   $emsg[4] = "Error allocating memory for the passed string."
   $emsg[5] = ""
   
   $struct = DllStructCreate($strVar)
   If @error Then
      If $debug Then MsgBox(0, "Error:", "Error:>" & $emsg[@error] & @CRLF)
      SetError(1)
      Return 0
   EndIf
   
   $emsg[0] = 'No Error. '
   $emsg[1] = 'Struct not a correct struct returned by DllStructCreate.'
   $emsg[2] = 'Element value out of range. '
   $emsg[3] = 'index would be outside of the struct.'
   $emsg[4] = 'Element data type is unknown'
   $emsg[5] = 'index < 0.'
   For $a_ctr = 0 To UBound($a_Variable) - 1
      DllStructSetData($struct, ($a_ctr) + 1, $a_Variable[$a_ctr])
      If @error Then
         If $debug Then ConsoleWrite("Set>" & $a_ctr & @CRLF & "Error:>" & $emsg[@error] & @CRLF)
         SetError(1)
         Return 0
      EndIf
   Next
   Return $struct
EndFunc  ;==>_CreateStuctFromArray
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

@gafrost

Thanks, a valuable lesson learned. I believe I tried int_prt and long_ptr but never tried ptr by itself.

@everyone,

We now have a working udf for the statusbar thanks to Gary.

Please keep in mind that your prog must handle the resize event for the statusbar. See Example prog.

Edit: Here is a fix for default part sizing in the GuiCtrStatusBarSetParts func.

;=== Set each panel to be same size and assign the last one the remainder
   If Not IsArray($a_PanelWidth) Then
      Dim $a_PanelWidth[$i_Panels], $panel, $size, $strPanel, $struct_Panel
      $size = WinGetClientSize("")
      For $panel = 1 To $i_Panels
         $a_PanelWidth[$panel-1] = Int(($size[0] / $i_Panels) * $panel)
     Next
     $a_PanelWidth[$i_Panels - 1] = -1
   EndIf
 ;== end set sizing

eltorro

Edited by eltorro
Link to comment
Share on other sites

You might want to add icons to your status bar

opt("MustDeclareVars", 1)

#include-once
#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>

Local $gui, $StatusBar1, $ret0, $ret1, $msg, $ret2, $retl1, $retcode, $asize[1]
Local $a[3] = [100, 350, -1]
Local $s[3] = ["New Text", "How about music", "Even More Text"]
$gui = GUICreate("StatusBar GUI", 500, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$StatusBar1 = _GuiCtrlCreateStatusBar ($gui, $a, $s)
_GuiCtlrStatusBarSetIcon($StatusBar1, 0, "shell32.dll", 21)
_GuiCtlrStatusBarSetIcon($StatusBar1, 1, "shell32.dll", 168)
_GuiCtlrStatusBarSetIcon($StatusBar1, 2, "shell32.dll", 24)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_RESIZED
            _GuiCtrlStatusBarResize ($StatusBar1)
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
    ;;;;;
    EndSelect
    
WEnd

Func _GuiCtlrStatusBarSetIcon($StatusBar, $i_part, $szIconFile, $iconID)
    Local $hIcon = DllStructCreate("int")
    Local $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", "shell32.dll", "int", $iconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
    $result = $result[0]
    If $result > 0 Then
        $result = DllCall("user32.dll", "int", "SendMessage", "hwnd", $StatusBar, "int", $SB_SETICON, "int", $i_part, "hwnd", DllStructGetData($hIcon, 1))
    EndIf
    $hIcon = 0
    Return $result[0]
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

new error

C:\Program Files\AutoIt3\Examples\My Stuff\tesstt_old2.au3 (36) : ==> Variable used without being declared.:

$result = DllCall("user32.dll", "int", "SendMessage", "hwnd", $StatusBar, "int", $SB_SETICON, "int", $i_part, "hwnd", DllStructGetData($hIcon, 1))

$result = DllCall("user32.dll", "int", "SendMessage", "hwnd", $StatusBar, "int", ^ ERROR

i searched and connot find it... $SB_SETICON...

not in global const's or anywhere

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

opt("MustDeclareVars", 1)

#include-once
#include <GUIConstants.au3>
#Include <GuiStatusBar.au3>

Local Const $CCM_FIRST = 0x2000
Local Const $CCM_SETBKCOLOR = ($CCM_FIRST + 1)
Global Const $SB_SETBKCOLOR = $CCM_SETBKCOLOR

Local $gui, $StatusBar1, $ret0, $ret1, $msg, $ret2, $retl1, $retcode, $asize[1]
Local $a[3] = [100, 350, -1]
Local $s[3] = ["New Text", "How about music", "Even More Text"]
$gui = GUICreate("StatusBar GUI", 500, -1, -1, -1, $WS_SIZEBOX)
GUISetState(@SW_SHOW)

$StatusBar1 = _GuiCtrlCreateStatusBar ($gui, $a, $s)
_GuiCtlrStatusBarSetIcon($StatusBar1, 1, "shell32.dll", 168)
_GuiCtlrStatusBarSetIcon($StatusBar1, 0, "shell32.dll", 21)
_GuiCtlrStatusBarSetIcon($StatusBar1, 2, "shell32.dll", 24)
DllCall("user32.dll", "int", "SendMessage", "hwnd", $StatusBar1, "int", $SB_SETBKCOLOR, "int", 0, "int", _ReverseColorOrder(0xffff00))

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_RESIZED
            _GuiCtrlStatusBarResize ($StatusBar1)
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
    ;;;;;
    EndSelect
    
WEnd

Func _GuiCtlrStatusBarSetIcon($StatusBar, $i_part, $szIconFile, $iconID)
    Local $hIcon = DllStructCreate("int")
    Local $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", "shell32.dll", "int", $iconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
    $result = $result[0]
    If $result > 0 Then
        $result = DllCall("user32.dll", "int", "SendMessage", "hwnd", $StatusBar, "int", $SB_SETICON, "int", $i_part, "hwnd", DllStructGetData($hIcon, 1))
    EndIf
    DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIcon))
    $hIcon = 0
    Return $result[0]
EndFunc

Func _ReverseColorOrder($v_color)
   Local $tc = Hex(String($v_color), 6)
   Return '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2)
EndFunc ;==>_ReverseColorOrder

Edit: forgot the destroyicon

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...