{"id":3743,"date":"2014-03-30T05:07:22","date_gmt":"2014-03-30T05:07:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/cimagelist-cbitmap-and-ctoolbar-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:07:22","modified_gmt":"2014-03-30T05:07:22","slug":"cimagelist-cbitmap-and-ctoolbar-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/cimagelist-cbitmap-and-ctoolbar-collection-of-common-programming-errors\/","title":{"rendered":"CImageList, CBitmap and CToolbar-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn Hello,suppose I have few bitmap files a.bmp and b.bmp which i mange to load into CBitmap instance a and b accordingly.Now suppose that I added them to a CImageList, then how can I load \/ set it to a CtoolBar?tnx<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1<\/p>\n<p>OK! This is a way to do it too. My way would be a little bit more complicated.<br \/>\nYou don&#8217;t need to use SendMessage you can execute<\/p>\n<p>_barbara.GetToolBarCtrl()-&gt;SetImageList<\/p>\n<p>You can directly load a CBitmap with the Load function. There is no need to use LoadImage.<\/p>\n<p>Do you need to load the symbols from more than one bitmap? Isn&#8217;t it possible for you to use one bitmap?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2 Hey Martin,Since I&#8217;m new to this MFC, could you send me an example of what you ment?I did succed to make it works like this:(where my CToolBar is _barbara, and nButtonIDs is array of\u00a0 commands IDs)_barbara.CreateEx(this); CString strBitmap1(&#8220;toolbar2.bmp&#8221;); CString strBitmap2(&#8220;..\/toolbar3.bmp&#8221;); HBITMAP hBitmap1 = static_cast( ::LoadImage( AfxGetInstanceHandle() ,strBitmap1 ,IMAGE_BITMAP , 0 , 0 , LR_LOADFROMFILE | LR_CREATEDIBSECTION )); HBITMAP hBitmap2 = static_cast( ::LoadImage(AfxGetInstanceHandle(), strBitmap2, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION)); CImageList list; list.Create(15,16,ILC_COLOR,0,10); CBitmap c1; c1.Attach(hBitmap1); list.Add(&amp;c1,RGB(255,255,255)); if (hBitmap2){ CBitmap c2; c2.Attach(hBitmap2); list.Add(&amp;c2,RGB(255,255,255)); } _barbara.SendMessage(TB_SETIMAGELIST, 0, reinterpret_cast(list.m_hImageList)); _barbara.SetButtons(nButtonIDs,9); list.Detach();<\/p>\n<p>tnx<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3<\/p>\n<p>OK! This is a way to do it too. My way would be a little bit more complicated.<br \/>\nYou don&#8217;t need to use SendMessage you can execute<\/p>\n<p>_barbara.GetToolBarCtrl()-&gt;SetImageList<\/p>\n<p>You can directly load a CBitmap with the Load function. There is no need to use LoadImage.<\/p>\n<p>Do you need to load the symbols from more than one bitmap? Isn&#8217;t it possible for you to use one bitmap?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn4 Hello again,Well, I need to allow a dynaimc number of buttons in the toolbar and also a dynamic bitmap for each one &#8211; which means that I could change them at runtime, therefor I can&#8217;t use MFC resource since it&#8217;s being compiled or something and i cant use only one bitmap. I&#8217;ll try this one: _barbara.GetToolBarCtrl()-&gt;SetImageListIt looks much nicer : )anyway,<\/p>\n<p>tnx very much<\/p>\n<p><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hello,suppose I have few bitmap files a.bmp and b.bmp which i mange to load into CBitmap instance a and b accordingly.Now suppose that I added them to a CImageList, then how can I load \/ set it to a CtoolBar?tnx msdn1 OK! This is a way to do it too. My way would be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3743","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3743"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3743\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}