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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Issue with SetBitmap

Issue with SetBitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestionarchitecture
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.
  • C Offline
    C Offline
    CoffeeAddict19
    wrote on last edited by
    #1

    I'm trying to change the face of a button to a solid color bitmap, but for some reason it's just displaying the button without the bitmap on the front. Here is the code:

    CGameOptionsDialog::CGameOptionsDialog(char* lpszName) : CDialog(lpszName)
    {
    	//initialize graphics
    	Problem = mem_DC.CreateCompatibleDC(NULL);
    	CBitSolidBkButton.CreateBitmap(20, 20, mem_DC.GetDeviceCaps(PLANES), mem_DC.GetDeviceCaps(BITSPIXEL), NULL);
    	mem_DC.SelectObject(CBitSolidBkButton);
    	NewSolidBkColor = RGB(220, 20, 60); //default
    	NewSolidBkBrush.CreateSolidBrush(NewSolidBkColor);
    	mem_DC.SelectObject(NewSolidBkBrush);
    	mem_DC.FloodFill(0, 0, NewSolidBkColor);
    }
    

    and where SetBitmap is called...

    BOOL CGameOptionsDialog::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    ...
    
    //initialize controls
    	SolidColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(145, 55, 165, 75), this, ID_CHANGE_BK_COLOR);
    	Gradient1ColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(145, 85, 165, 105), this, ID_CHANGE_GRADIENT1_COLOR);
    	Gradient2ColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(175, 85, 195, 105), this, ID_CHANGE_GRADIENT2_COLOR);
    	SolidColorSelectButton.SetBitmap((HBITMAP)CBitSolidBkButton);
    
    if(Problem == FALSE)
            MessageBox("Problem", "MSG", MB_OK);
    
            return TRUE;
    }
    

    The "Problem" message box isn't popping up, so I'm pretty shure that the device context got initialized right (it's a class member, so scope isn't an issue). Any ideas on what is wrong? Thanks.

    W 1 Reply Last reply
    0
    • C CoffeeAddict19

      I'm trying to change the face of a button to a solid color bitmap, but for some reason it's just displaying the button without the bitmap on the front. Here is the code:

      CGameOptionsDialog::CGameOptionsDialog(char* lpszName) : CDialog(lpszName)
      {
      	//initialize graphics
      	Problem = mem_DC.CreateCompatibleDC(NULL);
      	CBitSolidBkButton.CreateBitmap(20, 20, mem_DC.GetDeviceCaps(PLANES), mem_DC.GetDeviceCaps(BITSPIXEL), NULL);
      	mem_DC.SelectObject(CBitSolidBkButton);
      	NewSolidBkColor = RGB(220, 20, 60); //default
      	NewSolidBkBrush.CreateSolidBrush(NewSolidBkColor);
      	mem_DC.SelectObject(NewSolidBkBrush);
      	mem_DC.FloodFill(0, 0, NewSolidBkColor);
      }
      

      and where SetBitmap is called...

      BOOL CGameOptionsDialog::OnInitDialog()
      {
      	CDialog::OnInitDialog();
      
      ...
      
      //initialize controls
      	SolidColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(145, 55, 165, 75), this, ID_CHANGE_BK_COLOR);
      	Gradient1ColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(145, 85, 165, 105), this, ID_CHANGE_GRADIENT1_COLOR);
      	Gradient2ColorSelectButton.Create(" ", WS_CHILD|WS_VISIBLE|BS_BITMAP, CRect(175, 85, 195, 105), this, ID_CHANGE_GRADIENT2_COLOR);
      	SolidColorSelectButton.SetBitmap((HBITMAP)CBitSolidBkButton);
      
      if(Problem == FALSE)
              MessageBox("Problem", "MSG", MB_OK);
      
              return TRUE;
      }
      

      The "Problem" message box isn't popping up, so I'm pretty shure that the device context got initialized right (it's a class member, so scope isn't an issue). Any ideas on what is wrong? Thanks.

      W Offline
      W Offline
      Warren Stevens
      wrote on last edited by
      #2
      1. try adding a bitmap resource, and then using that in your line: SolidColorSelectButton.SetBitmap((HBITMAP)CBitSolidBkButton); that way you can tell whether it's a bitmap-creation issue OR a button creation issue. 2) You have the line: mem_DC.SelectObject(CBitSolidBkButton); Did you select the bitmap back OUT of the device context later on???

      www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)

      C 1 Reply Last reply
      0
      • W Warren Stevens
        1. try adding a bitmap resource, and then using that in your line: SolidColorSelectButton.SetBitmap((HBITMAP)CBitSolidBkButton); that way you can tell whether it's a bitmap-creation issue OR a button creation issue. 2) You have the line: mem_DC.SelectObject(CBitSolidBkButton); Did you select the bitmap back OUT of the device context later on???

        www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)

        C Offline
        C Offline
        CoffeeAddict19
        wrote on last edited by
        #3

        blah...I gave it up and did something similar: http://www.codeproject.com/buttonctrl/colorbox.asp[^]

        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