Setting font in GroupBox

Posted on 2013-11-01
Last Modified: 2015-05-17
The code below used to work in VC++ v6.0. It has stopped working in VS2010, Win 8.
The idea is to set the font of all the controls in a dialog box at runtime.  The code works below works exactly as expected EXCEPT that the font in the group box controls is not changed.  I suppose I could try sub classing  the group boxes but I would rather do something easier.   Don't feel bad, I don't really expect to get a solution here ...

This code is in the OnInitDialog() function:
	CWnd* pChildWnd = GetWindow(GW_CHILD);
	int iCount = 0;
	while (pChildWnd)
		CString sTest;
		iCount ++;
		sTest.Format("control %d",iCount);

		pChildWnd = pChildWnd->GetWindow(GW_HWNDNEXT);

Open in new window

Question by:Hey_Bud
  • 3
  • 2

Accepted Solution

Hey_Bud earned 0 total points
ID: 39622178

The dialog box was not derived from CDialog,  but from a third party dialog class which apparently does not work "exactly" as expected.  If the dialog box is derived from CDialog, everything works as expected.

Thank you ...
LVL 33

Expert Comment

ID: 39622207
are you using id numbers for the group boxes? or do they have IDC_STATIC as id?

if the latter you may try to change that.

in your test, does the text of the group boxes change by the call of SetWindowText?

if no, the text label of a group box probably has changed to a child window of the group box control. if so, you would need to have a further loop for each control to get their child windows as well. this nested loop also would help to set the font of combo boxes both for the edit and the list part.


Author Comment

ID: 39622408
I said:
"The code works below works exactly as expected"

If each dialog item did not have a unique ID, this would not have happened.

"the text label of a group box probably has changed to a child window of the group box "

Good Grief!

I  have indicated what was wrong above.
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

LVL 33

Expert Comment

ID: 39625034
"If the dialog box is derived from CDialog, everything works as expected."

sorry I missed that comment.

the text label of a group box probably has changed to a child window of the group box
Good Grief!
hmm. it was a guess as you stated that the groupbox control doesn't accept a new font for the control. the change you made by deriving from CDialog instead of  a 3rd-party dialog, does not explain why your original code did not work for group boxes. the control would apply the new font if it was a CGroupbox or was derived from CGroupBox beside they added an own paint function or the text part was a child window or they restored the old font after your function. you probably can see with spy what happened.


Author Comment

ID: 39625094
I have contacted the third party vendor.  They  have admitted this bug and sent a fix.  I have no further need to pursue this matter.
LVL 45

Expert Comment

ID: 39625217

Please accept your comment: http:#a39625094 as the solution.

aikimark -- zone advisor

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
Java Loop 6 59
How to Convert a Quote to an Order in SalesForce 2 35
T-SQL: Preventing Duplicate Records from Being Returned When "Joining" Code Blocks 2 43
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now