【发布时间】:2013-11-17 11:41:29
【问题描述】:
我创建了一个 Win32 控制台应用程序来编写一个简单的 MFC 项目。
源码如下:
#include <afxwin.h>
class MyApp : public CWinApp
{
public:
BOOL InitInstance();
MyApp()
{
}
};
class MainWindow : public CFrameWnd
{
protected:
int OnCreate(LPCREATESTRUCT lpCreateStruct);
void OnClose();
LRESULT OnTimer(WPARAM wParam, LPARAM lParam);
// This line is causing the error
DECLARE_MESSAGE_MAP()
};
BOOL MyApp::InitInstance()
{
MainWindow* mainWindow = new MainWindow();
m_pMainWnd = mainWindow;
mainWindow->Create(NULL, L"Main Window");
mainWindow->ShowWindow(m_nCmdShow);
return TRUE;
}
MyApp myApp;
int MainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetTimer(1, 2000, NULL);
return 0;
}
void MainWindow::OnClose()
{
if (MessageBox(L"Close?", L"Close", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
KillTimer(1);
CFrameWnd::OnClose();
}
}
LRESULT MainWindow::OnTimer(WPARAM wParam, LPARAM lParam)
{
MessageBeep(MB_ICONQUESTION);
return 0;
}
当我尝试编译时,出现以下错误:
错误 1 错误 LNK2001:未解析的外部符号“受保护:虚拟结构 AFX_MSGMAP const * __thiscall MainWindow::GetMessageMap(void)const” (?GetMessageMap@MainWindow@@MBEPBUAFX_MSGMAP@@XZ) D:\Projects\MinimumMFC\MinimumMFC\最小MFC.obj 最小MFC
【问题讨论】:
-
在使用 MFC 创建对话框应用程序时,您是否可以选择: 1. 在共享 DLL 中使用 MFC?
-
这看起来不像一个 Win32 控制台 应用程序。考虑编辑您的问题以匹配您的问题。
标签: c++ visual-studio mfc visual-studio-2013