943,929 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 879
  • C++ RSS
Jul 2nd, 2009
0

Need some help understanding MFC

Expand Post »
I'm having some of trouble understanding exactly how an MFC GUI works.

What is the resource file for and exactly how does it relate to the classes you create (e.g. the subclass of CDialog)?

Specifically, I want to add some bitmap buttons (CBitmapButton) to my dialog, so I followed the first part of this article:
http://www.functionx.com/visualc/controls/bmpbtn.htm

Everything worked fine, but then later on it says to use the resource ID of your bitmap button. How would I go about creating a resource ID and adding it to the resource script?

I added some regular buttons to my dialog using the dialog editor, and found this in the script:
C++ Syntax (Toggle Plain Text)
  1. BEGIN
  2. PUSHBUTTON "Button1",IDC_BUTTON1,57,46,50,14
  3. PUSHBUTTON "Button2",IDC_BUTTON2,129,47,50,14
  4. PUSHBUTTON "Button3",IDC_BUTTON3,55,18,50,14
  5. PUSHBUTTON "Button4",IDC_BUTTON4,121,19,50,14
  6. END
If I wanted to access the actual object of one of those buttons and call it's functions, how would I do that? Also, is there anything instead of "PUSHBUTTON" that I can use for CBitmapButtons?

I've taken a look at all the files VS generated but can't figure out how everything works together. None of the MFC tutorials I've looked at bother explaining the relationship with the resource script either.

Any help would be appreciated. Thank you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muhandis is offline Offline
8 posts
since Jun 2009
Jul 2nd, 2009
0

Re: Need some help understanding MFC

what compiler and version are you using?

Microsoft has a Scribble Tutorial that's an introduction to MFC.
Last edited by Ancient Dragon; Jul 2nd, 2009 at 9:58 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,953 posts
since Aug 2005
Jul 2nd, 2009
0

Re: Need some help understanding MFC

I'm using Visual Studio 2008.

Thank you for the link. I actually forgot the article uses provided source code, so I can look at exactly how they did it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muhandis is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: Need some help understanding MFC

muhandis>I'm having some of trouble understanding exactly how an MFC GUI works.

You should read MFC Fundamental - MSDN online page
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 3rd, 2009
0

Re: Need some help understanding MFC

I understand a bit more after experimenting and looking at sample code. However, I'm still having a few problems and would really appreciate any help.

In this article: http://www.functionx.com/visualc/controls/bmpbtn.htm

It says to do declare the CBitmapButtons as members of the dialog in the second part, but doesn't explain how you're supposed to map the resource IDs to them. They just declare the controls and then the IDs pop out of nowhere when they have to provide them parameters.

Right now, I'm using this code (in OnInitDialog) to add a CBitmapButton to my dialog:
	CBitmapButton *btnMap = new CBitmapButton();
	btnMap->Create(NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
		CRect(0, 0, 0, 0), this, IDC_TESTBUTTON);
	btnMap->LoadBitmaps(IDB_TEST, 0, 0, 0);
	btnMap->SizeToContent();
	btnMap->SubclassDlgItem(IDC_TESTBUTTON, this);

However, I got an assertion failed error once I added that last line. I broke on the error, and got this as the cause:
BOOL CWnd::Attach(HWND hWndNew)
{
	ASSERT(m_hWnd == NULL);     // only attach once, detach on destroy
	ASSERT(FromHandlePermanent(hWndNew) == NULL);
		// must not already be in permanent map
...(Microsoft code)
}
Which is in wincore.cpp (line 329).

Also, according to the people who answered someone with a very similar problem here:
http://social.msdn.microsoft.com/For...0-0abd909d3e4e

You're supposed to just declare the buttons as members of the class (the normal way). Again, what I don't understand about that is how I am supposed to map the resource ID to the button.

Thanks
Last edited by muhandis; Jul 3rd, 2009 at 1:37 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muhandis is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: Need some help understanding MFC

Click to Expand / Collapse  Quote originally posted by muhandis ...
I'm using Visual Studio 2008.

Thank you for the link. I actually forgot the article uses provided source code, so I can look at exactly how they did it.
http://msdn.microsoft.com/en-us/library/f35t8fts.aspx
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Jul 3rd, 2009
0

Re: Need some help understanding MFC

Thank you for the reply but someone already suggested that.

Still looking for help on my last post.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muhandis is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: Need some help understanding MFC

I resolved my problems by getting rid of SubclassDlgItem and following this: http://msdn.microsoft.com/en-us/visualc/bb931337.aspx

Thank you all for your replies.
Last edited by muhandis; Jul 3rd, 2009 at 6:33 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muhandis is offline Offline
8 posts
since Jun 2009

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: How to make a non-blocking socket?
Next Thread in C++ Forum Timeline: Will this code generates a segmentation fault???





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


Follow us on Twitter


© 2011 DaniWeb® LLC