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.

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?

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

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.