Author Topic: Toolbar bitmaps.  (Read 321 times)

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Toolbar bitmaps.
« 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.
nothing to report.

HSE

  • Member
  • *****
  • Posts: 1182
  • <AMD>< 7-32>
Re: Toolbar bitmaps.
« Reply #1 on: November 26, 2019, 10:05:43 AM »
Some old code:
Code: [Select]
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

jj2007

  • Member
  • *****
  • Posts: 9928
  • Assembler is fun ;-)
    • MasmBasic
Re: Toolbar bitmaps.
« Reply #2 on: November 26, 2019, 06:33:15 PM »
WS_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

  • Member
  • *****
  • Posts: 1182
  • <AMD>< 7-32>
Re: Toolbar bitmaps.
« Reply #3 on: November 26, 2019, 11:07:42 PM »

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Toolbar bitmaps.
« Reply #4 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
nothing to report.

Manos

  • Regular Member
  • *
  • Posts: 48
Re: Toolbar bitmaps.
« Reply #5 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.

TimoVJL

  • Member
  • ***
  • Posts: 488
Re: Toolbar bitmaps.
« Reply #6 on: December 01, 2019, 06:21:26 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 ?
Code: [Select]
{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
Code: [Select]
...
{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);
...
« Last Edit: December 01, 2019, 07:37:49 AM by TimoVJL »
May the source be with you

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Toolbar bitmaps.
« Reply #7 on: December 01, 2019, 06:39:54 AM »
    nice example manos. tx
nothing to report.

Manos

  • Regular Member
  • *
  • Posts: 48
Re: Toolbar bitmaps.
« Reply #8 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.