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:

BEGIN
    PUSHBUTTON      "Button1",IDC_BUTTON1,57,46,50,14
    PUSHBUTTON      "Button2",IDC_BUTTON2,129,47,50,14
    PUSHBUTTON      "Button3",IDC_BUTTON3,55,18,50,14
    PUSHBUTTON      "Button4",IDC_BUTTON4,121,19,50,14
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.

what compiler and version are you using?

Microsoft has a Scribble Tutorial that's an introduction to 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.

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)
{
	[B]ASSERT(m_hWnd == NULL);[/B]     // 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/Forums/en-US/vcgeneral/thread/6cda7ab9-790a-497d-a470-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

Thank you for the reply but someone already suggested that.

Still looking for help on my last post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.