Newbie SDK Problem

Started by
1 comment, last by max_j 23 years, 5 months ago
I am working with one of the SDK examples (which comes with the MSDN Library), but I have a problem as it is not compatible with VC++ 6.0. There''s this code: ------------------------ 1. HDC hdc; 2. HDC hmemorydcNew; 3. HDC hmemorydcOld; 4. LONG checkMarkSize; 5. HBITMAP hCheckBitmap; 6. HBITMAP hOldBitmapSave; 7. HBITMAP hNewBitmapSave; 8. 9. hdc = GetDC (hwnd); 10. 11. hmemorydcNew = CreateCompatibleDC (hdc); 12. hmemorydcOld = CreateCompatibleDC (hdc); 13. 14. checkMarkSize = GetMenuCheckMarkDimensions (); 15. 16. hCheckBitmap = CreateCompatibleBitmap (hdc, LOWORD (checkMarkSize),HIWORD (checkMarkSize)); 17. 18. hOldBitmapSave = SelectObject (hmemorydcNew, hCheckBitmap); 19. hNewBitmapSave = SelectObject (hmemorydcOld, hbm); ------------------------- Lines 18 and 19 throw an error like this: Error C2440: ''='' : cannot convert from ''void *'' to ''struct HBITMAP__ *'' Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast Someone said that it was written with VC++ 5.0. So, how should I fix it to make it VC++ 6.0 compatible ?????
Advertisement
Try putting a (HBITMAP) after the = sign, like this:

    1. HDC hdc;HDC hmemorydcNew;HDC hmemorydcOld;LONG checkMarkSize;HBITMAP hCheckBitmap;HBITMAP hOldBitmapSave;HBITMAP hNewBitmapSave;hdc = GetDC (hwnd); hmemorydcNew = CreateCompatibleDC (hdc);hmemorydcOld = CreateCompatibleDC (hdc);checkMarkSize = GetMenuCheckMarkDimensions ();hCheckBitmap = CreateCompatibleBitmap (hdc, LOWORD (checkMarkSize),HIWORD (checkMarkSize));hOldBitmapSave = (HBITMAP) SelectObject (hmemorydcNew, hCheckBitmap);hNewBitmapSave = (HBITMAP) SelectObject (hmemorydcOld, hbm);    


Though, why you need to save the return value of a SelectObject is something I don''t know...

Null and Void
It is an inexperienced programmer who speaks of the length of his works.
It is an experienced one who speaks of the briefness.
http://www.crosswinds.net/~druidgames/
Try to cast the return value of SelectObject() to HBITMAP. So line 18 would become

hOldBitmapSave = (HBITMAP)SelectObject (hmemorydcNew, hCheckBitmap);

Do the same with line 19.
This is because SelectObject() returns a more general GDI object handle (HGDIOBJ), because you can select other object types than bitmaps.

Oh, someone as been faster.

Edited by - VolkerG on October 29, 2000 4:43:39 AM

This topic is closed to new replies.

Advertisement