This topic is now archived and is closed to further replies.


Newbie SDK Problem

Recommended Posts

max_j    122
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 ?????

Share this post

Link to post
Share on other sites
Null and Void    1088
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.

Share this post

Link to post
Share on other sites
VolkerG    151
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

Share this post

Link to post
Share on other sites