Bitblt更换位图(SDK程序)
使用SDK写了一个图片程序,想实现在按下键盘任意键时候切换图片:
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HBITMAP hBitmapImage;
static HINSTANCE hInstance;
static int l_siClientW,l_siClientH,l_siBitmapW,l_siBitmapH;
BITMAP O_Image;
HDC hdc,hdcImage;
int l_iBitmapX,l_iBitmapY;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT)lParam)->hInstance;
hBitmapImage=(HBITMAP)::LoadImage(NULL,"McDou.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(!hBitmapImage) MessageBox(NULL,"","",MB_OK);
GetObject(hBitmapImage,sizeof(BITMAP),&O_Image);
l_siBitmapW=O_Image.bmWidth;
l_siBitmapH=O_Image.bmHeight;
return 0;
case WM_SIZE:
l_siClientW=LOWORD(lParam);
l_siClientH=HIWORD(lParam);
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
hdcImage=CreateCompatibleDC(hdc);
SelectObject(hdcImage,hBitmapImage);
l_iBitmapX=(l_siClientW-l_siBitmapW)/2;
l_iBitmapY=(l_siClientH-l_siBitmapH)/2;
BitBlt(hdc,l_iBitmapX,l_iBitmapY,l_siBitmapW,l_siBitmapH,hdcImage,0,0,SRCCOPY);
DeleteDC(hdcImage);
EndPaint(hWnd,&ps);
return 0;
case WM_KEYDOWN:
hBitmapImage=(HBITMAP)::LoadImage(NULL,"G.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(!hBitmapImage) MessageBox(NULL,"","",MB_OK);
GetObject(hBitmapImage,sizeof(BITMAP),&O_Image);
l_siBitmapW=O_Image.bmWidth;
l_siBitmapH=O_Image.bmHeight;
return 0;
case WM_DESTROY:
case WM_CLOSE:
DeleteObject(hBitmapImage);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
没成功,请高手指点(评论我折段代码的实用性或先进性的免回)。