Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Where this MFC Wizard generated code reads the ESC key?

Status
Not open for further replies.

C++

Junior Member level 3
Junior Member level 3
Joined
Oct 12, 2004
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
243
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

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
 

MFC Problem

hi,
when u enter ESC, there is a default handler for this type of keys,similarly for enter key,
so the code for this is embedded deep in the base classes, in your case in CDialog class, so here is what u need to do to handle these keys,
override the OnCancel() method in your CWin32TestAppDlg dlg class, and in this function do not call the base member.
 

    C++

    Points: 2
    Helpful Answer Positive Rating
MFC Problem

also, to futher explain to you how the message gets to the base class(CDialog), see this line of code
BEGIN_MESSAGE_MAP(CWin32TestAppDlg, CDialog), what this says is handle all the messages in CWin32TestAppDlg for which handlers have been defined, if a handler has not been found then search for handlers in the CDialog class, and CDialog class has a default implementation to handle this type of message and the handler exits the dialog.
you can find more info on this topic, by reading
MFC Internals: Inside the Microsoft(c) Foundation Class Architecture
by George Shepherd, Scot Wingo
 

    C++

    Points: 2
    Helpful Answer Positive Rating
Re: MFC Problem

okies, I figured it out, it won't exit with the Esc button anymore, thanks...

now I have another question....

does MFC have some kinda message loop like the WinAPI? somewhere where I can keep on updataing some text on the screen according to the time :-/
 

MFC Problem

hi,
Yes, MFC internally has a message loop running, i will tell u how to accompolish what u want to do.

if i understand correctly u want to update some text on the screen based on some time.

solution:
In Your window, start a window timer by calling SetTimer(), this takes an ID parameter some number for identification and the time in milisec's and the function parameter to be called, set this to null,
now using class wizard map WM_TIMER message in your window class and this function will have a ID parameter and this function will get called at every milisecs elapses that u specified in your SetTimer() function.
now when u r finished call KillTimer() with the ID.

enjoy.
 

    C++

    Points: 2
    Helpful Answer Positive Rating
Re: MFC Problem

i think that'd solve my problem, but here's the description of what i'm trying to do

we're making "automated game tables", where the costumer walks in, pays some money, there's a light on top of the tables, and the computer's supposed to turn the light on for the amount of time the csutomer paid for through the USB port with some circuits we made . . .

now there's 2 different approaches, have the circuits keep track of time, or the pc...

i think what u said up there might be the solution, but i'm gonna have to work on it, and see what happens
 

Re: MFC Problem

well, couldn't figure it out, can u give an example code plz?
 

Re: MFC Problem

hi,
i have attached a sample program using the timer, which will count till a certain number and then stop the timer, hope this helps you.
 

    C++

    Points: 2
    Helpful Answer Positive Rating
Re: MFC Problem

thanks, but mine's still not working :( what am i doing wrong?
 

Re: MFC Problem

C++ said:
thanks, but mine's still not working :( what am i doing wrong?

BEGIN_MESSAGE_MAP(COnTimerTestDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

add ON_WM_TIMER() between BEGIN_MESSAGE_MAP(COnTimerTestDlg, CDialog) , END_MESSAGE_MAP()
your version is lack of ON_WM_TIMER() map
 

    C++

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top