GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Sep-2004, 06:36
Frandy Frandy is offline
New Member
 
Join Date: Sep 2004
Location: Italy
Posts: 19
Frandy is on a distinguished road
Unhappy

Dialog based application


Hello:

My dialog based program consisting of 1 input & 1 output boxes (for double variables) is working fine.
Now, I'd like to get the output in a second dialog window that should appear when I hit a button on the first :-x one.
The window #2 should offer a top level button for printing the output.
What should I do ?
Detailed replies will be very much appreciated as I'm only a beginner.
Thanks a lot.

Frandy
  #2  
Old 27-Sep-2004, 07:36
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,037
LuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really nice
Quote:
Originally Posted by Frandy
Hello:

My dialog based program consisting of 1 input & 1 output boxes (for double variables) is working fine.
Now, I'd like to get the output in a second dialog window that should appear when I hit a button on the first :-x one.
The window #2 should offer a top level button for printing the output.
What should I do ?
Detailed replies will be very much appreciated as I'm only a beginner.
Thanks a lot.

Frandy

Took me a lot of time to answer, didn't it?
Sorry about that, I'm a bussy man...
As other people might do this in another way, I will encourage them to post their opinion on this. I will show you how I do it (this is *my* awesome way ).

First, let's consider your 2 dialog classes are CDialogOneDlg and CDialogTwoDlg.
Then, in add this include:

CPP / C++ / C Code:
#include "DialogTwoDlg.h"

Then, call the second dialog when user clicks "Button":

CPP / C++ / C Code:
void CDialogOneDlg::OnButton() 
{
	CDialogTwoDlg secondDlg(this);
	int nRetCode = secondDlg.DoModal();	

	if ( nRetCode == IDOK )
	{
//		if the second dialog box was closed by pressing "OK"
//					do what you please/need		
	}

}

Also,in DialogTwoDlg.h, include the header of CDialogOneDlg:

CPP / C++ / C Code:
#include "DialogOneDlg.h"

And in the member data area of CDialogTwoDlg, add a pointer to your first dialog (also in DialogTwoDlg.h)

CPP / C++ / C Code:
	CDialogOneDlg * dlg;

In DialogTwoDlg.cpp, you will have the constructor defined something like:

CPP / C++ / C Code:
CDialogTwoDlg::CDialogTwoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogTwoDlg::IDD, pParent)

Add to this constructor this simple line of code:

CPP / C++ / C Code:
	dlg = (CDialogOneDlg *)pParent;


Now, you have a reference to your first dialog that you can use in your second one!

Of course, you must make the data you are trying to use from your first dialog a member of your first dialog's class:
Let's say you have a member data defined like this in DialogOneDlg.h:

CPP / C++ / C Code:
	double a[20];
// member data of CDialogOneDlg

You can use this in the second dialog like this:

CPP / C++ / C Code:
BOOL CDialogTwoDlg::OnInitDialog() 
{
	for (int i = 0; i < n; i++)
	{
		dlg->a[i] ...;
	}
}

I sure hope this was clear enough...If not, pls. let me know where is it you need more help and I'll provide it for you.

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 02-Oct-2004, 11:53
Frandy Frandy is offline
New Member
 
Join Date: Sep 2004
Location: Italy
Posts: 19
Frandy is on a distinguished road
Thanks for your reply.
Unfortunately, my second dialog has been created by means of the Menu/Insert Dialog. So, you have no OnInitDialog() in the DialogTwo.cpp.
In the meantime, I've been using a list box to display the results. BUT, I don't know how to print the results on my printer by pressing a button on the main dialog.
Have you any idea?

Thanks again.

Frandy
  #4  
Old 03-Oct-2004, 23:55
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,037
LuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really nice
Quote:
Originally Posted by Frandy
Thanks for your reply.
Unfortunately, my second dialog has been created by means of the Menu/Insert Dialog. So, you have no OnInitDialog() in the DialogTwo.cpp.

Oh, you don't need to wory about that. You see, the OnInit method is just handling the dialog's "reaction" to an event. So, you can just add it in. I suppose you didn't create a class for your dialog either? If this is the case, just double-click the surface of your dialog box, and you'll be able to add a clas for it. You can jiust name it CDialogTwoDlg. Then, go to Class Wizard, to the "Message Map" section, and add this meesage: WM_INITDIALOG (you'll need to scroll down quite a bit). Click Add Function, and then Edit Code.

Quote:
Originally Posted by Frandy
In the meantime, I've been using a list box to display the results. BUT, I don't know how to print the results on my printer by pressing a button on the main dialog.
Have you any idea?

Thanks again.

Frandy

Well, you could do this pretty easy, if you used the Document/View architecture. Tis would imply working with a MDI or SDI application rather than a DIALOG-based one.
In case you decide to go with this, please take the time to read this (very small) tutor.
Don't get me wrong, it's not my style to point to a faq, but I think you will find this very useful.
For any concerns you might still have, please don't hesitate to ask.

Best regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Specified CGI Application Misbehaved by not running a complete set of HTTP Header SSS Computer Software Forum - Windows 2 16-Oct-2006 23:01
Send and receive data through port using MFC Dialog Based mithila MS Visual C++ / MFC Forum 1 10-Sep-2004 02:01
How to let Enter-key-press message goes to ActiveX control on dialog Yuri MS Visual C++ / MFC Forum 3 08-Sep-2004 07:40
daialog based application MFC Pandiani MS Visual C++ / MFC Forum 2 01-Aug-2004 10:45
controling dialog objects & multiple source files omills MS Visual C++ / MFC Forum 0 14-Jul-2004 23:30

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:04.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.