LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert an image onto a toolbar button

hello,

When using Toolbar_InsertItem() to set  a toolbar button image, it needs to specify an image file which has existed on some folder , this procedure is normally , but if my image data is saved in a database in binary format , and I can read out it from the database , can I using SetBitmapData() to show the image on the button ? Please give an advise. Thanks.


David
0 Kudos
Message 1 of 3
(3,076 Views)

Well, I did a simple try modifying the tooldemo sample program and seems that it's possible to modify the image shown on a toolbar button using a simple bitmap.

To substitute the image shown, you can simply use SetCtrlBitmap on a particular button. This approach is far from optimized since it modifies an already created button, so you must at least have one image file to load when creating the buttons: you simply change the image shown after the button is created with standard functions. Nevertheless, this method permits you to use the standard toolbar instrument driver without modifications.

To test my solution, open the tooldemo project and substitute MenuCallback() function with the following:

void CVICALLBACK MenuCallback (int menuBar, int menuItem, void *callbackData, int panel){

 int  pnl, ctrl, bitmap = 0;
 char description[64];

    switch(menuItem){
        case MENU_HELP_ABOUT:
            if ((hAboutPanel = LoadPanel (0, "tooldemo.uir", ABOUT)) < 0)
                return;
            InstallPopup (hAboutPanel);
            break;
        default:
            GetMenuBarAttribute (menuBar, menuItem, ATTR_ITEM_NAME, description);
            GetBitmapFromFile (IMAGE_BYSIZE, &bitmap);
            Toolbar_GetCtrlFromDescription (gToolbar, description, &pnl, &ctrl);
            SetCtrlBitmap (pnl, ctrl, 0, bitmap);
            break;
   }      
}

This code loads a bitmap from disk (you can load it from your database) and then shows it on the button.

After this modifications, the image on the first 7 buttons is modified when you click on one of them (it becomes the image associated with the "Sort by size" button).

Hope this can help you

Roberto



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,065 Views)
Roberto , Thank you for your advise!

David
0 Kudos
Message 3 of 3
(3,050 Views)