The MASM Forum

General => The Campus => Topic started by: xandaz on November 26, 2019, 09:12:22 AM

Title: Toolbar bitmaps.
Post by: xandaz on November 26, 2019, 09:12:22 AM
    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.
Title: Re: Toolbar bitmaps.
Post by: HSE on November 26, 2019, 10:05:43 AM
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
Title: Re: Toolbar bitmaps.
Post by: jj2007 on November 26, 2019, 06:33:15 PM
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.
Title: Re: Toolbar bitmaps.
Post by: HSE on November 26, 2019, 11:07:42 PM
Quote from: jj2007 on November 26, 2019, 06:33:15 PM
This works

That's.
Title: Re: Toolbar bitmaps.
Post by: xandaz on November 27, 2019, 12:17:37 AM
    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
Title: Re: Toolbar bitmaps.
Post by: 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.
Title: Re: Toolbar bitmaps.
Post by: TimoVJL on December 01, 2019, 06:21:26 AM
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);
...
Title: Re: Toolbar bitmaps.
Post by: xandaz on December 01, 2019, 06:39:54 AM
    nice example manos. tx
Title: Re: Toolbar bitmaps.
Post by: Manos on December 01, 2019, 08:17:56 PM
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.