Click here to Skip to main content
14,984,271 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Can we give a background or just a color to our dialogus in MFC?
Can we change the text color of buttons?
Posted
Updated 9-Jun-10 22:51pm
v2

1 solution

Sweety Khan wrote:
Can we give a background or just a color to our dialogus in MFC?

Yes, you may handle the WM_CTLCOLORDLG [^] message, see, for instance "Dialog FAQ".


Sweety Khan wrote:
Can we change the text color of buttons?

In a similar way, handle the WM_CTLCOLORBTN message [^].


[added]
You really need some introductory material:
See here [^] for an article series on Windows message handling in dialogs.
[/added]

:)
   
v2
Comments
Sweety Khan 10-Jun-10 4:38am
   
i have write these in my main.cpp

HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
char c;
switch(c)
{
case "WM_CTLCOLORDLG":
return (LONG)g_hbrBackground;
case "WM_CTLCOLORSTATIC":
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(255, 255, 255));
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)g_hbrBackground;
}
break;
}

and write these in that dialoge which i want in color

c=WM_CTLCOLORDLG;
c=WM_CTLCOLORSTATIC;

but got tooo many errors. plz see Pallini, what's wrong with that.

waiting for ur reply
CPallini 10-Jun-10 5:08am
   
"main.cpp"?
You should add a Windows message handler in you window class. See my modifyed reply for a link about the subject.
«_Superman_» 10-Jun-10 6:43am
   
Remove the double quotes around the WM_XXX
CPallini 10-Jun-10 6:48am
   
"Remove the double quotes around the WM_XXX"
And what about the "char c"? :-)
Sweety Khan 10-Jun-10 7:46am
   
i know i dont know enough :(( to do all these things. this article goes above from my head. see is that correct

HBRUSH CdrawbitmapDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

{
if (nCtlColor == CTLCOLOR_EDIT)
{
pDC->SetBkColor(RGB(255, 255, 0)); // yellow
return m_hYellowBrush;
}
if (nCtlColor == CTLCOLOR_DLG)
{
pDC->SetBkColor(RGB(255, 0, 0)); // red
return m_hRedBrush;
}
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
} :doh:

i m getting this error
error C2509: 'OnCtlColor' : member function not declared in 'CdrawbitmapDlg' :((
CPallini 10-Jun-10 8:19am
   
Well, if you haven't generated the message handler using the VS wizard then you have to manually add the method declaration inside the CdrawbitmapDlg class. Add the following line
HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) ;
inside the class declaration.
Sweety Khan 10-Jun-10 12:48pm
   
ohhh. i add this line in my #include "draw bitmapDlg.h" in
class CdrawbitmapDlg : public CDialog

but got these errors
error C2065: 'm_hYellowBrush' : undeclared identifier
error C2065: 'm_hRedBrush' : undeclared identifier

so i declare these
HBRUSH m_hYellowBrush;
HBRUSH m_hRedBrush;

program build successfully but no effect on dialog

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900