关于使用LoadBitmap显示位图的问题
以下是我写的回调函数的部分:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hinstance;
HDC hdc,hdc1;
BITMAP bitmap;
static HBITMAP hbitmap;
PAINTSTRUCT ps;
switch (message) /* handle the messages */
{
case WM_CREATE:
{
hinstance=((LPCREATESTRUCT)lParam)->hInstance;
hbitmap=LoadBitmap(hinstance,"shit");
GetObject(hbitmap,sizeof(BITMAP),&bitmap);
}
break;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);
hdc1=CreateCompatibleDC (hdc);
SelectObject(hdc1,hbitmap);
BitBlt (hdc, 0, 0, 100, 100, hdc1, 0, 0, SRCCOPY) ;
DeleteDC (hdc1) ;
EndPaint (hwnd, &ps) ;
}
break;
注意红色的那一句,必须使用static,这个才能正常工作,如果没有static,就什么也不显示了,这是为什么?