Click here to Skip to main content
15,885,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Linker Error Pin
Chris Meech20-May-10 3:31
Chris Meech20-May-10 3:31 
AnswerRe: Linker Error Pin
Aescleal20-May-10 3:19
Aescleal20-May-10 3:19 
GeneralRe: Linker Error Pin
john563220-May-10 3:41
john563220-May-10 3:41 
QuestionNot getting Excel::_ApplicationPtr from WindowsPtr. Pin
KTTransfer20-May-10 2:08
KTTransfer20-May-10 2:08 
QuestionTough one: modify screen contents on the fly Pin
y.a.k20-May-10 0:50
y.a.k20-May-10 0:50 
AnswerRe: Tough one: modify screen contents on the fly Pin
CPallini20-May-10 1:47
mveCPallini20-May-10 1:47 
QuestionCStatic Background color Pin
Anu_Bala19-May-10 23:34
Anu_Bala19-May-10 23:34 
AnswerRe: CStatic Background color [modified] Pin
Hristo-Bojilov20-May-10 0:37
Hristo-Bojilov20-May-10 0:37 
Your problem seems to be elementary.When the CWnd::OnCtlColor is finished the brush you have created inside is automatically destroyed by the MFC runtime without warning, so nothing happened.You should declare the brush as your window class member variable not as local variable.At first simply put it in your dialog(for example) h file:

class CMyDialog:public CDialog
{
protected:
	CBrush m_brH;
....
}


Initialize in the dialog contructor
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDialog::IDD, pParent)
{
        ...
	m_brH.CreateSolidBrush(RGB(0,0,255));  

return TRUE;
}


Use it elsewhere without releasing:
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if (nCtlColor == CTLCOLOR_STATIC) 
	{                   
             hbr = m_brH;  
	} 

	return hbr;
}

and at last don 't forget to release it:

CMyDialog::~CMyDialog()
{
	if(m_brH.m_hObject!=NULL)
	   m_brH.DeleteObject();
}

Life is a stage and we are all actors!
modified on Thursday, May 20, 2010 10:30 AM

GeneralRe: CStatic Background color Pin
Anu_Bala20-May-10 1:29
Anu_Bala20-May-10 1:29 
QuestionOpen Control panel Using VC++ Pin
Sabid M19-May-10 21:17
Sabid M19-May-10 21:17 
AnswerRe: Open Control panel Using VC++ Pin
Hristo-Bojilov19-May-10 21:41
Hristo-Bojilov19-May-10 21:41 
GeneralRe: Open Control panel Using VC++ Pin
Sabid M19-May-10 22:40
Sabid M19-May-10 22:40 
QuestionRetrive System Serial Number Pin
kushMuchaal19-May-10 20:52
kushMuchaal19-May-10 20:52 
AnswerRe: Retrive System Serial Number Pin
CPallini19-May-10 21:00
mveCPallini19-May-10 21:00 
GeneralRe: Retrive System Serial Number Pin
kushMuchaal19-May-10 22:08
kushMuchaal19-May-10 22:08 
GeneralRe: Retrive System Serial Number Pin
kushMuchaal19-May-10 22:11
kushMuchaal19-May-10 22:11 
GeneralRe: Retrive System Serial Number Pin
Richard MacCutchan20-May-10 2:21
mveRichard MacCutchan20-May-10 2:21 
QuestionButton Size Pin
AbhiHcl19-May-10 19:27
AbhiHcl19-May-10 19:27 
AnswerRe: Button Size Pin
Stephen Hewitt19-May-10 20:03
Stephen Hewitt19-May-10 20:03 
GeneralRe: Button Size Pin
AbhiHcl19-May-10 21:35
AbhiHcl19-May-10 21:35 
AnswerRe: Button Size Pin
Aescleal19-May-10 22:57
Aescleal19-May-10 22:57 
QuestionAbout MSDN Library? Pin
Syouki_kou19-May-10 16:27
Syouki_kou19-May-10 16:27 
AnswerRe: About MSDN Library? Pin
Niklas L2-Jun-10 9:24
Niklas L2-Jun-10 9:24 
Questiondebugging app to find out which code module doesn't decrease a count Pin
abiemann19-May-10 10:43
abiemann19-May-10 10:43 
AnswerRe: debugging app to find out which code module doesn't decrease a count Pin
«_Superman_»19-May-10 10:53
professional«_Superman_»19-May-10 10:53 

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.