943,549 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3471
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 14th, 2009
0

Re: Open Dialog window in MFC

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.
Attached Files
File Type: zip dlgtest.zip (386.8 KB, 32 views)
Last edited by Ancient Dragon; Jul 14th, 2009 at 10:33 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 14th, 2009
1

Re: Open Dialog window in MFC

Your OnSim should look like:

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Jul 14th, 2009
0

Re: Open Dialog window in MFC

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 14th, 2009
0

Re: Open Dialog window in MFC

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
colmcy1 is offline Offline
39 posts
since Feb 2009
Jul 14th, 2009
0

Re: Open Dialog window in MFC

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 15th, 2009
1

Re: Open Dialog window in MFC

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.
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ source file being compiled as C source file
Next Thread in C++ Forum Timeline: Falling letters typing game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC