候捷都没办法,你说咋办啊?~

neight 2004-02-03 12:31:07
首先,先向各位道歉,小的不才,不是候老师没办法。近日看了候老师的《深入浅出MFC》
在消息传递那章卡住了,百思不得其解,忘有能者相助。自当重谢。
问题是,为什么这些代码编译不过?
//mfc.cpp ************************************************************
#include "my.h" // ­ì¸Ó§t¤J mfc.h ´N¦n¡A¦ý¬°¤F extern CMyWinApp ©Ò¥H...

extern CMyWinApp theApp;
extern void printlpEntries(AFX_MSGMAP_ENTRY* lpEntry);

BOOL CCmdTarget::OnCmdMsg(UINT nID, int nCode)
{
cout << "CCmdTarget::OnCmdMsg()" << endl;
// Now look through message map to see if it applies to us
AFX_MSGMAP* pMessageMap;
AFX_MSGMAP_ENTRY* lpEntry;
for (pMessageMap = GetMessageMap(); pMessageMap != NULL;
pMessageMap = pMessageMap->pBaseMessageMap)
{
lpEntry = pMessageMap->lpEntries;
printlpEntries(lpEntry);
}

return FALSE; // not handled
}

BOOL CWnd::Create()
{
cout << "CWnd::Create \n";
return TRUE;
}

BOOL CWnd::CreateEx()
{
cout << "CWnd::CreateEx \n";
PreCreateWindow();
return TRUE;
}

BOOL CWnd::PreCreateWindow()
{
cout << "CWnd::PreCreateWindow \n";
return TRUE;
}

LRESULT CWnd::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
AFX_MSGMAP* pMessageMap;
AFX_MSGMAP_ENTRY* lpEntry;

cout << "CWnd::WindowProc()" << endl;
if (nMsg == WM_COMMAND) // special case for commands
{
if (OnCommand(wParam, lParam))
return 1L; // command handled
else
return (LRESULT)DefWindowProc(nMsg, wParam, lParam);
}

pMessageMap = GetMessageMap();

for (; pMessageMap != NULL;
pMessageMap = pMessageMap->pBaseMessageMap)
{
lpEntry = pMessageMap->lpEntries;
printlpEntries(lpEntry);
}
return 0; // J.J.Hou: if find, should call lpEntry->pfn,
// otherwise should call DefWindowProc.
// for simplization¡A we just return 0.
}

LRESULT CWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
cout << "CWnd::DefWindowProc()" << endl;
return TRUE;
}

BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)
{
cout << "CWnd::OnCommand()" << endl;
// ...
return OnCmdMsg(0, 0);
}

BOOL CFrameWnd::OnCommand(WPARAM wParam, LPARAM lParam)
{
cout << "CFrameWnd::OnCommand()" << endl;
// ...
// route as normal command
return CWnd::OnCommand(wParam, lParam);
}

BOOL CFrameWnd::Create()
{
cout << "CFrameWnd::Create \n";
CreateEx();
return TRUE;
}

BOOL CFrameWnd::PreCreateWindow()
{
cout << "CFrameWnd::PreCreateWindow \n";
return TRUE;
}

CView* CFrameWnd::GetActiveView() const
{
cout << "CFrameWnd::GetActiveView()" << endl;
return m_pViewActive;
}

BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode)
{
cout << "CFrameWnd::OnCmdMsg()" << endl;
// pump through current view FIRST
CView* pView = GetActiveView();
if (pView->OnCmdMsg(nID, nCode))
return TRUE;

// then pump through frame
if (CWnd::OnCmdMsg(nID, nCode))
return TRUE;

// last but not least, pump through app
CWinApp* pApp = AfxGetApp();
if (pApp->OnCmdMsg(nID, nCode))
return TRUE;

return FALSE;
}

BOOL CDocument::OnCmdMsg(UINT nID, int nCode)
{
cout << "CDocument::OnCmdMsg()" << endl;
if (CCmdTarget::OnCmdMsg(nID, nCode))
return TRUE;

return FALSE;
}

BOOL CView::OnCmdMsg(UINT nID, int nCode)
{
cout << "CView::OnCmdMsg()" << endl;
if (CWnd::OnCmdMsg(nID, nCode))
return TRUE;

BOOL bHandled = FALSE;
bHandled = m_pDocument->OnCmdMsg(nID, nCode);
return bHandled;
}

AFX_MSGMAP* CCmdTarget::GetMessageMap() const // JJHou: in MFC 40 cmdtarg.cpp
{
return &CCmdTarget::messageMap;
}

AFX_MSGMAP CCmdTarget::messageMap = // JJHou: in in MFC 40 cmdtarg.cpp
{
NULL,
&CCmdTarget::_messageEntries[0]
};

AFX_MSGMAP_ENTRY CCmdTarget::_messageEntries[] = // JJHou: in in MFC 40 cmdtarg.cpp
{
{ 0, 0, CCmdTargetid, 0, AfxSig_end, 0 } // nothing here
};

BEGIN_MESSAGE_MAP(CWnd, CCmdTarget)
ON_COMMAND(CWndid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CFrameWnd, CWnd)
ON_COMMAND(CFrameWndid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CDocument, CCmdTarget)
ON_COMMAND(CDocumentid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CView, CWnd)
ON_COMMAND(CViewid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
ON_COMMAND(CWinAppid, 0)
END_MESSAGE_MAP()

CWinApp* AfxGetApp()
{
return theApp.m_pCurrentWinApp;
}

LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
CWnd *pWnd) // last param. pWnd is added by JJHou.
{
cout << "AfxWndProc()" << endl;
return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
}

LRESULT AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg,
WPARAM wParam, LPARAM lParam)
{
cout << "AfxCallWndProc()" << endl;
LRESULT lResult = pWnd->WindowProc(nMsg, wParam, lParam);
return lResult;
}


...全文
39 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
无我无人 2004-02-03
  • 打赏
  • 举报
回复
拒绝回答骗眼球者。
neight 2004-02-03
  • 打赏
  • 举报
回复


//AFXMSG.h*****************************************
enum AfxSig
{
AfxSig_end = 0, // [marks end of message map]
AfxSig_vv,
};

#define ON_COMMAND(id, memberFxn) { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)memberFxn },


//my.cpp***************************************************
#include "my.h"

CMyWinApp theApp; // global object

BOOL CMyWinApp::InitInstance()
{
cout << "CMyWinApp::InitInstance \n";
m_pMainWnd = new CMyFrameWnd;
return TRUE;
}

CMyFrameWnd::CMyFrameWnd()
{
Create();
}

BEGIN_MESSAGE_MAP(CMyWinApp, CWinApp)
ON_COMMAND(CMyWinAppid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
ON_COMMAND(CMyFrameWndid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
ON_COMMAND(CMyDocid, 0)
END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP(CMyView, CView)
ON_COMMAND(CMyViewid, 0)
END_MESSAGE_MAP()

void printlpEntries(AFX_MSGMAP_ENTRY* lpEntry)
{
struct {
int classid;
char* classname;
} classinfo[] = {
CCmdTargetid , "CCmdTarget ",
CWinThreadid , "CWinThread ",
CWinAppid , "CWinApp ",
CMyWinAppid , "CMyWinApp ",
CWndid , "CWnd ",
CFrameWndid , "CFrameWnd ",
CMyFrameWndid, "CMyFrameWnd ",
CViewid , "CView ",
CMyViewid , "CMyView ",
CDocumentid , "CDocument ",
CMyDocid , "CMyDoc ",
0 , " "
};

for (int i=0; classinfo[i].classid != 0; i++)
{
if (classinfo[i].classid == lpEntry->nID)
{
cout << lpEntry->nID << " ";
cout << classinfo[i].classname << endl;
break;
}
}
}
//------------------------------------------------------------------
// main
//------------------------------------------------------------------
void main()
{
CWinApp* pApp = AfxGetApp();

pApp->InitApplication();
pApp->InitInstance();
pApp->Run();

CMyDoc* pMyDoc = new CMyDoc;
CMyView* pMyView = new CMyView;
CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd;
pMyFrame->m_pViewActive = pMyView;
pMyView->m_pDocument = pMyDoc;

// test Message Routing
cout << endl << "pMyFrame receive WM_CREATE, ";
cout << "routing path and call stack:" << endl;
AfxWndProc(0, WM_CREATE, 0, 0, pMyFrame);

cout << endl << "pMyView receive WM_PAINT, ";
cout << "routing path and call stack:" << endl;
AfxWndProc(0, WM_PAINT, 0, 0, pMyView);

cout << endl << "pMyView receive WM_COMMAND, ";
cout << "routing path and call stack:" << endl;
AfxWndProc(0, WM_COMMAND, 0, 0, pMyView);

cout << endl << "pMyFrame receive WM_COMMAND, ";
cout << "routing path and call stack:" << endl;
AfxWndProc(0, WM_COMMAND, 0, 0, pMyFrame);
}

//my.h*****************************************************
#include <iostream.h>
#include "mfc.h"

class CMyWinApp : public CWinApp
{
public:
CMyWinApp::CMyWinApp() {
}
CMyWinApp::~CMyWinApp() {
}
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};

class CMyFrameWnd : public CFrameWnd
{
public:
CMyFrameWnd();
~CMyFrameWnd() {
}
DECLARE_MESSAGE_MAP()
};

class CMyDoc : public CDocument
{
public:
CMyDoc::CMyDoc() {
}
CMyDoc::~CMyDoc() {
}
DECLARE_MESSAGE_MAP()
};

class CMyView : public CView
{
public:
CMyView::CMyView() {
}
CMyView::~CMyView() {
}
DECLARE_MESSAGE_MAP()
};

neight 2004-02-03
  • 打赏
  • 举报
回复
//mfc.h**************************************************
#define TRUE 1
#define FALSE 0

typedef char* LPSTR;
typedef const char* LPCSTR;

typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef int INT;
typedef unsigned int UINT;
typedef long LONG;

typedef UINT WPARAM;
typedef LONG LPARAM;
typedef LONG LRESULT;
typedef int HWND;

#define WM_COMMAND 0x0111 // following windows.h
#define WM_CREATE 0x0001
#define WM_PAINT 0x000F
#define WM_NOTIFY 0x004E

#define CObjectid 0xffff
#define CCmdTargetid 1
#define CWinThreadid 11
#define CWinAppid 111
#define CMyWinAppid 1111
#define CWndid 12
#define CFrameWndid 121
#define CMyFrameWndid 1211
#define CViewid 122
#define CMyViewid 1221
#define CDocumentid 13
#define CMyDocid 131

#include <iostream.h>

////////////////////////////////////////////////////////////////////
// Window message map handling

struct AFX_MSGMAP_ENTRY;

struct AFX_MSGMAP
{
AFX_MSGMAP* pBaseMessageMap;
AFX_MSGMAP_ENTRY* lpEntries;
};

#define DECLARE_MESSAGE_MAP() static AFX_MSGMAP_ENTRY _messageEntries[]; static AFX_MSGMAP messageMap; virtual AFX_MSGMAP* GetMessageMap() const;

#define BEGIN_MESSAGE_MAP(theClass, baseClass) AFX_MSGMAP* theClass::GetMessageMap() const { return &(theClass::messageMap); } AFX_MSGMAP theClass::messageMap = { &(baseClass::messageMap), (AFX_MSGMAP_ENTRY*) (theClass::_messageEntries) }; AFX_MSGMAP_ENTRY theClass::_messageEntries[] = {

#define END_MESSAGE_MAP() { 0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } };

// Message map signature values and macros in separate header
#include <afxmsg_.h>

class CObject
{
public:
CObject::CObject() {
}
CObject::~CObject() {
}
};

class CCmdTarget : public CObject
{
public:
CCmdTarget::CCmdTarget() {
}
CCmdTarget::~CCmdTarget() {
}

virtual BOOL OnCmdMsg(UINT nID, int nCode);

DECLARE_MESSAGE_MAP() // base class - no {{ }} macros
};

typedef void (CCmdTarget::*AFX_PMSG)(void);

struct AFX_MSGMAP_ENTRY // MFC 4.0 format
{
UINT nMessage; // windows message
UINT nCode; // control code or WM_NOTIFY code
UINT nID; // control ID (or 0 for windows messages)
UINT nLastID; // used for entries specifying a range of control id's
UINT nSig; // signature type (action) or pointer to message #
AFX_PMSG pfn; // routine to call (or special value)
};

class CWinThread : public CCmdTarget
{
public:
CWinThread::CWinThread() {
}
CWinThread::~CWinThread() {
}

virtual BOOL InitInstance() {
cout << "CWinThread::InitInstance \n";
return TRUE;
}
virtual int Run() {
cout << "CWinThread::Run \n";
// AfxWndProc(...);
return 1;
}
};

class CWnd;

class CWinApp : public CWinThread
{
public:
CWinApp* m_pCurrentWinApp;
CWnd* m_pMainWnd;

public:
CWinApp::CWinApp() {
m_pCurrentWinApp = this;
}
CWinApp::~CWinApp() {
}

virtual BOOL InitApplication() {
cout << "CWinApp::InitApplication \n";
return TRUE;
}
virtual BOOL InitInstance() {
cout << "CWinApp::InitInstance \n";
return TRUE;
}
virtual int Run() {
cout << "CWinApp::Run \n";
return CWinThread::Run();
}

DECLARE_MESSAGE_MAP()
};

typedef void (CWnd::*AFX_PMSGW)(void);
// like 'AFX_PMSG' but for CWnd derived classes only

class CDocument : public CCmdTarget
{
public:
CDocument::CDocument() {
}
CDocument::~CDocument() {
}

virtual BOOL OnCmdMsg(UINT nID, int nCode);

DECLARE_MESSAGE_MAP()
};

class CWnd : public CCmdTarget
{
public:
CWnd::CWnd() {
}
CWnd::~CWnd() {
}

virtual BOOL Create();
BOOL CreateEx();
virtual BOOL PreCreateWindow();
virtual LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);

DECLARE_MESSAGE_MAP()
};

class CView;

class CFrameWnd : public CWnd
{
public:
CView* m_pViewActive; // current active view

public:
CFrameWnd::CFrameWnd() {
}
CFrameWnd::~CFrameWnd() {
}
BOOL Create();
virtual BOOL PreCreateWindow();
CView* GetActiveView() const;
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
virtual BOOL OnCmdMsg(UINT nID, int nCode);

DECLARE_MESSAGE_MAP()

friend CView;
};

class CView : public CWnd
{
public:
CDocument* m_pDocument;

public:
CView::CView() {
}
CView::~CView() {
}

virtual BOOL OnCmdMsg(UINT nID, int nCode);

DECLARE_MESSAGE_MAP()

friend CFrameWnd;
};

// global function
CWinApp* AfxGetApp();
LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
CWnd* pWnd); // last param. pWnd is added by JJHOU.
LRESULT AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg, WPARAM wParam,
LPARAM lParam);


lovenoend 2004-02-03
  • 打赏
  • 举报
回复
就当没看见……
:)
flyelf 2004-02-03
  • 打赏
  • 举报
回复
晕倒一片
abc_xyz 2004-02-03
  • 打赏
  • 举报
回复
beyondtkl 2004-02-03
  • 打赏
  • 举报
回复
hehe.
gz.
樓主 提問也是有學問的.要多養成好習慣.
比如說你的錯誤:
既然是編譯錯誤,那就把錯誤鐵出來,而且響應的代碼也鐵出來,大家再給你想法子.....
tanyaliji 2004-02-03
  • 打赏
  • 举报
回复
晕!
pcgenius 2004-02-03
  • 打赏
  • 举报
回复
晕。把编译时出现什么错误打出来先。
yintongshun 2004-02-03
  • 打赏
  • 举报
回复
先看错误,再看代码,在什么方式下编译的?Console?
zhangcrony 2004-02-03
  • 打赏
  • 举报
回复
我眼睛也受不了﹗
把報的錯貼出來就OK了.
fzd999 2004-02-03
  • 打赏
  • 举报
回复
我的ggjjmmdd啊,你把编译报的错贴出来就可以了,这么多代码你要人命啊
carbon107 2004-02-03
  • 打赏
  • 举报
回复
一看直恍眼睛

唉,你编译时出再什么错误啊!!

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧