Archived

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

cleves

drawing a line

Recommended Posts

cleves    148
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
Valderman    513
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
Nik02    4351
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
hellz    356
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