我用VS2012,運行MFC Windows程式設計的例子,代碼與書本一樣,代碼如下:
hello.H檔案:
class CMyApp : public CWinApp //定義一個應用程式類
{
public :
virtual bool InitInstance();
};
class CMainWindow:public CFrameWnd //定義個應用程式視窗類
{
public :
CMainWindow ();
protected :
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
Hello.cpp檔案:
#include <afxwin.h>
#include "Hello.h"
CMyApp myApp; //實體化一個應用程式物件
BOOL CMyApp ::InitInstance()
{
m_pMainWnd=new CMainWindow ;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE ;
}
BEGIN_MESSAGE_MAP(CMainWindow ,CFrameWnd )
ON_WM_PAINT()
END_MESSAGE_MAP()
CMainWindow::CMainWindow ()
{
Create(NULL ,_T("The Hello App!"));
}
void CMainWindow ::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("Hello,MFC"),-1,&rect,
DT_SINGLELINE|DT_CENTER |DT_VCENTER );
}
下面是報錯資訊:
錯誤 1 error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afx.h 24
2 IntelliSense: #error 指令: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afx.h 24
3 IntelliSense: 宣告與 "bool CMyApp::InitInstance()" (已宣告 所在行數: 4,所屬檔案: "c:\users\hsjiang\documents\visual studio 2012\projects\project1\project1\Hello.h") 不兼容 c:\Users\hsjiang\Documents\Visual Studio 2012\Projects\Project1\Project1\Hello.cpp 4
4 IntelliSense: 回傳型別與重寫虛擬函式 "CWinThread::InitInstance" 的回傳型別 "BOOL" 既不相同,也不協變 c:\Users\hsjiang\Documents\Visual Studio 2012\Projects\Project1\Project1\Hello.h 4
這些錯誤該如何解決,在線等!謝謝各位朋友!
uj5u.com熱心網友回復:
bool 和 BOOL 是不一樣的, 要區分大小寫uj5u.com熱心網友回復:
BOOL CMyApp ::InitInstance()virtual bool InitInstance();
BOOL 與 bool 不是一個型別·
uj5u.com熱心網友回復:
為什么手動輸入例子代碼后,要設定使用靜態或者動態庫,不能使用Windows標準庫,也要選擇多位元組字符集,為什么還要指定入口點,而自帶的例子卻不要,這樣的設定,能否使用在實際的專案中?uj5u.com熱心網友回復:
我這個例子運行起來了,我想問,CWinApp與CWinAppEx的使用有什么不同,為什么我把CWinApp改成CWinAppEx就不能用了,謝謝!uj5u.com熱心網友回復:
你全部都改掉了嗎?這個工程搜索CWinApp修改成CWinAppEx試試~
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/134117.html
標籤:基礎類
上一篇:我是剛學的菜鳥,程式運行出現引發了例外: 讀取訪問權限沖突。 this 是 0xFFFFFFF0。 請幫忙解決!萬分感激!
