Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Drawing icons on a toolbar

Drawing icons on a toolbar

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpperformance
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ron Olson
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • R Ron Olson

      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

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      Why don't you use a regular toolbar bitmap strip? Steve S [This signature space available for rent]

      R 1 Reply Last reply
      0
      • S Steve S

        Why don't you use a regular toolbar bitmap strip? Steve S [This signature space available for rent]

        R Offline
        R Offline
        Ron Olson
        wrote on last edited by
        #3

        The problem is that the toolbar is variable....the buttons that would appear in the toolbar, as well as their order, are variable. In addition, I already have several dozen ico files which would all have to be mushed together into one big bitmap.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups