Click here to Skip to main content
16,005,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ ques. Pin
David Crow29-Sep-04 7:36
David Crow29-Sep-04 7:36 
GeneralRe: C++ ques.thanks Pin
Ann6629-Sep-04 7:40
sussAnn6629-Sep-04 7:40 
GeneralRe: C++ ques. Pin
Bob Stanneveld29-Sep-04 7:32
Bob Stanneveld29-Sep-04 7:32 
GeneralRe: C++ ques.thanks Pin
Ann6629-Sep-04 7:41
sussAnn6629-Sep-04 7:41 
Generaluser-mode, kernel-mode and firewalls Pin
darcome29-Sep-04 5:29
darcome29-Sep-04 5:29 
GeneralRe: user-mode, kernel-mode and firewalls Pin
Bash29-Sep-04 6:21
Bash29-Sep-04 6:21 
GeneralRe: user-mode, kernel-mode and firewalls Pin
darcome29-Sep-04 6:28
darcome29-Sep-04 6:28 
GeneralSetBitmap displays garbage problems... Pin
Greg Ellis29-Sep-04 5:28
Greg Ellis29-Sep-04 5:28 
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 Wink | ;)

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();

}

CStaticDisplay::OnPaint()
{
CPaintDC dc(this);
Draw();
}
GeneralOnDrawItem Problem with Listbox Pin
YooVeeAy29-Sep-04 5:05
YooVeeAy29-Sep-04 5:05 
GeneralRe: OnDrawItem Problem with Listbox Pin
YooVeeAy29-Sep-04 5:33
YooVeeAy29-Sep-04 5:33 
GeneralRe: OnDrawItem Problem with Listbox Pin
Max Santos29-Sep-04 10:08
Max Santos29-Sep-04 10:08 
GeneralA MS Project Task – CView (se picture) Pin
anderslundsgard29-Sep-04 4:58
anderslundsgard29-Sep-04 4:58 
Generalmulticast on multiple network adapters Pin
markus.gruener29-Sep-04 4:53
markus.gruener29-Sep-04 4:53 
GeneralReading .txt file using CFile Pin
Neeranjan29-Sep-04 4:35
Neeranjan29-Sep-04 4:35 
GeneralRe: Reading .txt file using CFile Pin
David Crow29-Sep-04 4:38
David Crow29-Sep-04 4:38 
GeneralRe: Reading .txt file using CFile Pin
Cedric Moonen29-Sep-04 4:41
Cedric Moonen29-Sep-04 4:41 
GeneralRe: Reading .txt file using CFile Pin
Nicholas Cardi29-Sep-04 4:59
Nicholas Cardi29-Sep-04 4:59 
GeneralMaximum file open problem with fopen Pin
DevendraC29-Sep-04 3:39
DevendraC29-Sep-04 3:39 
GeneralRe: Maximum file open problem with fopen Pin
David Crow29-Sep-04 4:23
David Crow29-Sep-04 4:23 
GeneralRe: Maximum file open problem with fopen Pin
Blake Miller29-Sep-04 4:34
Blake Miller29-Sep-04 4:34 
GeneralRe: Maximum file open problem with fopen Pin
Nicholas Cardi29-Sep-04 4:40
Nicholas Cardi29-Sep-04 4:40 
GeneralRe: Maximum file open problem with fopen Pin
Alan Chambers29-Sep-04 10:34
Alan Chambers29-Sep-04 10:34 
GeneralRe: Maximum file open problem with fopen Pin
DevendraC30-Sep-04 2:44
DevendraC30-Sep-04 2:44 
QuestionWhy this linker error? Pin
Jenie_net29-Sep-04 3:38
Jenie_net29-Sep-04 3:38 
AnswerRe: Why this linker error? Pin
Nicholas Cardi29-Sep-04 4:14
Nicholas Cardi29-Sep-04 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.