Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

basic mfc help

Posted on 2004-04-06
4
Medium Priority
?
299 Views
Last Modified: 2013-11-20
Howdy,

I've just started dabbling in MFC after a few years of c++.  I had a short introduction to MFC book lying around so i thought i'd give it a shot on a project for one of my friends.  So far i think i've been doing pretty good using that book along with the MS site, but i've ran into a few problems and i'd kind of like to know some answers.

1.  What is the alternative for DoModal() ?  I mean, how can i make a child/popup window that allows the user to access the parent window?

2.  How do i make things load automatically when a popup Window is created?  For instance i want a name to be loaded into a text box when one of my dialog classes is instantiated.  If i put that code in the constructor it blows up on me because the DoModal() function hasn't been called.  I always have to have a button saying something similar to "show results", and when its clicked it loads the values on the screen.

If you want to see some of my code let me know, but more or less i just want to know some general ideas.

Thanks,
--Jason

0
Comment
Question by:solman66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 10771853
1) Alternative of DoModal is modeless dialog. See CDialog::Create function. Notice that if you use modeless dialog, it is better to keep dialog instance as member of parent dialog class, because modeless dialog exists when function which creates it exits.

void CParentDialog::CreateUnmodalChild()
{
    m_Child.Create(...);  
}


2) Initialize dialog controls in OnInitDialog function. When parent initializws child dialog, it may set it's members which are not linked to controls. In OnInitDialog these members are used to set control values.

void CParentDialog::ShowModalChild()
{
     CChildDlg dlg(this);
     dlg.m_sString = "...";     // m_sString is CString
     dlg.DoModal();              // in CChildDlg::OnInitDialog use m_sString to show in some control
}
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10774201
The reason your software "blows up" when you try to initialize the text box is that the control is not yet displayed on the screen, and the routine you use (probably SetWindowText()) expects the control to be already created and displayed. Use AlexFM's suggestion to first set a member variable in your dialog class. By just setting this variable you are not making any assumptions about what's already displayed. Once OnInitDialog() is called, you know that the controls are created and you can safely use any methods to initalize them.
0
 
LVL 2

Author Comment

by:solman66
ID: 10779002
Thanks!

That worked perfectly, i have a few other questions that i want to try to work out myself, but if i have any other ones i can't find easily i know where to come.

I was pretty sure that was the reason the program would blow up, but its always niced to be re-assured.

Now i can go back through and re-write alot of my code.

One day last week, I had tried the "create" function to create a modeless dialog, but i don't think i was doing it right, i guess my only question about it is to make sure i understand m_Child correctly.  I'm taking that as an object of my child class, declared as a private member variable in the parent class.  If you don't get back to me on that its no big deal i'll probably test it out here later tonight.

Thanks again!
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10780765
>> Object of my child class, declared as a private member variable in the parent class.

Right.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question