ToolBar_SetState/ToolBar_GetState working not as documented
issueid=345 19-02-2012 17:01
Super Moderator
Number of reported issues by Petr Schreiber: 133
ToolBar_SetState/ToolBar_GetState working not as documented
The toolbar related commands ToolBar_SetState/ToolBar_GetState do not work as expected

I noticed that the ToolBar_SetState/ToolBar_GetState don't work as expected.
For example, ToolBar_SetState( hDlg, %tToolbar, 2, %TBSTATE_CHECKED) does not check the second button in %tToolbar, but disables it instead.

Here is testing code, just launch it, and press "Check state":
' Basic Template for custom dialog
' Start Date 02-19-2012
' Created by Petr Schreiber
Uses "UI"

' -- ID numbers of controls
Begin ControlID
End ControlID    

Begin Const
  %MAIN_WIDTH   = 320
  %MAIN_HEIGHT  = 240
End Const

' -- Create dialog here
Function TBMain()
  Local hDlg As DWord

  Dialog New Pixels, 0, "<Enter title here>",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
  ' -- Place controls here
  Control Add TOOLBAR, hDlg, %tToolbar, "", , , , , %WS_VISIBLE Or %WS_TABSTOP Or %CCS_TOP Or %TBSTYLE_FLAT
    ToolBar_AddButton    hDlg, %tToolbar, 0, %bA    , %TBSTYLE_CHECK Or %TBSTYLE_GROUP, "A"
    ToolBar_AddButton    hDlg, %tToolbar, 0, %bB    , %TBSTYLE_CHECK Or %TBSTYLE_GROUP, "B"
    ToolBar_AddButton    hDlg, %tToolbar, 0, %bC    , %TBSTYLE_CHECK Or %TBSTYLE_GROUP, "C"
    ' -- DOES NOT WORK
    'ToolBar_SetState( hDlg, %tToolbar, 2, %TBSTATE_CHECKED)  ' -- I would expect to check the second button (B)
    ' -- DOES WORK                                        
    ToolBar_SetState( hDlg, %tToolbar, 2, 5)   ' -- This checks the second button, but it should be done by value instead
  Control Add Button, hDlg, %bCheckState, "Check state", 5, 100, 100, 25, Call cbCheckButton
  Dialog Show Modal hDlg, Call cbDialog

End Function

' -- Callback for dialog
CallBack Function cbDialog()

  ' -- Test for messages
  Select Case CBMSG

    ' -- Put code to be executed after dialog creation here

    Case %WM_COMMAND
    ' -- You can handle controls here

    Case %WM_CLOSE
    ' -- Put code to be executed before dialog end here

  End Select

End Function
CallBack Function cbCheckButton()

      MsgBox 0, "Expected return values:"+$CRLF+
                "Buttons report (notice the checked property is reported as 5 instead of 1):"+$CRLF+
                "A"+$TAB+ToolBar_GetState(CBHNDL, %tToolbar, 1)+$CRLF+
                "B"+$TAB+ToolBar_GetState(CBHNDL, %tToolbar, 2)+$CRLF+
                "C"+$TAB+ToolBar_GetState(CBHNDL, %tToolbar, 3)+$CRLF
    End If
  End If

End Function
Maybe the problem is in the equates, and not the commands, I am not really sure.

Issue Details
Issue Number 345
Project thinBasic
Category Unknown
Status Not a Bug
Priority 2
Affected Version 1.8.9
Fixed Version (none)
Milestone (none)
Users able to reproduce bug 0
Users unable to reproduce bug 0
Assigned Users (none)
Tags (none)

25-02-2012 16:08
thinBasic author

I may be wrong but ... toolbar items state is a bit oriented option.
As you know it means it can/must have multiple bits to be set.

If you just set it checked it will be disabled if not defined. So try something like:
    ToolBar_SetState( hDlg, %tToolbar, 2, %TBSTATE_ENABLED Or %TBSTATE_CHECKED)
I'm not sure I'm 100% correct, I need to read Microsoft documentation but from what I read into PB documentation it is like I state.

Let me know what you think

26-02-2012 15:02
Super Moderator
Hi Eros,

you are right of course! So if I want to see if the usable toolbar button is checked, I need to go like:
If ToolBar_GetState(hDlg, %tlbMain, %myButton) = (%TBSTATE_ENABLED Or %TBSTATE_CHECKED) Then
End If
Maybe worth adding some comment to help file, it didn't occurred me at first.


18-03-2012 12:58
Issue Changed by Petr Schreiber
  • Status changed from Unconfirmed to Not a Bug

+ Reply