hi
i wanna set a value for a CEdit control on a dlgbox, from within a non-class member function which resides in the cpp file of the dlgbox. what's the correct way to do this?
thx.
Printable View
hi
i wanna set a value for a CEdit control on a dlgbox, from within a non-class member function which resides in the cpp file of the dlgbox. what's the correct way to do this?
thx.
But perhaps you can elaborate a little more on what you're trying to do and show some code.Code:dlg.yourcontrol.SetWindowText("...");
sorry not a CEdit it's a CList.
tried this but i get an assertion faliure:
i do this in a non-class member function.Code:CServerDlg sd;
sd.m_clrecvd.InsertString(-1, szServerW);
Did you create the dialog first?
This is the typical sequence if you want to initialize data inside your dialog before showing it.Code:CServerDlg sd;
sd.Create(IDD_YOURDLGID_HERE);
sd.m_clrecvd.InsertString(-1, szServerW);
EnableWindow(FALSE); // Disable parent
sd.ShowWindow(SW_SHOW);
sd.RunModalLoop();
EnableWindow(TRUE); // Enable parent
sd.DestroyWindow(); // Destroy window
ow... it's the default dlg of a mfc project. im just trying to insert a string into a clist on it -- from a function which is not in dlg's members list.
Ya, create an object of the class and create the window first, then you can add items to the list. You can't add items to a nonexistant window.
Just make a function or something.
If the dialog is created then you can mess around with it all you want.
the dialog exsists -- it displays. what i want is to change things within it from an outside function. maybe that's not possible?
It is. So long as you create it before.
Common belief may be that when you do
It also creates the window. But it doesn't.Code:CServerDlg sd;
It actually creates the dialog when you do
Therefore, you can't just doCode:sd.DoModal();
Because the window (or its child window [or controls]) have not been created yet.Code:CServerDlg sd;
sd.m_clrecvd.InsertString(-1, szServerW);
The solution is to do what I posted above. Call Create to create the dialog first, THEN add your strings to the list.
Then you have to emulate the behavior of DoModal yourself because it will ASSERT if you've created the dialog before the call to the function.
Or, if you just want a modeless dialog, just call ShowWindow.
ok thx i'll do that.
I always test the control exists with GetSafeHwnd() before adding to it from another app/dlg.
I also use GetParent(). If a child dlg wants to update the LV on the parent, it calls a wrapper method;
GetParent()->InsertLVItem(iIndex,sText);
If not a child dialog then
AfxGetApp() will get the main apps CWnd.