Re: Setting value to static text control at runtime
On 5/14/2010 10:32 AM, SM wrote:
Hi,
I have a dialog box(About dialog) and it contains three static text
controls.
Now I need to set the value to the one static control in run time, so
I changed the ID from IDC_STATIC to IDC_Test
CSimpleDialog<IDD_TESTDLG> dlgTest;
//dlgTest.SetDlgItemTextA(IDC_Test,_T("Test"));
//GetDlgItem(IDC_SOC_Version).SetDlgItemTextA(IDC_Test,_T("Test"));
dlgTest.DoModal(m_hWnd);
GetDlgItem(IDC_SOC_Version).SetDlgItemTextA(IDC_SOC_Version,_T("Test"));
while running the application i'm getting assertion as
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: ...\AllVCLanguageSamples\C++\MFC\ole\TstCon\Release
\TstCon32.exe
File: d:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlwin.h
Line: 1320
Expression: ::IsWindow(m_hWnd)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
I tried moving the getdlgitem before domodal and it also throw error.
Tried SetDlgItemTextA , same error only.
How can I set value to static text control?
You need to add 'OnInitDialog' to your class (RTFM about it). If you
don't have a class, you need to make one (subclass your 'CSimpleDialog'
for that), and set the text in that function. That's the place that
gets executed *before* the dialog shows up on the screen and *after* all
controls have been created from the dialog template. Essentially you're
going to be "tapping" into 'DoModal' that way.
Another possibility is to generate the dialog template dynamically and
use 'DialogBoxIndirect' function, but I think this is more work than the
former approach.
V
--
I do not respond to top-posted replies, please don't ask