PDA

View Full Version : mfc close message



mesman00
July 9th, 2004, 16:52
i'm using mfc. what is the message sent by the window when the close button in clicked. in the regular win api it's WM_CLOSE, but it's apparently differently in mfc. i tried including


ON_COMMAND(WM_CLOSE, OnClose)

in my message map, but to no avail. thanks.

zenogais
July 9th, 2004, 19:36
You always have the ability to override this method, but to that you need to override it in the class definition. Here's an example from my emulator:

NeoMain.h:



class NeoMain : public CFrameWnd
{
public:
NeoMain();
protected:
int OnCreate(LPCREATESTRUCT lpCreateStruct);
void OnClose();

std::string m_strVersion; ///< String dictating the current NeoPSX verison.

DECLARE_MESSAGE_MAP();
};


NeoMain.cpp:



....................
void NeoMain::OnClose()
{
//======================================== ===========
// Handling Resource Destruction And Destroy Window
//======================================== ===========
DestroyWindow();
}
.......................


Hope this will help you.

mesman00
July 9th, 2004, 20:26
yah i tried to overload the method, didn't work. this is my code:

CMainWin.h


#include <afxwin.h> //main mfc lib
#include <afxdlgs.h> //for file dialogs
#include <CString>
#include <string>
#include "DCMconvert.h"
#include "mainMenu.h"
#include "CWebView.h"

using namespace std;

#define IDF_OpenDialog 301
#define IDS_Label 401

// Declare the main window class
class CMainWin : public CFrameWnd
{
private:

CWebView *webView;
CStatic *label;
CFileDialog *openDialog;
CFileDialog *saveDialog;
DCMconvert convert;
CString fileExt;
CString fileName;
CString filePath;
CString savePath;
string htmlFilePath;
string xmlFilePath;
string txtFilePath;
string currentView;
bool fileLoaded;

public:

CMainWin();
//~CMainWin();

afx_msg void OnItemFileLoad();
afx_msg void OnItemFileSaveAs();
afx_msg void OnItemFilePrint();
afx_msg void OnItemFileExit();
afx_msg void OnItemViewHTML();
afx_msg void OnItemViewXML();
afx_msg void OnItemViewTXT();
afx_msg void OnItemHelpAbout();
void OnClose();

DECLARE_MESSAGE_MAP()
};


and here is the implementation in CMainWin.cpp

void CMainWin::OnClose()
{
MessageBox("test", "", MB_OK);
}

when i hit the x button the message box never comes up. do i need to add something tot he message map as well? thanks.

Doomulation
July 9th, 2004, 20:49
You're doing it wrong afaik ;)
ON_WM_CLOSE() is the one you're looking for. MFC simply wraps windows API, it doesn't change it. WM_CLOSE is sent to your window, it is.

You can also use spy++ to monitor sent messages to your windows.

mesman00
July 9th, 2004, 21:19
You're doing it wrong afaik ;)
ON_WM_CLOSE() is the one you're looking for. MFC simply wraps windows API, it doesn't change it. WM_CLOSE is sent to your window, it is.

You can also use spy++ to monitor sent messages to your windows.

ON_WM_CLOSE is not a method, unless its in another library other than CFrameWnd.

zenogais
July 9th, 2004, 21:21
ON_WM_CLOSE is not a method, unless its in another library other than CFrameWnd.

Its a macro, you add it in between your BEGIN_MESSAGE_MAP() END_MESSAGE_MAP() sequence.

Doomulation
July 9th, 2004, 23:33
Its a macro, you add it in between your BEGIN_MESSAGE_MAP() END_MESSAGE_MAP() sequence.
zenogais is correct ;)
Shame on you for not understanding that :evil:

Now have phun programming =)

mesman00
July 12th, 2004, 14:47
zenogais is correct ;)
Shame on you for not understanding that :evil:

Now have phun programming =)

doh!