C++
Junior Member level 3
MFC Problem
I'm trying to learn mfc on my own through trial and error . . . So far I've figured out lots of the stuff, but there's still 1 thing I don't get. . .
I used the MFC Application wizard (VC++ .NET) to start a dialog based project, it generates code for an OK, and Cancel button which both exit the program...
The program also exits when the Esc key is pressed, I figured out how it exists by pressing those two buttons, but I can't find the code for where it exits when the Esc key is pressed
That's all the MFC Wizard generated code, I'd appreciate it if someone could tell me where it reads the Esc key
I'm trying to learn mfc on my own through trial and error . . . So far I've figured out lots of the stuff, but there's still 1 thing I don't get. . .
I used the MFC Application wizard (VC++ .NET) to start a dialog based project, it generates code for an OK, and Cancel button which both exit the program...
The program also exits when the Esc key is pressed, I figured out how it exists by pressing those two buttons, but I can't find the code for where it exits when the Esc key is pressed
Code:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
// Win32TestAppDlg.h : header file
//
#pragma once
// CWin32TestAppDlg dialog
class CWin32TestAppDlg : public CDialog
{
// Construction
public:
CWin32TestAppDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_WIN32TESTAPP_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
// Win32TestApp.h : main header file for the PROJECT_NAME application
//
#pragma once
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
// CWin32TestApp:
// See Win32TestApp.cpp for the implementation of this class
//
class CWin32TestApp : public CWinApp
{
public:
CWin32TestApp();
// Overrides
public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
extern CWin32TestApp theApp;
// stdafx.cpp : source file that includes just the standard includes
// Win32TestApp.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// Win32TestAppDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Win32TestApp.h"
#include "Win32TestAppDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CWin32TestAppDlg dialog
CWin32TestAppDlg::CWin32TestAppDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWin32TestAppDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWin32TestAppDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CWin32TestAppDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CWin32TestAppDlg message handlers
BOOL CWin32TestAppDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWin32TestAppDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWin32TestAppDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// Win32TestApp.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Win32TestApp.h"
#include "Win32TestAppDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CWin32TestApp
BEGIN_MESSAGE_MAP(CWin32TestApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CWin32TestApp construction
CWin32TestApp::CWin32TestApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CWin32TestApp object
CWin32TestApp theApp;
// CWin32TestApp initialization
BOOL CWin32TestApp::InitInstance()
{
CWinApp::InitInstance();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CWin32TestAppDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
That's all the MFC Wizard generated code, I'd appreciate it if someone could tell me where it reads the Esc key