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. SetBitmap displays garbage problems...

SetBitmap displays garbage problems...

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphics
1 Posts 1 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.
  • G Offline
    G Offline
    Greg Ellis
    wrote on last edited by
    #1

    Hi Guys, I have a class derived from CStatic that I used to create my own custom static display. I try to use SetBitmap to insert an image into the control as a background and then I draw the text on top of that. The problem is that sometimes the button doesn't show the image that I set into it. Sometimes it shows windows controls(minimize button, maximize button, or just garbage), but this only happens sometimes. I cannot reproduce the problem consistently so maybe I am leaking resources or something, I don't know. Here is my code. Can anyone tell what is wrong? void CStatusDisplay::SetButton(CString cszFilename, UINT nIDResource) { CBitmap cbBitmap; HBITMAP hBitmap; HBITMAP hOldBitmap=NULL; if(cszFilename!="") { if(LoadBitmapFromFile(cszFilename, cbBitmap)) { hBitmap = (HBITMAP)cbBitmap.Detach(); hOldBitmap = SetBitmap(hBitmap); } else { AfxMessageBox("Error loading bitmap in display status"); } } else { if(cbBitmap.LoadBitmap(nIDResource)) { hBitmap = (HBITMAP)cbBitmap.Detach(); hOldBitmap = SetBitmap(hBitmap); } else { AfxMessageBox("Error loading bitmap in display status"); } } if(hOldBitmap!=NULL) DeleteObject(hOldBitmap); } //This gets called in OnPaint!! void CStatusDisplay::Draw() { CClientDC dc(this); CRect rect; GetClientRect(&rect); CMemDC2 memDC(&dc, &rect,TRUE); //memDC.FillSolidRect(&rect, RGB(72,82,107)); //memDC.FillSolidRect(&rect, RGB(255,0,0)); DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, (LPARAM)0); //add some text on top of that ;) CFont font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = m_nFontSize; if(m_bBold) lf.lfWeight = FW_BOLD; if(m_bItalics) lf.lfItalic = TRUE; strcpy(lf.lfFaceName, m_cszFontName); font.CreateFontIndirect(&lf); CFont* def_font = memDC.SelectObject(&font); memDC.SetBkMode(TRANSPARENT); memDC.SetTextColor(m_crTextColor); UINT uFormat = NULL; if(m_cszAlign == "left") uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER |DT_LEFT | DT_END_ELLIPSIS; else if(m_cszAlign == "lefttop") uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_TOP |DT_LEFT | DT_END_ELLIPSIS; else if(m_cszAlign == "center") uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER |DT_CENTER | DT_END_ELLIPSIS; else if(m_cszAlign == "wordbreak") uFormat = DT_NOPREFIX | DT_VCENTER |DT_CENTER | DT_WORDBREAK; memDC.DrawText(m_cszStatus, &rect, uFormat); memDC.SelectObject(def_font); BOOL bRet = font.DeleteObject(

    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