GDI , someone can helpe me ? II
´m reading TOTWGPG and i get into the gdi part. so i make this code:
bool BotarLine(HWND hwnd)
{
HDC hdc = GetDC(hwnd);
HPEN pen = NULL;
HPEN oldpen = NULL;
pen = CreatePen(PS_SOLID,1,RGB(0,255,0));
oldpen = SelectObject(hdc, pen); <= the error is here
// do line stuff
SelectObject(hdc,oldpen);
DeleteObject(pen);
return 0;
}
is exact the thing that was explained in TOTGPG but i always get this error:
C:\projetos\treino\treinoadv.cpp(29) : error C2440: ''='' : cannot convert from ''void *'' to ''struct HPEN__ *''
Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast
Error executing cl.exe.
so what is wrong? i already used the vc++ documentation but they do the same thing i do too
i even tryed to compile the similar code thats comes in TOTGPG but it gives me the same error
so someone can help me?
-...you know, brazilian girls have a big ..., it would be the happiest day of may live...
you know when you put oldpen = SelectObject(hdc, pen); ??
Change that to
oldpen = (HPEN)SelectObject(hdc, pen);
It needs a special type of cast. That'll probably fix it! If it doesn't, then change pen = CreatePen(PS_SOLID,1,RGB(0,255,0)); to:
pen = (HPEN)CreatePen(PS_SOLID,1,RGB(0,255,0));
Do that ONLY if my first solution doesn't work. If my first solution doesn't work, keep the (HPEN) on there- you definately need it to. Sorry, I'm a little rusty on my GDI, but my first solution should work if memory serves me right.
There are three types of people in the world; those who can count, and those who can't.
Edited by - Fredric on May 22, 2000 1:37:13 PM
Change that to
oldpen = (HPEN)SelectObject(hdc, pen);
It needs a special type of cast. That'll probably fix it! If it doesn't, then change pen = CreatePen(PS_SOLID,1,RGB(0,255,0)); to:
pen = (HPEN)CreatePen(PS_SOLID,1,RGB(0,255,0));
Do that ONLY if my first solution doesn't work. If my first solution doesn't work, keep the (HPEN) on there- you definately need it to. Sorry, I'm a little rusty on my GDI, but my first solution should work if memory serves me right.
There are three types of people in the world; those who can count, and those who can't.
Edited by - Fredric on May 22, 2000 1:37:13 PM
Yeah I got the same problem, but i just took a look in the source code on the CD, and sure enough, it used the cast that Frederic mentioned. I mean, if you look at your error message, it even tells you that you need to cast it.
"Born of a Broken Man, but not a broken man."
"Born of a Broken Man, but not a broken man."
This is a pretty strange error, since I do it that way all the time and I dont get an error. Wierd... Actually, I do it that way, only oldpen is a *CPen type (pointer to a CPen object), and that works well. You can try that.
Also, its a bool function, so return a bool type, not 0 (just a little thing i noticed, tehe )
Also, its a bool function, so return a bool type, not 0 (just a little thing i noticed, tehe )
Could you be using vc5, zipster? I''m using vc6, and in similar posts (this kind of question pops up a lot), people usually say that vc6 typechecks much harder than no 5
i do not tryed that yet but i remenber somenthing about that in "Windows Game Progaming For Dummies" weird he don´t somenthing about it in TOWGPG
for some reasons everytime i see somebody saying GDI, i think they''re talking about Global Defence Initiative.
- pouya
--------------
Don't take life seriously, you won't get out of it alive!
- pouya
--------------
Don't take life seriously, you won't get out of it alive!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement