winapi - create toolbar with my bitmap images -


this example code of msdn create toolbar, example use standard images of system.
need change in code use images resource file, example: idb_copy bitmap "copy.bmp", , idb_cut bitmap "cut.bmp", , idb_paste bitmap "paste.bmp".

himagelist g_himagelist = null;  hwnd createsimpletoolbar(hwnd hwndparent) {     // declare , initialize local constants.     const int imagelistid    = 0;     const int numbuttons     = 3;     const int bitmapsize     = 16;      const dword buttonstyles = btns_autosize;      // create toolbar.     hwnd hwndtoolbar = createwindowex(0, toolbarclassname, null,                                    ws_child | tbstyle_wrapable, 0, 0, 0, 0,                                    hwndparent, null, g_hinst, null);      if (hwndtoolbar == null)         return null;      // create image list.     g_himagelist = imagelist_create(bitmapsize, bitmapsize,   // dimensions of individual bitmaps.                                 ilc_color16 | ilc_mask,   // ensures transparent background.                                 numbuttons, 0);      // set image list.     sendmessage(hwndtoolbar, tb_setimagelist,              (wparam)imagelistid,              (lparam)g_himagelist);      // load button images.     sendmessage(hwndtoolbar, tb_loadimages,              (wparam)idb_std_small_color,              (lparam)hinst_commctrl);      // initialize button info.     // idm_new, idm_open, , idm_save application-defined command constants.      tbbutton tbbuttons[numbuttons] =      {         { makelong(std_filenew,  imagelistid), idm_new,  tbstate_enabled, buttonstyles, {0}, 0, (int_ptr)l"new" },         { makelong(std_fileopen, imagelistid), idm_open, tbstate_enabled, buttonstyles, {0}, 0, (int_ptr)l"open"},         { makelong(std_filesave, imagelistid), idm_save, 0,               buttonstyles, {0}, 0, (int_ptr)l"save"}     };      // add buttons.     sendmessage(hwndtoolbar, tb_buttonstructsize, (wparam)sizeof(tbbutton), 0);     sendmessage(hwndtoolbar, tb_addbuttons,       (wparam)numbuttons,       (lparam)&tbbuttons);      // resize toolbar, , show it.     sendmessage(hwndtoolbar, tb_autosize, 0, 0);      showwindow(hwndtoolbar,  true);      return hwndtoolbar; } 

i found solution:

const int id_tb_standard = 0;  const int id_il_standard = 0;  hwnd hwndtoolbar = createwindowex(0, toolbarclassname, null,              ws_child | tbstyle_tooltips, 0, 0, 0, 0, hwnd, (hmenu)id_tb_standard, hinstance, null);  himagelist himagelist = imagelist_loadbitmap(hinstance, makeintresourcew(idb_cut), 16, 0, rgb(255, 0, 255)); imagelist_add(himagelist, loadbitmap(hinstance, makeintresource(idb_copy)), null); imagelist_add(himagelist, loadbitmap(hinstance, makeintresource(idb_paste)), null);  sendmessage(hwndtoolbar, tb_setimagelist, (wparam)id_il_standard, (lparam)himagelist); sendmessage(hwndtoolbar, (uint) tb_sethotimagelist, 0, (lparam)hhotimagelist); sendmessage(hwndtoolbar, tb_buttonstructsize, (wparam)sizeof(tbbutton), 0);  tbbutton tbb[3] =  {     {0,id_cut,tbstate_enabled,tbstyle_button},     {1,id_copy,tbstate_enabled,tbstyle_button},     {2,id_paste,tbstate_enabled,tbstyle_button}, };    sendmessage(hwndtoolbar, (uint) tb_addbuttons, 3, (lparam)&tbb);  sendmessage(hwndtoolbar, tb_autosize, 0, 0); showwindow(hwndtoolbar , sw_show); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -