Need some help understanding MFC

Thread Solved
Reply

Join Date: Jun 2009
Posts: 8
Reputation: muhandis is an unknown quantity at this point 
Solved Threads: 0
muhandis muhandis is offline Offline
Newbie Poster

Need some help understanding MFC

 
0
  #1
Jul 2nd, 2009
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,172
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: 1439
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: Need some help understanding MFC

 
0
  #2
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: muhandis is an unknown quantity at this point 
Solved Threads: 0
muhandis muhandis is offline Offline
Newbie Poster

Re: Need some help understanding MFC

 
0
  #3
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,434
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 439
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: Need some help understanding MFC

 
0
  #4
Jul 3rd, 2009
muhandis>I'm having some of trouble understanding exactly how an MFC GUI works.

You should read MFC Fundamental - MSDN online page
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: muhandis is an unknown quantity at this point 
Solved Threads: 0
muhandis muhandis is offline Offline
Newbie Poster

Re: Need some help understanding MFC

 
0
  #5
Jul 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 359
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: Need some help understanding MFC

 
0
  #6
Jul 3rd, 2009
Originally Posted by muhandis View Post
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
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: Jun 2009
Posts: 8
Reputation: muhandis is an unknown quantity at this point 
Solved Threads: 0
muhandis muhandis is offline Offline
Newbie Poster

Re: Need some help understanding MFC

 
0
  #7
Jul 3rd, 2009
Thank you for the reply but someone already suggested that.

Still looking for help on my last post.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: muhandis is an unknown quantity at this point 
Solved Threads: 0
muhandis muhandis is offline Offline
Newbie Poster

Re: Need some help understanding MFC

 
0
  #8
Jul 3rd, 2009
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.
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