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. How to draw a bitmap on top of button?

How to draw a bitmap on top of button?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
27 Posts 6 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.
  • I Igor Jerosimic

    I want to draw a small arrow bitmap on top of already drawn button. I tried with calling default drawing proc before my code for drawing bitmap but it gives me some error. OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct); HDC thdc = CreateCompatibleDC(lpDrawItemStruct->hDC); HGDIOBJ tobj = SelectObject(thdc, LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_ARROW_DOWN))); TransparentBlt(lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.right - 20, lpDrawItemStruct->rcItem.top + (lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top - 16) / 2, 16, 16, thdc, 0, 0, 16, 16, RGB(255, 0, 255)); SelectObject(thdc, tobj); DeleteDC(thdc); } if i exclude "CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);" then code works, but there is no borders and caption text, just my bitmap.

    I Offline
    I Offline
    Igor Jerosimic
    wrote on last edited by
    #21

    CImageButton class is very lousy way of replacing API function DrawFrameControl and i definitely don't need that... All that code is easily replaced with these 4 lines of code: CPaintDC dc(this); CRect rc; GetClientRect(&rc); dc.DrawFrameControl(&rc, DFC_BUTTON, DFCS_BUTTONPUSH); http://img214.imageshack.us/img214/6206/drawingfx6.png

    1 Reply Last reply
    0
    • I Igor Jerosimic

      Can you explain how do you think that i should use CBitmapButton class? As i see that class only helps in inserting bitmaps on to buttons, but it still needs me to draw the button (because my bitmap is displayed only on one small portion of button).

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #22

      that's a problem :) .. I will tell you another way. Make the button owner draw, in the DrawItem Function,do as follows DrawItem() { DrawFrameControl();// This function will draw a statndard button. // here , draw your bitmap }

      nave

      I 1 Reply Last reply
      0
      • N Naveen

        that's a problem :) .. I will tell you another way. Make the button owner draw, in the DrawItem Function,do as follows DrawItem() { DrawFrameControl();// This function will draw a statndard button. // here , draw your bitmap }

        nave

        I Offline
        I Offline
        Igor Jerosimic
        wrote on last edited by
        #23

        I tried that already, look at this picture http://img214.imageshack.us/img214/6206/drawingfx6.png It draws button but without XP styles...

        N 1 Reply Last reply
        0
        • I Igor Jerosimic

          I tried that already, look at this picture http://img214.imageshack.us/img214/6206/drawingfx6.png It draws button but without XP styles...

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #24

          check the following article. it draws all controls in xp style http://www.codeproject.com/w2k/xpvisualstyle.asp[^]

          nave

          I 2 Replies Last reply
          0
          • N Naveen

            check the following article. it draws all controls in xp style http://www.codeproject.com/w2k/xpvisualstyle.asp[^]

            nave

            I Offline
            I Offline
            Igor Jerosimic
            wrote on last edited by
            #25

            OK thanks, this looks like something i needed.

            1 Reply Last reply
            0
            • N Naveen

              check the following article. it draws all controls in xp style http://www.codeproject.com/w2k/xpvisualstyle.asp[^]

              nave

              I Offline
              I Offline
              Igor Jerosimic
              wrote on last edited by
              #26

              I did it, it works now, thank you.

              N 1 Reply Last reply
              0
              • I Igor Jerosimic

                I did it, it works now, thank you.

                N Offline
                N Offline
                Naveen
                wrote on last edited by
                #27

                :)

                nave

                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