954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MFC Question

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.

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);
	addEmailButton->SetFocus();


The problem is, when the GetDlgItem() is called, the first line in the function is:

ASSERT(::IsWindow(m_hWnd))


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.

PreyaticIntent
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

First problem first.
When you exit from a previous window, type in a text box and press enter, your app exits?

Can you trap any exceptions (is an exception actually thrown)?
What is the data type bound to your textbox?

Are you trapping keypresses?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

That has been a common problem for many years with MFC. The way to solve it is to hook the keyboard event and ignore the Enter key.

Here are a few more suggestions

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: