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);

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


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.

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?

Edited 5 Years Ago by thines01: clarity

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

This article has been dead for over six months. Start a new discussion instead.