vc 显示位图问题
错哪了,可以运行,但就是显示不了图片#include<Windows.h>HBITMAPhb,bg;HDCbdc,hdc,mdc;HWNDhWnd;LRESULTCALL...
错哪了,可以运行,但就是显示不了图片
#include<Windows.h>
HBITMAP hb,bg;
HDC bdc, hdc,mdc;
HWND hWnd;
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE preInstance, PSTR szCmdLine, int iCmdShow)
{ hdc = GetDC(hWnd);
MSG msg;
bdc = CreateCompatibleDC(hdc);
mdc = CreateCompatibleDC(hdc);
hb = CreateCompatibleBitmap(hdc,640,480);
bg = (HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
SelectObject(bdc,bg);
SelectObject(mdc,hb);
WNDCLASSEX ws;
ws.cbClsExtra = 0;
ws.cbSize = sizeof(WNDCLASSEX);
ws.cbWndExtra = 0;
ws.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
ws.hCursor = LoadCursor(NULL,IDC_ARROW);
ws.hIcon = LoadIcon(NULL,IDI_APPLICATION);
ws.hIconSm = NULL;
ws.hInstance = hInstance;
ws.lpfnWndProc = WinProc;
ws.lpszClassName = "teris";
ws.lpszMenuName = NULL ;
ws.style = CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&ws))
{
return 0;
}
hWnd = CreateWindow("Teris","Teris",WS_OVERLAPPEDWINDOW,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
SetTimer(hWnd,1,10,NULL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hWnd ,UINT msg, WPARAM wParam ,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
switch (wParam)
{ case VK_DOWN:
break;
case VK_NEXT:
break;
}
break;
case WM_CREATE:
break;
case WM_TIMER:
InvalidateRect (hWnd, NULL, FALSE) ;
break;
case WM_PAINT:
BitBlt(mdc,0,0,640,480,bdc,0,0,SRCCOPY);
break;
case WM_DESTROY:
DeleteDC(mdc);
DeleteDC(bdc);
DeleteObject(hb);
DeleteObject(bg);
ReleaseDC(hWnd,hdc);
PostQuitMessage(0);
KillTimer(hWnd,1);
return 0;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
} 展开
#include<Windows.h>
HBITMAP hb,bg;
HDC bdc, hdc,mdc;
HWND hWnd;
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE preInstance, PSTR szCmdLine, int iCmdShow)
{ hdc = GetDC(hWnd);
MSG msg;
bdc = CreateCompatibleDC(hdc);
mdc = CreateCompatibleDC(hdc);
hb = CreateCompatibleBitmap(hdc,640,480);
bg = (HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
SelectObject(bdc,bg);
SelectObject(mdc,hb);
WNDCLASSEX ws;
ws.cbClsExtra = 0;
ws.cbSize = sizeof(WNDCLASSEX);
ws.cbWndExtra = 0;
ws.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
ws.hCursor = LoadCursor(NULL,IDC_ARROW);
ws.hIcon = LoadIcon(NULL,IDI_APPLICATION);
ws.hIconSm = NULL;
ws.hInstance = hInstance;
ws.lpfnWndProc = WinProc;
ws.lpszClassName = "teris";
ws.lpszMenuName = NULL ;
ws.style = CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&ws))
{
return 0;
}
hWnd = CreateWindow("Teris","Teris",WS_OVERLAPPEDWINDOW,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
SetTimer(hWnd,1,10,NULL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hWnd ,UINT msg, WPARAM wParam ,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
switch (wParam)
{ case VK_DOWN:
break;
case VK_NEXT:
break;
}
break;
case WM_CREATE:
break;
case WM_TIMER:
InvalidateRect (hWnd, NULL, FALSE) ;
break;
case WM_PAINT:
BitBlt(mdc,0,0,640,480,bdc,0,0,SRCCOPY);
break;
case WM_DESTROY:
DeleteDC(mdc);
DeleteDC(bdc);
DeleteObject(hb);
DeleteObject(bg);
ReleaseDC(hWnd,hdc);
PostQuitMessage(0);
KillTimer(hWnd,1);
return 0;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询