Hi,
can anyone show me how to change the image of a rebar/ toobar at runtime.
Thank you.
Marc
You need to fill a TBBUTTONINFO structure ( http://msdn.microsoft.com/en-us/library/windows/desktop/bb760478%28v=vs.85%29.aspx ) and send a TB_SETBUTTONINFO message ( http://msdn.microsoft.com/en-us/library/windows/desktop/bb787413%28v=vs.85%29.aspx ).
Thank you Jose. I will have a look.
Marc
Hi,
I have been able to change the text with TB_SETBUTTONINFO
Local MVC_hReBar As Dword : MVC_hReBar = GetDlgItem( hWndForm, IDC_FRMMAIN_REBAR )
Local MVC_hToolBar As Dword : MVC_hToolBar = GetDlgItem( MVC_hReBar, IDC_FRMMAIN_TOOLBARALL )
Local ToolBarButtonInfo As TBBUTTONINFO
Local sButtonText As String
sButtonText = "My text"
ToolBarButtonInfo.cbSize = SizeOf(TBBUTTONINFO)
ToolBarButtonInfo.dwMask = %TBIF_TEXT Or %TBIF_COMMAND
ToolBarButtonInfo.pszText = StrPtr(sButtonText)
ToolBarButtonInfo.idCommand = IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR
SendMessage(MVC_hToolBar, %TB_SETBUTTONINFO, IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR, VarPtr(ToolBarButtonInfo))
'
ToolBarButtonInfo.dwMask = %TBIF_SIZE Or %TBIF_COMMAND
ToolBarButtonInfo.cx = 150 'Width in pixel
SendMessage(MVC_hToolBar, %TB_SETBUTTONINFO, IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR, VarPtr(ToolBarButtonInfo))
Trying to change a image does not work:
Local MVC_hReBar As Dword : MVC_hReBar = GetDlgItem( hWndForm, IDC_FRMMAIN_REBAR )
Local MVC_hToolBar As Dword : MVC_hToolBar = GetDlgItem( MVC_hReBar, IDC_FRMMAIN_TOOLBARALL )
Local MVC_tempLong As Long : MVC_tempLong = LoadImage( App.hInstance, "IMAGE_20122013", %IMAGE_ICON, 48, 48, 0 )
Local tbi As TBButtonInfo
tbi.cbSize = SizeOf(tbi)
tbi.dwMask = %TBIF_IMAGE
tbi.iImage = MVC_tempLong
SendMessage MVC_hToolBar, %TB_SetButtonInfo, IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR, VarPtr(tbi)
Probably has to do something with the image handle.
What am I doing wrong?
Marc
tbi.iImage is not an handle, but the zero-based index of the image in the toolbar image list.
Thank you.
Here is the next try:
Local hImageList As Dword : hImageList = ImageList_Create( 48, 48, %ILC_COLOR32 Or %ILC_MASK, 5, 1)
Local hImage As Long : hImage = LoadImage( App.hInstance, "IMAGE_20122013", %IMAGE_ICON, 48, 48, 0 )
Local lImageIndex As Long : lImageIndex = ImageList_AddIcon( hImageList, hImage )
Local hReBar As Dword : hReBar = GetDlgItem( hWndForm, IDC_FRMMAIN_REBAR )
Local hToolBar As Dword : hToolBar = GetDlgItem( hReBar, IDC_FRMMAIN_TOOLBARALL )
Local tbi As TBButtonInfo
tbi.cbSize = SizeOf(tbi)
tbi.dwMask = %TBIF_IMAGE
tbi.iImage = lImageIndex
SendMessage hToolBar, %TB_SetButtonInfo, IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR, VarPtr(tbi)
What am I doing wrong here?
thank you again,
Marc
You're are creating a new image list, when what you have to do is to get an handle to the image list being used by the toolbar, sending the TB_GETIMAGELIST message, and then call the ImageList_ReplaceIcon function.
OK,
I think I more or less have it working.
I added the following code:
Local hImageList As Dword : hImageList = SendMessage (hToolBar, %TB_GETIMAGELIST, 0, 0)
Local hImage As Long : hImage = LoadImage( App.hInstance, "IMAGE_20122013", %IMAGE_ICON, 48, 48, 0 )
ImageList_ReplaceIcon (hImageList , 0, hImage)
You have to do this with disable and hot imagelists also, so I used %TB_GETDISABLEDIMAGELIST and %TB_GETHOTIMAGELIST also.
I did not know have to figure out the index of the image to change and peeked a bit in the code FF gives (once again excellent to learn from)
The image most left of the toolbar is of course index 0
That worked but it did not show the image change immediately. I first did a FF_Redraw but that was a complete mis.
I then added
Local tbi As TBButtonInfo
tbi.cbSize = SizeOf(tbi)
tbi.dwMask = %TBIF_IMAGE
tbi.iImage = 0
SendMessage hToolBar, %TB_SetButtonInfo, IDC_FRMMAIN_TOOLBARALL_SCHOOLJAAR, VarPtr(tbi)
That seems to work.
I could probably be done better. Anything come to mind Jose?
Thanks all the same for taking the time to PUSH me in the right direction.
Best regards,
Marc