Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual C++ - dynamic static controls (changing font etc...)

19 views
Skip to first unread message

Chris Hall

unread,
Aug 14, 1999, 3:00:00 AM8/14/99
to
Hi,
I am creating a program that must dynamically create controls in a dialog,
such as CStatic or CButton objects.
This dialog could have 1 or more objects, so the program will not know until
run-time. I am doing this at the moment:

staticText = new CStatic();
staticText->Create( line, WS_VISIBLE | WS_CHILD, CRect, this,
IDC_STATICTEST);
[with a CStatic staticText member]

or

(new CStatic())->Create(line, WS_VISIBLE | WS_CHILD, CRect, this,
IDC_STATICTEST);

1. Am I going about it the right way?

I can not change the default font either, which is 'System'.

2. How do I change the attributes of a dynamically created control?

Cheers

( Reply to: pmo...@clear.net.nz )

Laszlo Radanyi

unread,
Aug 20, 1999, 3:00:00 AM8/20/99
to
> (new CStatic())->Create(line, WS_VISIBLE | WS_CHILD, CRect, this,
> IDC_STATICTEST);

This is the least preferred way unless you use a garbage collector.
The C++ object created by new will never be destroyed, thus you leak memory.

> 1. Am I going about it the right way?

"THE" right way ? :-)
But I get curious. If you can keep a CStatic member to hold the dynamic
instance, then how can you NOT know that you need the control ?

> I can not change the default font either, which is 'System'.

HFONT hFont = (HFONT)GetStockObject( SYSTEM_FONT );
BOOL bRedraw = FALSE;

::SendMessage(hwnd, WM_SETFONT, hFont, MAKELPARAM(bRedraw, 0 ));

or, (more or less) MFC-wise:

staticText->SetFont( CFont::FromHandle( hFont ), bRedraw );

> 2. How do I change the attributes of a dynamically created control?

1) Win32-way: through various SendMessage calls, preferably through C++
wrapper classes,
2) MFC-way: through the standard property methods for CWnd and specialized
methods for the various controls as described in the MFC docs.

---

For the task described you don't need MFC - you can do easier using standard
C++ techniques and reading the Win32 API. CheckOut www.relisoft.com for
examples.

The VWCL project ( www.vwcl.org ) also has a much usable library that wraps
much of the standard functionality of the Win32 API. I'd suggest you check
out these two sites and their examples and source code before learning Win32
through MFC.

If you absolutely want support from a Microsoft class library, check out ATL
to produce reasonably compact code.

---

Good Luck !

/Laszlo

mvoe...@gmx.de

unread,
Aug 23, 1999, 3:00:00 AM8/23/99
to
You have to change the font of the window after creation. If you want to,
I can send you a small set of helper classes, which are covering easy font
manipulation on windows.

0 new messages