Initialize Second Dialog

Hello:

I have a dialog application that I've created, and I can initialize a combo 
box on this dialog box before it is shown.  I also have a menu in this 
dialog.  A selection from this menu opens another dialog box...

   CMyOtherDialog otherDiag;
   otherDiag.DoModal();

However, when I try to initialize a combo box in the otherDiag through the 
constructor, it doesn't work.  I can add a button in otherDiag and once the 
user clicks it, it will populate the combo box, but the constructor doesn't 
do it.  Any ideas?

Saul775
0
Saul775 (62)
6/8/2006 5:08:02 PM
vc.mfc 33608 articles. 0 followers. Follow

9 Replies
688 Views

Similar Articles

[PageSpeed] 58

"Saul775" <Saul775@discussions.microsoft.com> wrote in message 
news:F8061600-9FB5-4423-8024-ADF6497C394F@microsoft.com...

> However, when I try to initialize a combo box in the otherDiag through the
> constructor, it doesn't work.  I can add a button in otherDiag and once 
> the
> user clicks it, it will populate the combo box, but the constructor 
> doesn't
> do it.  Any ideas?

When you construct a CDialog-derived class, the control windows don't exist. 
You have to initialise their contents in the OnInitDialog() member.   That 
is what it is for.

It's no use expecting MFC to be object-oriented  :-)

Dave
-- 
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm



0
dave1 (356)
6/8/2006 5:12:47 PM
As pointed out by David, you will need to do this in OnInitDialog. You
cannot do this in Constructor or in OnCreate of the dialog.

---
Ajay

Saul775 wrote:
> Hello:
>
> I have a dialog application that I've created, and I can initialize a combo
> box on this dialog box before it is shown.  I also have a menu in this
> dialog.  A selection from this menu opens another dialog box...
>
>    CMyOtherDialog otherDiag;
>    otherDiag.DoModal();
>
> However, when I try to initialize a combo box in the otherDiag through the
> constructor, it doesn't work.  I can add a button in otherDiag and once the
> user clicks it, it will populate the combo box, but the constructor doesn't
> do it.  Any ideas?
> 
> Saul775

0
ajaykalra (6841)
6/8/2006 5:32:13 PM
> It's no use expecting MFC to be object-oriented  :-)

I am not sure if this aspect is a OO issue. Its more of a design
badness. In .Net its much more intutive to do this(No OnInitDialog to
deal with).

---
Ajay

0
ajaykalra (6841)
6/8/2006 5:35:00 PM
Thanks for such a quick response!  It worked great!

Actually, could I ask one last question?  How can I pass an argument to the 
constructor of the dialog box class?  I've noticed there's one argument that 
is NULL, which is the parent.  Should I just append to the constructor?  Make 
a new constructor?  Thanks again!

"David Webber" wrote:

> 
> "Saul775" <Saul775@discussions.microsoft.com> wrote in message 
> news:F8061600-9FB5-4423-8024-ADF6497C394F@microsoft.com...
> 
> > However, when I try to initialize a combo box in the otherDiag through the
> > constructor, it doesn't work.  I can add a button in otherDiag and once 
> > the
> > user clicks it, it will populate the combo box, but the constructor 
> > doesn't
> > do it.  Any ideas?
> 
> When you construct a CDialog-derived class, the control windows don't exist. 
> You have to initialise their contents in the OnInitDialog() member.   That 
> is what it is for.
> 
> It's no use expecting MFC to be object-oriented  :-)
> 
> Dave
> -- 
> David Webber
> Author MOZART the music processor for Windows -
> http://www.mozart.co.uk
> For discussion/support see
> http://www.mozart.co.uk/mzusers/mailinglist.htm
> 
> 
> 
> 
0
Saul775 (62)
6/8/2006 5:48:01 PM
> Should I just append to the constructor?  Make
> a new constructor?

Either will work. Its your class; MFC does not restrict this in any
way.

--
Ajay

0
ajaykalra (6841)
6/8/2006 5:52:19 PM
"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message 
news:1149788099.971384.69910@i40g2000cwc.googlegroups.com...

>> It's no use expecting MFC to be object-oriented  :-)
>
> I am not sure if this aspect is a OO issue. Its more of a design
> badness.

It has always seemed to me that creating a CDialog which is not yet a 
dialog, but rather something to which one may be attached, is a lack of 
object-orientation.

Of course one can always get around such considerations by rejecting the 
concept  "CDialog is a dialogue" and substituting "CDialog is a wrapper 
around a dialogue into which a dialogue may, or may not, have been 
inserted".    To that extent you can always get around the idea that "this 
is not object oriented" by redefining what the objects are :-)     But in 
fact the CDialog-derived class already knows the formn of the dialogue which 
will be inserted from the IDD enum defined within the class.   So it is a 
real mish-mash.   Certainly bad design, as you put it  (from the aesthetic 
point of view), but also, I would argue, bad object-orientation leaving half 
constructed objects lying around until a second initialisation phase 
(OnInitDialo) is called.  One gets used to it, and for those of us that once 
used the Windows API in C, the thin wrapper idea was easy to pick up.  But 
I'd hardly use it as a model for my own C++.

> In .Net its much more intutive to do this(No OnInitDialog to
> deal with).

I must look at .net one of these days.   But I use a lot of multiple 
inheritance and bit fields and I suspect that converting a large C++ 
application to that framework would be tedious.

Dave
-- 
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm


0
dave1 (356)
6/8/2006 5:58:55 PM
> Of course one can always get around such considerations by rejecting the
> concept  "CDialog is a dialogue" and substituting "CDialog is a wrapper
> around a dialogue into which a dialogue may, or may not, have been
> inserted".

I see what you mean.

> I must look at .net one of these days.   But I use a lot of multiple
> inheritance and bit fields and I suspect that converting a large C++
> application to that framework would be tedious.

Although MI is not supported, you can have a class which supports
multiple interfaces. However I am not really sure what advantage, if
any, you would gain by porting your code over to .Net. Best you can do
is to use CLI and keep on using existing code in .Net. 

--
Ajay

0
ajaykalra (6841)
6/8/2006 6:22:59 PM
Yup, like Ajay said, either is fine. I usually just append to the constructor 
(remember to leave the : CDialog(IDD, pParent) in your constructor 
implementation). 

Just have a member variable to save the parameter and use that to populate 
the combo box (if that is what the parameters are for) during OnInitDialog()

Isabella

"Saul775" wrote:

> Thanks for such a quick response!  It worked great!
> 
> Actually, could I ask one last question?  How can I pass an argument to the 
> constructor of the dialog box class?  I've noticed there's one argument that 
> is NULL, which is the parent.  Should I just append to the constructor?  Make 
> a new constructor?  Thanks again!
> 
> "David Webber" wrote:
> 
> > 
> > "Saul775" <Saul775@discussions.microsoft.com> wrote in message 
> > news:F8061600-9FB5-4423-8024-ADF6497C394F@microsoft.com...
> > 
> > > However, when I try to initialize a combo box in the otherDiag through the
> > > constructor, it doesn't work.  I can add a button in otherDiag and once 
> > > the
> > > user clicks it, it will populate the combo box, but the constructor 
> > > doesn't
> > > do it.  Any ideas?
> > 
> > When you construct a CDialog-derived class, the control windows don't exist. 
> > You have to initialise their contents in the OnInitDialog() member.   That 
> > is what it is for.
> > 
> > It's no use expecting MFC to be object-oriented  :-)
> > 
> > Dave
> > -- 
> > David Webber
> > Author MOZART the music processor for Windows -
> > http://www.mozart.co.uk
> > For discussion/support see
> > http://www.mozart.co.uk/mzusers/mailinglist.htm
> > 
> > 
> > 
> > 
0
Isa (36)
6/8/2006 10:49:02 PM
"Saul775" <Saul775@discussions.microsoft.com> wrote in message 
news:BA84C85D-B443-4015-BA8F-B296BA63DE82@microsoft.com...

> Actually, could I ask one last question?  How can I pass an argument to 
> the
> constructor of the dialog box class?

If  you are editing the fields of a structure MyStruct, typically you will 
have a dialogue class with a member

    MyStruct m_struct;

and

1. change the constructor to the form

CMyDialog(  const CMyStruct &s, CWnd *pParent )
    :  CDialog( CMyDialog::IDD, pParent )
    , m_struct( s )
{
.....
}

2. Then in

OnInitDialog()

fill in the control variables and do OnUpdateData(FALSE)

3. Then in OnOK()

do UpdateData(TRUE)

and then fill in m_struct from the values of the control variables

4. Then if m_struct is private (as it should be) have a method

const MyStruct & CMyDialog::GetStruct() const
{
    return m_struct;
}

This is pretty standard.  There are plenty of possible variations on it of 
course, but before long you get to be able to write dialogues like this in 
your sleep :-)

[Oh, and if in doubt,  make sure m_struct has a copy constructor and 
assignment operator.  Often the default behaviour will do though.]

Dave
-- 
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm


0
dave1 (356)
6/9/2006 7:27:20 AM
Reply:

Similar Artilces:

Displaying Message from event sink to Edit control in dialog box
Hai I am working on FTP Software using MFC and i have to write the ftp server request and response to tracer window. The server request and response were caught by Eventsink and i donot know how to pass this text to edit control in dialog box which is another class. Here is coding of Event Sink / EventSink.cpp : implementation file // #include "stdafx.h" #include "RoboFTPClient.h" #include "RoboFTPClientDlg.h" #include "Eventsink.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern long gnResult...

Adding second SMTP Virtual Server instance in a 2003 cluster
I need to create a SMTP connector, so I need to create a new SMTP Virtual Server for it. In cluster admin I created an IP address for this resource. Then I tried to create a SMTP Virtual Server. However, after the wizard page where it asks for a dependency and demands a System Attendant, I get the following error. All the virtual server instances for this protocol are already in the cluster. ID no: c1037f37 Is the problem that I am creating the SMTP Virtual Server in the same group that already has one? Is the problem that I need to create a new System Attendant also? -- Matthew Tisd...

Recurrence Question: "Second Tuesday" type recurrence pattern in Outlook
This may be a newbie question, but is there a way in Outlook (directly or via a third-party utility) to make a recurring appointment that recurs, for example, on the "Second Tuesday" or "Last Monday" of every month? <alex.kipnis@gmail.com> wrote in message news:1168452520.516237.83860@77g2000hsv.googlegroups.com... > This may be a newbie question, but is there a way in Outlook (directly > or via a third-party utility) to make a recurring appointment that > recurs, for example, on the "Second Tuesday" or "Last Monday" of every > month...

MCE
This is a software, hardware, and setup problem - so I cross posted it. Hardware/Software/firmware/drivers: ------------------------------ Windows XP SP3 Media Center Edition (MCE) w/all current updates, Pinnacle PCTV 800i HD PCI card (coax cable from DirecTV satellite tuner), ATI Radeon HD 3200 graphics card, AMD Athlon Dual Core processor 2.5 GHz, 1.75 GB RAM, official (came in the MCE box) IR sensor and blaster. MCE has all current updates. Current firmware and drivers are installed for the PCI TV card, the motherboard, the processor, and the graphics card. The Windows...

Dropped Initial Word
I have Office 2007 Word running on XP Service Pack 2. I know how to make a drop cap for the starting paragraph in a paper. Is there any way to make the entire first word drop 2 or 3 lines depending on what I need? As an example if I were to type the sentence "Now is the time for all good men to come to the aid of their country." I would want to drop the word Now not just the N. Select the whole word and then apply drop cap formatting. -- Stefan Blom Microsoft Word MVP "Deej Hernandez" <DeejHernandez@discussions.microsoft.com> wrote in message...

Refer to Listbox second column
Dear All, Can we refer to listbox second column,and then transfer the second column value on the listbox click even. And Also how to open an excel workbook files through a cmd button.I usually using hyperlink address but it doesn't seem cute. Thank's combo and list box columns can be addressed using the columns collection. Me.MyTextBox = Me.MyListBox.Column(1) Note that the columns start numbering at 0, so the second column is (1). You can open an excel workbook with the Shell command. See details in VBA Help. -- Dave Hargis, Microsoft Access MVP "shiro" wrot...

Constructor initialization
Hi, Why do CMyClass::CMyClass() : m_iMyInt(0) // initialize { } instead of CMyClass::CMyClass() { m_iMyInt = 0; // assign } The first seems preferred, but I've always done the second (Self taught C++ so I don't know all the theory). Hi, When a class is instantiated, and for the purposes of this post lets leave inherited classes out of the picture, after the physical memory is allocated the members constructors are called and then the classes own constructor. When the members are constructed, the default constructor is called and then when your constructor executes th...

faq initialize CList
Hi, I have a member viarable of CList<CPoint,CPoint&> m_pointlist in Class Segment. Should I have to initialize the m_pointlist in Segment constructur? Thanks. The CList has a constructor with a default parameter (block size = 10). If that number satisfies you, you do not need to worry about initialization. Otherwise, follow this syntax: class Segment { private: CList<CPoint, CPoint&> m_pointList; public: Segment() : m_pointList( 100 ) // Place your own number instead of 100... { } } or class Segment { private: CList<CPoint, CPoint&> m_point...

creating Dialog
The following question should be very easy to answer : I am splitting my application into several Dll and I am getting into troubles with my resources. I have built an MFC Dialog and the associated class using the wizzard in one of my Dlls. This Dialog is called by the main application and it cannot open for any reason. If the dialog id defined as Child, it does not crash but it does not open, otherwise it crashes. Help !!!!!!!! MFCBeginer wrote: > The following question should be very easy to answer : > > I am splitting my application into several Dll and I am > getti...

Second Unicode Query
I want a program which recognize the default language of system and should be convert into default language whether it's in any language. for example I made an application in English. now if i run my application on a system whose default language is Greek then my application should be open in Greek. Tell me what should i do to solve my problem. Please reply as soon as possible Hi, In this case you can have 2 separate resource DLL's, say 1 for English and 1 for Greek. Based on the language load the appropriate resource DLL. Balaji "Manoj" <cmanoj@stellarinfo.com>...

Changing initials into numbers
I have data that I download into Excel and initials are used for different people. I need to give those initials a number in excel for example MJ = 01, HS = 02..etc. Thank you. On 2/3/2010 9:26 AM, Kathie wrote: > I have data that I download into Excel and initials are used for different > people. I need to give those initials a number in excel for example MJ = 01, > HS = 02..etc. Thank you. see VLOOKUP in Excel help. Bill Kathie You have to be more specific. Where are the initials (column, row, sheet)? Where do you want the numbers placed? HTH Otto &quo...

Possible to Look Up Records by Initials?
I have a user who's telling me that prior to this weekend in CRM, she could lookup user records by initials rather than typing in part of the name. I don't see where that setting would have been marked in CRM. Has anyone else heard of this? If so, how did you implement this type of search customization/configuration? Steps to recreate problem: Account screen Account Owner field's magnifying glass Assign Account Assign to another user fields magnifiying glass Look Up Records' Look For field = initials of user you're attempting to Find. I doubt you can use the init...

Capture initial value of text box
Not sure why I can't seem to get this to work, but here's what I'm trying to do: I have a text box, 'Actual_Due_Date', tied to a field in a table. In the same table is a text box named 'Org_Due_Date'. When the initial value is set in the 'Actual' field, I want to capture and store it permanently in the 'Org' field. I have two forms, a New Project form and an Edit Project form. My thought was to just setup a simple macro in the New Project form in the 'Actual' field that says After Update set the 'Org' field equal to the 'A...

Remove middle initial from "first name middle initial"
Hello Excel Gurus, I've been searching the site for an answer to this question but as yet no luck. If I missed a previous post on this topic I apologize, please direct me to it. I have 1 column with a series of people's first names. Many have a middle initial, some don't. About half of the cells are of two people's names joined by an "&". Sample data below: Frank & Debbie J Marshall & Teresa Timothy R Jeffrey D & Eileen N Pamela J James R & Rachel Brooke S Myung S Martin F & Susan A Kathleen I need remove the middle initial and preserve...

Dialog Boxes
Hi, I am wanting to create and design a dialog box to open up in my workbook in excel but cannot remember how to start. I would be very grateful for help on this matter. Cheers What type of dialog box? Interactive or static? Simple one could be like Private Sub Workbook_Open() whatname = InputBox("enter your name here") MsgBox "Hello there " & whatname & ". What can I do for you today?" End Sub Placed in Thisworkbook module. Gord Dibben MS Excel MVP On Sat, 14 Oct 2006 19:38:13 GMT, "Martin" <martin.lovett@tesco.n...

'Assign Macro' dialog missing in Excel XP
I'm trying to assign a macro to a command button, however the 'Assign Macro' dialog is missing from the context menu when right clicking the button. I have only been to do it when having opened an old worksheet (created in excel 97) with existing command buttons & macros, then the option is there to assign a macro. I have searched the net for a solution however to no avail. I know it is possible since Excel Help states that is the official way to do it. I have office Xp installed with service pack 2. I hope you will be able to help me. Thank you It's possible ...

How can I call a function from an MFC Dialog upon start up
How can I call a function from an MFC Dialog upon startup without having to call it from the OnPaint() method?. I want the dialog to complete the OnPaint() and then call a function?. I am needing an Install Dialog that has a Status bar and automatically executes without any user interaction. So far I managed to get a dialog working with the status bar and by calling my install function from the OnPaint() method, but ofcourse that is not the way to program!. Thanks for any solution in advance. Robert Carlson Aqweeva Software robert@aqweeva.com Robert wrote: > > How can I call a fun...

Initializing Correct DATE
When I open Money, and start posting transactions to my accounts, the first transaction would be dated Sept. 23, 2008 INSTEAD of October 23, 2008; In other words, I must manually override the date when entering my first transaction in my account!! I NEVER had to do this before; any suggestions as to how to repair this anomaly?? Thanks, FLKulchar In microsoft.public.money, F. Lawrence Kulchar wrote: >When I open Money, and start posting transactions to my accounts, the first >transaction would be dated Sept. 23, 2008 INSTEAD of October 23, 2008; > >In other words, I must m...

Initial size for SDI app
I want to set the initial dimensions(height and width) for my SDI app. Also I don't want to allow the user to decrease the height and width of the app from the default values initially set when opened up, but would want to allow the size to be increased, if he resizes. Thanks "MFC" <MFC@nospam.com> wrote in message news:u0vK%23MmrFHA.3476@TK2MSFTNGP10.phx.gbl... >I want to set the initial dimensions(height and width) for my SDI app. Also > I don't want to allow the user to decrease the height and width of the app > from the default values initially set wh...

Move controls in dialog area
Hi, Bit of a newbie to VB.NET. I'm using 2003.NET. I have a project with a number of controls, but I cannot move the controls around at design time using the Up/Down/Left/Right cursor keys. I can drag the controls around with the mouse only. What's going on here? I was sure I could do this in VS2003.NET with my VC++ projects, but now I've even opened up one of those projects and still cannot. Seems like I've changed some setting that I cannot find. I've tried (with control I want to move selected): * Pressing arrow key * Pressing arrow key + LEFT_SHIFT ...

? Best Way to Set/Initialize Multiple Parameters
Hi, I thought I'd ask something that's been bugging me for years. It's happened to me on many occasions where I would be writing a class and I end up extending it to the point that it has a whole bunch of different parameters. At first it's fine; there's no problem with constructors and initialization routines for classes that have two or three parameters, but when I get to the five or six parameter point, those functions become unwieldy (especially if there are defaults). Of course there are always separate functions to set each member variable (or group of related varia...

dialog box #2
how do i make a custom dialog box? any help would be greatfully appriciated thanks! Tom Ogilvy recently posted a list of resources for getting started with UserForms: http://groups.google.com/groups?&threadm=O%24VViE9UEHA.2520%40TK2MSFTNGP12.phx.gbl ash wrote: > how do i make a custom dialog box? > any help would be greatfully appriciated thanks! > -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

outlook set up second user email
have set up a second user account in Outlook XP 2002 but having probs. I have the bigpond account name etc but when dialling out get message 691 message of username or password invalid. thxs ...

Two Dialog Resources, one dialog object?
Can someone please tell me if it is possible to have two dialogs in my resource view that link to the same dialog object? or will I have to implement a 'dialog functionality' object that is called from my event methods? I want to allow my users to choose from two different sized dialogs (one large, one small) depending on their registry settings. The dialogs would essentially be the same, with identical controls, just different layouts. Alternatively, is there any way to dynamically 'scale up' my dialog whilst still allowing it to be edited in resource view? I am using Visua...

Linking Dialog box content with cells in "regular" sheet
How to link data in Edit box (from Dialog caption) with exact cells in "regulal" Sheets? Or is there another way to link exact content from Dialog sheet to normal sheet? For example, if I have number 200 in Dialog, I need that exact number 200 on another ("regular") sheet to preform calculations with it. thnx ...