Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set dialog text font style and color

Status
Not open for further replies.

SeagullVN

Technical User
Oct 10, 2002
8
VN
Hi All,
I want to change font style and color for the text on my dialog but I do not how to do it. Could anyone please help me?
 
The font style can be changed easily on the "General" tab of the dialog properties by pressing the "Font..." button.
To change the color, you have to implement your own message handler function for WM_CTLCOLOR. It can be added by ClassWizard. In this function you have to change the color of the text with the SetTextColor function, and return your own brush.
I give you an example, tell me if it helps:
Code:
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	pDC->SetBkMode(TRANSPARENT);

	switch(nCtlColor){
		case CTLCOLOR_DLG :
		case CTLCOLOR_BTN :
		case CTLCOLOR_STATIC :
// define your own brush if you want to paint the background
			hbr=m_ctlBrush;
// if you want to change only the text color, the brush
// definition is not necessary			
			SetTextColor(pDC->m_hDC,yourColor);
	}
	
	return hbr;
}
 
Thank you very much! It really helped me!
Could you please help me more?
The next problem is:
When I choose font style by button "Font" on the dialog, the font of all dialog controls are changed!
How can I change font style for each control on my dialog?
Please help me!
Thanks in advance!
 
You need to define your own desired fonts with CreateFont. After that you can select the returned handle with SelectObject into the device context for painting the control. You should do this in the OnPaint function of each control. In this case you have to derivate your own classes for the controls and overwrite the OnPaint function.
It sounds complicated, and actually it is, but I don't know other method, I just suspect that there must be an easier way to do this.
 
I will follow your guide.
Thank you very much for helping me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top