Open Dialog window in MFC

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Open Dialog window in MFC

 
0
  #11
Jul 14th, 2009
When you double click on the button as I showed previously the VC++ 6.0 IDE will create the correct message map entry for you -- you do NOT have to code that yourself. After clicking that button, the message map in the *.cpp file should like something like this:
BEGIN_MESSAGE_MAP(CDlgtestDlg, CDialog)
	//{{AFX_MSG_MAP(CDlgtestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

And in the *.h file
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CDlgtestDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButton1();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
}

Attached is the complete project I made, minus compiler-generated files.
Last edited by Ancient Dragon; Jul 14th, 2009 at 10:33 am.
Attached Files
File Type: zip dlgtest.zip (386.8 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Open Dialog window in MFC

 
1
  #12
Jul 14th, 2009
Your OnSim should look like:

  1. void YourFirstDialog::OnSim()
  2. {
  3. CSimConFig dlg;
  4. dlg.DoModal();
  5. }

Please reread the manual concerning the return values of DoModal(). There is no point in comparing the return value against control IDs.
Another strange thing: are you sure the Button is in CMainFrame? Usually you only have IDs of menu items with ON_COMMAND handlers there.
Last edited by jencas; Jul 14th, 2009 at 11:30 am.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Open Dialog window in MFC

 
0
  #13
Jul 14th, 2009
>>Are you sure the Button is in CMainFrame?

Dialog projects do not have a CMainFrame class (assuming he created a dialog project, not SDI or MDI)
Last edited by Ancient Dragon; Jul 14th, 2009 at 11:32 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 35
Reputation: colmcy1 is an unknown quantity at this point 
Solved Threads: 0
colmcy1 colmcy1 is offline Offline
Light Poster

Re: Open Dialog window in MFC

 
0
  #14
Jul 14th, 2009
Hey AncientDragon and Jencas,

thanks a million for all your help. From looking at your example AncientDragon I think I may finally understand what is going on. Again thank you for posting that. Could I ask one small favour from you guys, could you recommand a good book for MFC, I have "Introduction to MFC Programming with Visual C++" by Richard M. Jones and "Professional MFC with Visual C++ 6" by Mike Blaszczak but im finding it hard to dig what I want from these two books. Is there any "bible" book for MFC like "Programming principles and practice using C++" by Bjarne Stroustrup book is for C++? Thanks again for all your help and time.

Colm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Open Dialog window in MFC

 
0
  #15
Jul 14th, 2009
There have been many major changes to MFC since that compiler was released. I started learning it by doing the Scribble Tutorial

That tutorial will not be useful on VC++ 2005/8 compilers.
Last edited by Ancient Dragon; Jul 14th, 2009 at 12:35 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Open Dialog window in MFC

 
1
  #16
Jul 15th, 2009
The source code for VS2005/8 can be found at http://msdn.microsoft.com/en-us/libr...ts(VS.80).aspx
Last edited by jencas; Jul 15th, 2009 at 7:20 am.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC