| | |
Need some help understanding MFC
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
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:
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 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)
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
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.
Microsoft has a Scribble Tutorial that's an introduction to MFC.
Last edited by Ancient Dragon; Jul 2nd, 2009 at 9:58 pm.
muhandis>I'm having some of trouble understanding exactly how an MFC GUI works.
You should read MFC Fundamental - MSDN online page
You should read MFC Fundamental - MSDN online page
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
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:
However, I got an assertion failed error once I added that last line. I broke on the error, and got this as the cause:
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
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)
}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.
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
•
•
•
•
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.
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
Please use code tags - Please mark solved threads as solved
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
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.
Thank you all for your replies.
Last edited by muhandis; Jul 3rd, 2009 at 6:33 am.
![]() |
Similar Threads
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Quit abruptly in MFC app (C++)
- Need Help Understanding Subject in C++ (C++)
- Difficulty understanding Object Orientated File Streaming (C++)
- Using MFC in a Static Library (C++)
- MFC diagram maker type thing (C)
- Some help understanding #define with C (C)
Other Threads in the C++ Forum
- Previous Thread: How to make a non-blocking socket?
- Next Thread: Will this code generates a segmentation fault???
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






