Advertisement Jump to content
Sign in to follow this  

MFC Question

This topic is 2589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#434343"][font="helvetica, arial, verdana,"]Okay, I'm still a fresh out of college programmer (only been doing it for 4 years), so I will try to be as descriptive as possible. I apologize now for anything that doesn't make sense, or if I'm even in the wrong place.

I've got a C++ project that using MFC to create forms. I have my main window, and inside it I have 7 tabs, one of them called "Send". On this tab I have several buttons and other controls. One button, the "Add" button, in it's properties, I have set to be the default button (the button I assume fires off when you press Enter). Now, when the form and tab is loaded, one button (the "Find File" button) has focus. Now, if I type in my textbox, and press Enter, my program shuts down (obviously not the effect I was going for). On top of that, I can't seem to find a way to make the "Add" button have focus upon starting the program. In the Send tab's constructor, I added:

CWnd* addEmailButton = GetDlgItem(IDC_ADD_EMAIL_TO_LIST);
[font="helvetica, arial, verdana,"]The problem is, when the GetDlgItem() is called, the first line in the function is:[/font]

[font="helvetica, arial, verdana,"]
[font="helvetica, arial, verdana,"] [/font]
[font="helvetica, arial, verdana,"][color="#434343"]Using Visual Studio, and mousing over m_hWnd, IntelliSense reports that it's unused. This, obviously, is causing the ASSERT to fail, and thus my program to crash. I would appreciate any and all help given to understand why exactly this is. Thank you.[/font]

Share this post

Link to post
Share on other sites
MFC is wrapping Win32 beneath. The usual flow of wrapper classes is thus:

Constructor, no valid HWND yet
Creating HWNDs
Running through a mapper function which actually assigns the HWND values to its members

In your OnInitDialog method the return value determines if you set the focus to a different control than the default one.

a) Add the SetFocus call to OnInitDialog
b) return FALSE to indicate that you set focus to a control

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!