Jump to content
  • Advertisement

Archived

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

cleves

drawing a line

This topic is 5610 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

Hey all, I use this to draw a line: // get the dc first HDC hdc = GetDC(hwnd); // create the green pen HPEN green_pen = CreatePen(PS_SOLID, 1, RGB(0,255,0)); // used to store old pen HPEN old_pen = NULL; // select the pen into the context old_pen = SelectObject(hdc, green_pen); // draw the line MoveToEx(hdc, 10,10, NULL); LineTo(hdc,50,60); // restore old pen SelectObject(hdc, old_pen); // delete the green pen DeleteObject(green_pen); // release the dc ReleaseDC(hwnd, hdc); But when i try to compile he writes: error C2440: ''='' : cannot convert from ''void *'' to ''struct HPEN__ *'' Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast How can i fix it? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
I think the problem is the
HPEN green_pen = CreatePen(PS_SOLID, 1, RGB(0,255,0)); 

line.

Try something like:
HPEN green_pen = (HPEN)CreatePen(PS_SOLID, 1, RGB(0,255,0)); 



"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."

Share this post


Link to post
Share on other sites
Cast the void pointer to HPEN, like

SelectObject(hdc,(HPEN)green_pen)

where the compiler expects HPEN variable.

EDIT:
Valderman, i was half second late
And my example was bad, but anyway casting is the way to go.

[edited by - Nik02 on August 8, 2003 8:11:28 AM]

Share this post


Link to post
Share on other sites
This looks like code from Tricks of the Windows Game Programming Gurus, and if so, here''s what I used to fix it:


old_pen = (HPEN) SelectObject(hdc,green_pen);


Hope that helps,

--hellz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!