一直试验不成功,不知道原因在哪里,用窗口hdc就可以,用创建的hMemDc就不行...一直显示白屏,在这里求教?
http://pan.baidu.com/s/1ntIhANB 帖了百度盘的链接,里面有代码.
代码就是加载了背景图,和一张图片.然后移动的图片,出现闪屏,所以想用双缓冲来弄.
懂的人,帮个忙,谢谢.折腾了三天了.
下面是核心代码,真心不知道哪里出错了!!!链接里有工程代码,有点乱,见谅...在学习中..麻烦懂的人帮我看一下.真心请教,谢谢大家了.
static HBITMAP hCloudBMP;
static HDC cloudDC;
BITMAP bm; //for get cloud bmp size
static HBITMAP hBgBMP;
static HDC bgDC;
BITMAP bgBm;
static HDC hMemDC;
static HBITMAP hTemp;
BITMAP bgTest;
HDC hdc;
int x,y=0;
int step=0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
RECT rect;
switch (message)
{
case WM_CREATE:
hCloudBMP=(HBITMAP)LoadImage(NULL,"1.bmp",IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
cloudDC =CreateCompatibleDC(hdc);
SelectObject(cloudDC,hCloudBMP);
ReleaseDC(hWnd, hdc);
GetObject(hCloudBMP,sizeof(BITMAP), &bm);
//x=bm.bmWidth;
//y=bm.bmHeight;
hBgBMP=(HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
bgDC=CreateCompatibleDC(hdc);
SelectObject(bgDC,hBgBMP);
ReleaseDC(hWnd, hdc);
GetObject(hBgBMP,sizeof(BITMAP),&bgBm);
//hTemp=(HBITMAP)LoadImage(NULL,"test.bmp",IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE);
hMemDC=CreateCompatibleDC(hdc);
hTemp=CreateCompatibleBitmap(hdc, 1280, 720);
SelectObject(hMemDC, hTemp);
//FillRect(hMemDC,
//DeleteObject(hTemp);
ReleaseDC(hWnd,hdc);
SetTimer(hWnd,100,100,NULL);
break;
case WM_TIMER:
x+=5;
y+=3;
InvalidateRect(hWnd,NULL,true);
//UpdateWindow(hWnd);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd, &ps);
BitBlt(hMemDC,0,0,bgBm.bmWidth,bgBm.bmHeight,bgDC,0,0,SRCCOPY);
if(step==0)
{
BitBlt(hMemDC,x,y,bm.bmWidth,bm.bmHeight,cloudDC,0,0,SRCCOPY);
}
else
{
//BitBlt(hdc,x,y,bm.bmWidth,bm.bmHeight,hMemDC,0,0,SRCCOPY);
}
//BitBlt(hdc,0,0,100,100,hMemDC,0,0,SRCCOPY);
BitBlt(hdc,0,0,1280,720,hMemDC,0,0,SRCCOPY);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
DeleteDC(cloudDC);
DeleteObject(hCloudBMP);
DeleteDC(bgDC);
DeleteObject(hBgBMP);
DeleteDC(hMemDC);
KillTimer(hWnd,10);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}