CWnd* p1 = GetDlgItem(IDC_STATICABOUTVERSION);
CStatic *p2 = dynamic_cast<CStatic*>(p1);
LOGINFO((void*)p1 << " => " << (void*)p2);
}
17:15:34.792 - INFO - CAboutDlg::OnInitDialog() - 016B46A8 => 00000000
Any thoughts?
Bill
Out until Monday - hooray!
AliR.
"Bill Davy" <Bi...@XchelSys.co.uk> wrote in message
news:uoK%232r6LJ...@TK2MSFTNGP02.phx.gbl...
The CStatic version will only work if there's a CStatic or derived object
wrapping the control's HWND somewhere.
If there's no CStatic or derived object, then MFC creates a temporary CWnd
object, which can't be dynamically cast to a CStatic.
Why not just add a CStatic variable to your class instead of using
GetDlgItem()?
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
This may be hard to understand. That's one reason (of many) that GetDlgItem
is best avoided. Use the IDE to create control member variables instead!
"Bill Davy" <Bi...@XchelSys.co.uk> wrote in message
news:uoK%232r6LJ...@TK2MSFTNGP02.phx.gbl...
--
Scott McPhillips [VC++ MVP]
> {
>
> CWnd* p1 = GetDlgItem(IDC_STATICABOUTVERSION);
>
> CStatic *p2 = dynamic_cast<CStatic*>(p1);
>
>
>
> LOGINFO((void*)p1 << " => " << (void*)p2);
>
> }
>
>
>
>17:15:34.792 - INFO - CAboutDlg::OnInitDialog() - 016B46A8 => 00000000
>
>
>
>Any thoughts?
>
****
Yes. Stop using GetDlgItem. It is essentially obsolete for common programming. It is
clear from this usage that it is completely inappropriate; create a class member and just
use it. Don't waste your time trying to use MFC as if it is bare Win32 with no support.
Use it correctly. Forget you ever heard of GetDlgItem; if you are writing more than once
a year, you are not using MFC correctly.
I would write this simply as
c_AboutVersion.SetWindowText(...something useful here...);
you have taken three overly complex lines to accomplish a trivial one-line task.
joe
****
>
>
>Bill
>
>Out until Monday - hooray!
>
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
>The CStatic version will only work if there's a CStatic or derived object
>wrapping the control's HWND somewhere.
>
>If there's no CStatic or derived object, then MFC creates a temporary CWnd
>object, which can't be dynamically cast to a CStatic.
>
>Why not just add a CStatic variable to your class instead of using
>GetDlgItem()?
Correct on all accounts, and as AliR mentioned, RTTI must be enabled for
dynamic_cast to work.
--
Doug Harrison
Visual C++ MVP
Wow, just explored add member. I'm going to spend a few days removing all
trace of GetDlgItem(). Wish the documentation mentioned it was not the way
to go.
Many thanks to you all for your excellent advice.
Bill