请教hellovfp大哥关于位图的问题
windows编程自学手册看到位图那一节 书中提供了一个Emerson2程序例子 我把.cpp .h .rc文件都录入到VC6中
因为是手抄的编译后出现很多错误 我都一一排除了 剩下最后三个错误 :
D:\开发语言\练习程序\C语言\EMERSON2\Emerson2.cpp(134) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct HBITMAP__ *' (or there is no acceptable conversion)
D:\开发语言\练习程序\C语言\EMERSON2\Emerson2.cpp(135) : error C2675: unary '!' : 'struct tagBITMAP' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\开发语言\练习程序\C语言\EMERSON2\Emerson2.cpp(160) : error C2440: 'type cast' : cannot convert from 'struct tagBITMAP' to 'struct HBITMAP__ *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
貌似都是关于Bitmap的。
出错的就在下面这两个函数里
程序代码:
///////////////////////////// // Create window Load bitmap // from resource ///////////////////////////// #pragma argsused BOOL skyline_OnCreate(HWND hwnd, CREATESTRUCT FAR * lpCreateStruct) { TEXTMETRIC TextMetrics; skylineBitmap = LoadBitmap(hInstance, "skylineBitmap"); // 这句 if (!skylineBitmap) // 和这句 { MessageBox(hwnd, "Not find skylineBitmap!", "Fatal Error", MB_OK | MB_ICONERROR); return FALSE; } HDC PaintDC = GetDC(hwnd); GetTextMetrics(PaintDC, &TextMetrics); ReleaseDC(hwnd, PaintDC); TextHeight = TextMetrics.tmHeight + TextMetrics.tmInternalLeading; SetScrollRange(hwnd, SB_VERT, 0, -1, FALSE); return TRUE; } ///////////////////////////// // Destructor : Delete Bitmap // from Memory ///////////////////////////// #pragma argsused void skyline_OnDestroy(HWND hwnd) { DeleteBitmap(skylineBitmap); // 这这函数 PostQuitMessage(0); }
用Go To Definition 看了下
源程序是这么定义函数和变量的
#define DeleteBitmap(hbm) DeleteObject((HGDIOBJ)(HBITMAP)(hbm))——————————————
// Varliables BITMAP skylineBitmap;————————————————————
程序代码:
/* Bitmap Header Definition */ typedef struct tagBITMAP { LONG bmType; LONG bmWidth; LONG bmHeight; LONG bmWidthBytes; WORD bmPlanes; WORD bmBitsPixel; LPVOID bmBits; } BITMAP, *PBITMAP, NEAR *NPBITMAP, FAR *LPBITMAP;
如果我将 BITMAP skylineBitmap; 改成 BITMAP *skylineBitmap;
就只剩下一个编译错误 D:\开发语言\练习程序\C语言\EMERSON2\Emerson2.cpp(134) : error C2440: '=' : cannot convert from 'struct HBITMAP__ *' to 'struct tagBITMAP *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function- style cast
后来就不知道这么弄了。
一大篇啊 麻烦看看。