Re: Setting value to static text control at runtime
On 5/14/2010 11:27 AM, SM wrote:
On May 14, 8:09 pm, Victor Bazarov<v.baza...@comcast.invalid> wrote:
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
Hi,
I don't have class for that dialog and only resource file.
I'm using VS2008, how to add class for that dialog, any wizards
avaliable, or simply class file i need to add?
There are different ways. Get yourself a book on MFC programming, and
study, it's not something that can be fully explained in a newsgroup
posting.
In the mean time, you could try doing
/// file MyAboutDlg.h
#include <....> // not sure what you need here, RTFM
class MyAboutDlg : public CSimpleDialog<IDD_TESTDLG>
{
public:
MyAboutDlg(HWND hParent)
: CSimpleDialog<IDD_TESTDLG>(hParent) {}
protected:
BOOL OnInitDialog( ??? don't remember, RTFM );
};
// file MyAboutDlg.cpp
#include <MyAboutDlg.h>
BOOL MyAboutDlg::OnInitDialog(...
{
... // I think you need to call the base class, RTFM
// do your 'SetDlgItemText' here:
this->SetDlgItemText(IDC_Test, _T("Test"));
return ... // don't remember, RTFM
}
V
--
I do not respond to top-posted replies, please don't ask