MFC中小笔记(四)
12、編譯透明化界面是出現 ?WS_EX_LAYERED ?AC_SRC_ALPHA ULW_ALPHA ULW_OPAQUE ?undeclared identifier ,搜索發現SDK版本過低。
方法1:搜索SDK,下載合適的SDK(sdk地址)。但是高版本的SDK開發的程序,在低版本上運行時就得需要相當版本的運行庫(如果在VS2008上開發的程序,調用了只有.net 3.5之后才有的函數庫或者引用頭文件,在XP沒有裝.net 3.5的系統上,是無法正常打開的)。
?
方法2:自己定義其中的宏,在開發過程中是沒關系的。
/*定義高版本的SDK中的宏*/#define WS_EX_LAYERED 0x00080000 #define AC_SRC_ALPHA 0x01 #define ULW_ALPHA 0x00000002 #define ULW_COLORKEY 0x0000000113、UpdateLayeredWindow? : undeclared identifier?
原因:SDK版本過低。如果在低版本中調用API的UpdateLayeredWindow? ,通過調用動態鏈接庫。 官方解釋 連接
/* 通過動態鏈接庫調用 UpdateLayerWindow */HINSTANCE hInst = LoadLibrary("User32.DLL"); if(hInst) { typedef BOOL(WINAPI *UpdateLayeredWindow)(HWND,HDC,POINT *,SIZE *,HDC,POINT *,COLORREF,BLENDFUNCTION *,DWORD);UpdateLayeredWindow myfunc= NULL; //取得UpdateLayeredWindow函數指針 myfunc=(UpdateLayeredWindow)GetProcAddress(hInst, "UpdateLayeredWindow");if(myfunc)myfunc(m_hWnd, pDC->m_hDC, &point, &size, MemDC, &pointSrc, 0, &blend, ULW_ALPHA : ULW_COLORKEY);FreeLibrary(hInst); }關于最后一個參數的解釋說明:
/* dwFlags 的解釋說明 */ dwFlags [in]Type: DWORDThis parameter can be one of the following values.Value Meaning //----------------------------------------------------------------ULW_ALPHA Use pblend as the blend function. If the display mode is 256 0x00000002 colors or less, the effect of this value is the same as the effect of ULW_OPAQUE. //----------------------------------------------------------------ULW_COLORKEY Use crKey as the transparency color.0x00000001 //---------------------------------------------------------------- ULW_OPAQUE Draw an opaque layered window.0x0000000 If hdcSrc is NULL, dwFlags should be zero. View Code?
14、在編寫含有皮膚、圖片的程序,盡量減少將資源導入到 Resource.h 中,那樣會增大程序的體積。最好的方式是采用 動態加載的方式。
?
15、AlphaBlend? is not a member of CDC? 采用系統的API 進行替換。
16、ON_WM_NCHITTEST ?? 消息的返回值,在不同的SDK下不同。
錯誤再現:error C2440: 'type cast' : cannot convert
from? 'long (__thiscall CMyWnd::*)(class CPoint)'
to? 'unsigned int (__thiscall CWnd::*)(class CPoint)'
Pointers to members have different representations; cannot cast between them
?
?afx_msg UINT OnNcHitTest(CPoint point);? //VC6.0
afx_msg LRESULT OnNcHitTest(CPoint point);//VS2008
?
17、錯誤再現
MyBase.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CMyBase::GetRuntimeClass(void)const " (?GetRuntimeClass@CDlgBase@@UBEPAUCRuntimeClass@@XZ)
MyDlg.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CMyBase::GetRuntimeClass(void)const " (?GetRuntimeClass@CDlgBase@@UBEPAUCRuntimeClass@@XZ)
原因:在類定義中,DECLARE_DYNAMIC(CMyBase)聲明了這樣一個定義宏,旨在確定運行時對象屬于哪一個類而定義的宏。
DEClARE_DYNCREATE/IMPLEMENT_DYNCREATE 是為了“動態創建"類的實例而定義的宏。new可以用來創建對象,但不是動態的。
?
/*下面的做法是通不過的:*/ char szClassName[60]; cin >> szClassName; CObject* pOb=new szClassName; //通不過 這里就要用到DEClARE_DYNCREATE/IMPLEMENT_DYNCREATE定義的功能了。?
?
但是在使用過程中,如果不進行解釋說明 IMPLEMENT_DYNAMIC(CMyBase, CBase) 會出現GetRuntimeClass 錯誤。出現此錯誤,可以查看 DECLARE_DYNAMIC 定義。\
MSDN解釋(點擊 連接)。
?
/* DECLARE_DYNAMIC 定義 */#define _DECLARE_DYNAMIC(class_name) \ public: \static AFX_DATA CRuntimeClass class##class_name; \virtual CRuntimeClass* GetRuntimeClass() const; \#endif// not serializable, but dynamically constructable #define DECLARE_DYNCREATE(class_name) \DECLARE_DYNAMIC(class_name) \static CObject* PASCAL CreateObject(); DECLARE_DYNAMIC 定義?
?
?
?
?
?
轉載于:https://www.cnblogs.com/Bachelor/p/3572623.html
總結
以上是生活随笔為你收集整理的MFC中小笔记(四)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数学专业考研及读研目录[2014年11月
- 下一篇: FFmpeg编译出错_img_conve