Jump to content
  • Advertisement
Sign in to follow this  

HBRUSH question

This topic is 4731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why am I get the following errors : error: invalid conversion from `void*' to `HPEN__*' error: invalid conversion from `void*' to `HBRUSH__*' On the following lines : hpenOld = SelectObject(hdc, hpen); hbrushOld = SelectObject(hdc, hbrush); With the following code :
HDC hdc=GetDC(hwnd);
		
HPEN hpen, hpenOld;
HBRUSH hbrush, hbrushOld;

hpen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0));
hbrush = CreateSolidBrush(RGB(255, 0, 0));

hpenOld = SelectObject(hdc, hpen);
hbrushOld = SelectObject(hdc, hbrush);
		
BitMapObject bmoDude;
RECT rcTemp;
SetRect(&rcTemp,0,0,width,20);
	
bmoDude.Create(hdc,width,height);
FillRect(bmoDude,&rcTemp,(HBRUSH)(hbrush));
ReleaseDC(hwnd,hdc);
		
BitBlt(bmoDude,0,0,width,20,*bmoMain,xcord,ycord,SRCAND);
BitBlt(bmoDude,0,0,width,20,*bmoMain,xcord,ycord,SRCPAINT);

Any help is greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
SelectObject returns a HOBJECT (I think) that is defined as void *. To assign it to an HPEN or HBRUSH, just cast it like so:


hpenOld = (HPEN)SelectObject(hdc, hpen);
hbrushOld = (HBRUSH)SelectObject(hdc, hbrush);

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
SelectObject returns a HOBJECT (I think) that is defined as void *. To assign it to an HPEN or HBRUSH, just cast it like so:


hpenOld = (HPEN)SelectObject(hdc, hpen);
hbrushOld = (HBRUSH)SelectObject(hdc, hbrush);


exact - except the fact that HOBJECT is really HGDIOBJ. Depending on the platform, a HGDIOBJ is either a new HANDLE type or a void* (on PC it is supposed to be a HANDLE).

Regards,

Share this post


Link to post
Share on other sites
The type of HGIOBJ is also effected by whether or not you have STRICT defined.

Anywho, SelectObject returns you a generic object. It doesn't know if it's a pen or a brush or a font or whatever. It's like how malloc returns a void*.

My advice is to #include <windowsx.h> and use SelectFont, SelectBitmap, etc. instead of the generic SelectObject. It makes your code more readable too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!