News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Toolbar bitmaps.

Started by xandaz, November 26, 2019, 09:12:22 AM

Previous topic - Next topic

xandaz

    Hey guys. I'm kinda disapointed at myself for thinking i could use ImageList_ functions to add the bitmap images to the toolbar buttons. I thought the IMageList_LoadImage would load bitmap and zero-base index them and then the iBitmap member of the TBBUTTON struct would point the index numer of the image, but, it doesn't seem to work that way. Am i wrong about this?
    Help is apprectiatted. Thanks in advance.

HSE

Some old code:
invoke LoadBitmap, hInstance, 750
mov hTbBmp , eax

invoke CreateToolbarEx, hWin, WS_CHILD+WS_VISIBLE+TBSTYLE_TOOLTIPS,
       787, 20, NULL, hTbBmp,
addr Toolbar,13,16,16,16,16, sizeof TBBUTTON
mov hToolBar, eax

invoke SendMessage, hToolBar, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON,0
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on November 26, 2019, 10:05:43 AMWS_CHILD+WS_VISIBLE+TBSTYLE_TOOLTIPS

This works only by accident, i.e. if the constants do not overlap, bit-wise. Otherwise it's a recipe for disaster.

WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS is the right way to go.

HSE

Equations in Assembly: SmplMath

xandaz

    Thanks guys. The problem is solved. It happened that i was using ImageList_LoadImage and the ImageList_AddMasked. ImageList_LoadImage dones't return a bitmap handle, so that was the error.
    Thanks again guys for all the help

Manos

Toolbars are a little idiosyncratic.

To work OK you should use the CreateWindowEx
instead of CreateToolbarEx.
Also you should do all the works before show the Toolbar.

Below is the source in C language. You can easly translate the code in Assembly.


int nButtons = 11;

TBBUTTON tbb[] =
{
   {0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {1, IDM_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {2, IDM_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {3, IDM_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {4, IDM_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {5, IDM_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {6, IDM_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {7, IDM_HELP_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON ,0,0,0},
};

hwndToolbar = CreateWindowEx(TBSTYLE_FLAT, TOOLBARCLASSNAME, (LPSTR) NULL,
         WS_CHILD | TBSTYLE_TOOLTIPS, 0,  0,  0,  24,  hwnd,  NULL,  hInstance,  NULL);

   hImageList = ImageList_LoadImage(hInstance, MAKEINTRESOURCE(IDB_TOOLBAR), 16, 1,
   CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_DEFAULTSIZE |   LR_LOADTRANSPARENT);
   SendMessage(hwndToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);

   SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
   SendMessage(hwndToolbar, TB_ADDBUTTONS, (WPARAM)nButtons, (LPARAM)&tbb);
   ShowWindow(hwndToolbar, SW_SHOW);


Manos.

TimoVJL

#6
Quote from: Manos on November 27, 2019, 06:40:11 AM
Toolbars are a little idiosyncratic.

To work OK you should use the CreateWindowEx
instead of CreateToolbarEx.
Also you should do all the works before show the Toolbar.

Below is the source in C language. You can easly translate the code in Assembly.


int nButtons = 11;

TBBUTTON tbb[] =
{
   {0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {1, IDM_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {2, IDM_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {3, IDM_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {4, IDM_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {5, IDM_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {6, IDM_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0},
   {0, 0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0},
   {7, IDM_HELP_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON ,0,0,0},
};

hwndToolbar = CreateWindowEx(TBSTYLE_FLAT, TOOLBARCLASSNAME, (LPSTR) NULL,
         WS_CHILD | TBSTYLE_TOOLTIPS, 0,  0,  0,  24,  hwnd,  NULL,  hInstance,  NULL);

   hImageList = ImageList_LoadImage(hInstance, MAKEINTRESOURCE(IDB_TOOLBAR), 16, 1,
   CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_DEFAULTSIZE |   LR_LOADTRANSPARENT);
   SendMessage(hwndToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);

   SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
   SendMessage(hwndToolbar, TB_ADDBUTTONS, (WPARAM)nButtons, (LPARAM)&tbb);
   ShowWindow(hwndToolbar, SW_SHOW);


Manos.
safer way ?
{0, IDM_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,{0},0,0},
...
that {0} have it's own meaning in that struct.
If someone use common controls bitmaps
0 -14 are used.
User's additional bitmap starts from15...
{15, IDM_BULSHIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
...
tbBitmap.hInst = hInst;
tbBitmap.nID = IDR_TB_BMP;
SendMessage(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&tbBitmap);
...
May the source be with you

xandaz

    nice example manos. tx

Manos

Quote
that {0} have it's own meaning in that struct.


I tried both {0} and 0, but the result is the same.
Therefore I have omit the {}.

Manos.