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);
} 展开
天正软件
2024-08-02 广告
2024-08-02 广告
上海天正软件有限公司是上海天正信息科技有限公司投资的专注于提供金融行业软件开发及解决方案的公司,上海天正通过与金融企业长期的合作,能够了解金融业务的需要,提供各种客户化的开发及顾问服务,为金融企业裁剪出一套适合自身业务需要的解决方案。...
点击进入详情页
本回答由天正软件提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询