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);
}
展开
 我来答
ziyang64
2012-11-21 · TA获得超过962个赞
知道小有建树答主
回答量:529
采纳率:0%
帮助的人:810万
展开全部
你的BitBlt函数将位图显示到了mdc上,而mdc跟这个窗口没有关系的。
这样改一下就行了:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc = BeginPaint( hWnd, &ps );
BitBlt( dc,0,0,640,480,bdc,0,0,SRCCOPY);
EndPaint( hWnd, &ps );
}
break;
帅幻迩3N
2012-11-21 · TA获得超过682个赞
知道小有建树答主
回答量:486
采纳率:100%
帮助的人:296万
展开全部
首先
hdc = GetDC(hWnd);
调用的地方就不对,窗口都还没有Create,hWnd怎么会有意义呢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式