drawing a line
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
I think the problem is the
line.
Try something like:
"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."
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."
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]
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]
What''s your compiler and in which line exactly the problem occurs ?
------------------------
- Seby -
www.dfhi-bomber.fr.st
------------------------
- Seby -
www.dfhi-bomber.fr.st
This looks like code from Tricks of the Windows Game Programming Gurus, and if so, here''s what I used to fix it:
Hope that helps,
--hellz
old_pen = (HPEN) SelectObject(hdc,green_pen);
Hope that helps,
--hellz
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement