Re: MFC, Multiple Dialogs, List boxes And Other Stuff
To pop up a dialog when you press a button, do something like this:
void MyMainDialog::OnButton()
{
CChildDlg dlg;
if (dlg.DoModal() == IDOK) {
m_nMyVar = dlg.m_nOption1;
}
}
Each dialog class, such as CChildDlg, will have it's own OnInitDialog()
handler. Just call the base class (CDialog) first. For lists, get a
pointer to the List and do an AddString().
BOOL CChildDlg ::OnInitDialog()
{
CDialog::OnInitDialog();
CListCtrl* pList = (CListCtrl* )GetDlgItem(IDC_LIST1); // or use the
Class Wizard to get a pointer
pList->AddString(_T("Item1"));
pList->AddString(_T("Item2"));
// etc.
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
--
---------------------------------------------------------------------
DataGet? & PocketLog? www.dataget.com
Data Collectors www.baxcode.com
--------------------------------------------------------------------
<andy@f1-software.com> wrote in message
news:1165245391.219946.67190@n67g2000cwd.googlegroups.com...
Hi =)
I am fairly new to MFC and Visual C++ (2005 Edition, Standard), I have
mainly worked on game programming and done nothing with GUI and
interface settings. A recent project has got me started and I am having
some problems that I am not really sure how to solve. Any help would be
grateful =)
I am able to create a default dialog window, add controls, talk to it
etc. My problems tend to stem more when it comes to adding multiple
dialogs to the project. For example, say I want to have 5 or 6
different windows that open up at various points depending on which
buttons have been clicked, such as an options window, or confirmation
window. I seem to be having a hard time seeting up an OnInitDialog()
event that will allow me to populate the gadget data with defaults, or
loaded data. I have tried to override it myself (which doesn't appear
to be working) and tried an OnCreate() event which again doesn't appear
to be doing anything. I am creating a new project, adding a 2nd dialog
and trying to populate a text string and a listbox control. I am going
dizzy reading all the documentation and appear to be going around in
circles =)
I am also having problems with simple list boxes. It seems I cannot add
any strings to the box at all. It either does nothing at all, or the
app crashes completely when the window is closed. This only seems to
happen on the windows created other than the first default window =) Do
any documents exist on how to effectively use the multi-column portions
of the listbox?
I was also wandering if there was a way to easily communicate through
any of my windows with simple variable calls, instead of having to add
functions to each dialog screen to query it's values. I know I can
access the variables, and was wandering if there is an easier way
besides directly accessing each dialog, so I can query the data for 3
windows in just one function.
Do any good tutorials exist that cover multi-dialog applications, and
how to override various bits and pieces etc.?
I apologize if some of my questions don't make sense =) If you need
more information, let me know.
Kind Regards
Andy 'Fish-Guy' Kellett
andy@f1-software.com