1 回答

TA貢獻1785條經驗 獲得超8個贊
有時候在給程序的類添加消息響應或者虛函數的時候,會彈出“Parsing error:Expected "afx_msg",input line.......”
//{{AFX_MSG(CMyimageDoc)
public:
afx_msg void OnStart();
afx_msg void Onsavefile();
afx_msg void OnStop();
protected:
afx_msg void OnFileSaveAs();
afx_msg void OnFileSave();
afx_msg void OnOriginalimage();
afx_msg void Onopenfile();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
如果你想給CMyimageDoc類添加虛函數或者消息響應的話就會彈出"Parsing error:......",你打開ClassWizard也會彈出這種錯誤。如果你在View類里打開的ClassWizard彈出這種錯誤的話,需要查找到底是哪個類中出現了問題,只需要再沒個類中點右鍵添加虛函數(或者消息響應)就能查找出來大地哪兒出現了問題。本例然后再需要改成
public:
//{{AFX_MSG(CLock_imageDoc)
afx_msg void OnStart();
afx_msg void Onsavefile();
afx_msg void OnStop();
afx_msg void OnFileSaveAs();
afx_msg void OnFileSave();
afx_msg void OnOriginalimage();
afx_msg void Onopenfile();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
再添加的話就會沒問題了。ClassWizard也能順利打開了。
還有一種是自己添加的消息,如
public:
//{{AFX_MSG(CLock_imageDoc)
afx_msg void OnStart();
afx_msg void Onsavefile();
afx_msg void OnStop();
afx_msg void OnFileSaveAs();
afx_msg void OnFileSave();
afx_msg void OnOriginalimage();
afx_msg void Onopenfile();
afx_msg void OnmyMessage(); ///////////自己添加的消息對應的消息響應
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
此時的ClassWizard也會彈出"Parsing error:......",此時值需要改成
public:
//{{AFX_MSG(CLock_imageDoc)
afx_msg void OnStart();
afx_msg void Onsavefile();
afx_msg void OnStop();
afx_msg void OnFileSaveAs();
afx_msg void OnFileSave();
afx_msg void OnOriginalimage();
afx_msg void Onopenfile();
//}}AFX_MSG
afx_msg void OnmyMessage(); ///////////自己添加的消息對應的消息響應(放在//}}AFX_MSG的外面才行)
DECLARE_MESSAGE_MAP()
這樣就不會出問題了。
MFC中有一種特殊的注釋,叫注釋宏。注釋宏一般由VC自動加入到你的代碼中。它是為class wizard服務的,class wizard通過它來定位各種系統自動添加代碼的添加位置。若要使用類向導添加成員變量和成員函數,則要保留注釋宏;否則,必須手動添加。如果你把它刪了,classwizad就不能自動生成代碼了 。 你添加消息響應的時候是不是發現源代碼里多了些代碼??那些代碼為什么會在那里出現?為什么不在別的文件里出現?就是因為那里有注釋宏它要將代碼生成在相應注釋宏之間 。 (這個注釋是讓ClassWizard能夠分辨出哪些代碼是它生成的,哪些是你自己寫的。你自己寫的代碼要在這個注釋之外,這樣ClassWizard再修改消息映射的時候就不會管你的代碼了。新版本vc(vs)已經沒有注釋宏了。)
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報