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 )
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