-
problem with case paint
Ok the error says:
ANSI C++ forbids implicit conversion from `void *' in initialization
I have no idea wtf that means, and if you can help me, heres the paint part:
Code:
case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
[b]HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);[b]
GetObject(g_hbmBall, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
}
break;
-
oops im mean
Code:
case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);//here
GetObject(g_hbmBall, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
}
break;
-
Think you need a cast because you are using .cpp file rather than .c files.
HBITMAP hOldBMP=(HBITMAP)SelectObject(hdc,hBitmap);
(MHO: Don't like the mixing of C and C++. Do not think you should call beginPaint() to init a variable. Not good style or good for speed or to find errors. You should already have your DC ready to just Blit when you need to paint. This method will not work fast enough if there is a lot to draw.)
There is no test for the update region, so the whole area is always repainted slowing you down. What if the update region is different size than the bitmap?
-
-
who?
where?
Don't you know what a type cast is?
-
Even in C files, you need to cast. Because it explicitly states what data type the parameter is. Otherwise, you might get compile time errors. I don't think it would cause runtime though...
-
Did you test your theory Garfield?
-
whats a type cast or whatever
-
Type casting defines the return type.
float fVar=1.2345;
int iVar=0;
iVar = fVar;//will generate 'loss of data' warning
iVar = (int)fVar;//will not generate warning
in your case
HBITMAP hOldBMP=(HBITMAP)SelectObject(hdc,hBitmap); //the bold bit is the type cast
-
oooooh ok thanx so far you helped the best
-
Further, you should understand that SelectObject() returns a void* (if you hadn't already gotten that much!), and void pointers MUST be cast in C and C++. The reason for the casting is simple: to avoid mistakes. What if, for instance some idiot tried to do this:
char *s = SelectObject( dc, brush );
The compiler will let you know that you may not want to do that, and it does so by demanding that you cast the void*!
Then again,
char *s = (char*)SelectObject( dc, brush );
...would compile - but at least you got a fair warning the first time!
-
Actually SelectObject() returns a HGDIOBJ (according to MSVC 6).
>>pointers MUST be cast in C
Not totally correct, though I agree it is good practice. It only MUST be cast if you use .cpp files.
I used SelectObject 664 times in my comercial web tool and cast none of them. I do use .c files. Try it without the .cpp files and see what I mean.