Drawing icons on a toolbar
-
Hi all- I'm completely stuck. I am trying to dynamically set buttons on a CToolbar object using SetBitmap() via a memory dc. The code I have is below: // begin code block void CBitmap_toolbar2View::OnInitialUpdate() { CWindowDC dc(this); CDC memdc; memdc.CreateCompatibleDC(&dc); CBitmap bm; VERIFY(bm.LoadBitmap(IDR_MAINFRAME)); CBitmap *poldbm = memdc.SelectObject(&bm); // draw into the dc/bitmap CBrush brush; brush.CreateSysColorBrush(COLOR_BTNFACE); HICON theIcon = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ENTRY), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); VERIFY(::DrawIconEx(memdc, 0, 0, // dc, x, y theIcon, // HICON (first small one) GetSystemMetrics(SM_CXICON), // cx GetSystemMetrics(SM_CYICON), // cy 0, brush, DI_NORMAL)); // frame, brush, flags DestroyIcon(theIcon); theIcon = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ORDER), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); VERIFY(::DrawIconEx(memdc, 32, 0, // dc, x, y theIcon, // HICON (first small one) GetSystemMetrics(SM_CXICON), // cx GetSystemMetrics(SM_CYICON), // cy 0, brush, DI_NORMAL)); // frame, brush, flags memdc.SelectObject(poldbm); ((CMainFrame*)GetParentFrame())->m_wndToolBar.SetBitmap((HBITMAP)bm.Detach()); ((CMainFrame*)GetParentFrame())->m_wndToolBar.Invalidate(TRUE); ((CMainFrame*)GetParentFrame())->m_wndToolBar.SetButtons(NULL,2); } //// end of code block I made the toolbar in the frame public just to make it easier to play with. So I have two icons that I want to set on the toolbar. The two calls to DrawIconEx() sets the first icon at 0,0 and the second one at 32,0 but what I see is the first icon twice. I have zero clue as to why I should see the first icon twice, especially when I call DestroyIcon() between DrawIconEx() and LoadImage() for the second icon. Any help would be appreciated, this is something of a showstopper and I have no way of getting around it right now. :( Ron
-
Hi all- I'm completely stuck. I am trying to dynamically set buttons on a CToolbar object using SetBitmap() via a memory dc. The code I have is below: // begin code block void CBitmap_toolbar2View::OnInitialUpdate() { CWindowDC dc(this); CDC memdc; memdc.CreateCompatibleDC(&dc); CBitmap bm; VERIFY(bm.LoadBitmap(IDR_MAINFRAME)); CBitmap *poldbm = memdc.SelectObject(&bm); // draw into the dc/bitmap CBrush brush; brush.CreateSysColorBrush(COLOR_BTNFACE); HICON theIcon = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ENTRY), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); VERIFY(::DrawIconEx(memdc, 0, 0, // dc, x, y theIcon, // HICON (first small one) GetSystemMetrics(SM_CXICON), // cx GetSystemMetrics(SM_CYICON), // cy 0, brush, DI_NORMAL)); // frame, brush, flags DestroyIcon(theIcon); theIcon = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ORDER), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); VERIFY(::DrawIconEx(memdc, 32, 0, // dc, x, y theIcon, // HICON (first small one) GetSystemMetrics(SM_CXICON), // cx GetSystemMetrics(SM_CYICON), // cy 0, brush, DI_NORMAL)); // frame, brush, flags memdc.SelectObject(poldbm); ((CMainFrame*)GetParentFrame())->m_wndToolBar.SetBitmap((HBITMAP)bm.Detach()); ((CMainFrame*)GetParentFrame())->m_wndToolBar.Invalidate(TRUE); ((CMainFrame*)GetParentFrame())->m_wndToolBar.SetButtons(NULL,2); } //// end of code block I made the toolbar in the frame public just to make it easier to play with. So I have two icons that I want to set on the toolbar. The two calls to DrawIconEx() sets the first icon at 0,0 and the second one at 32,0 but what I see is the first icon twice. I have zero clue as to why I should see the first icon twice, especially when I call DestroyIcon() between DrawIconEx() and LoadImage() for the second icon. Any help would be appreciated, this is something of a showstopper and I have no way of getting around it right now. :( Ron
-
Why don't you use a regular toolbar bitmap strip? Steve S [This signature space available for rent]