VC++多位图显示问题 30

为什么不能显示位图?//代码#include<windows.h>#include<string.h>#include<stdlib.h>#include<stdio.h... 为什么不能显示位图?
//代码
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//-logo-----------
HDC hdc;
HDC hdcmem;
HBITMAP hBm;
BITMAP bm;
//--tailgate------
HDC hdc_tailgate;
HDC hdcmem_tailgate;
HBITMAP hBm_tailgate;
BITMAP bm_tailgate;
static int pos=400;
//-------
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="位图";
char lpszTitle[]="BitMap";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=0;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
820,
600,
NULL,
NULL,
hInstance,
NULL);

hBm=LoadBitmap(hInstance,"logo"); //加载
GetObject(hBm,sizeof(BITMAP),(LPVOID)&bm);
hBm_tailgate=LoadBitmap(hInstance,"tailgate");
GetObject(hBm_tailgate,sizeof(BITMAP),(LPVOID)&bm_tailgate);

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
PAINTSTRUCT ps_tailgate;
switch(message)
{
case WM_CREATE:
//---logo------
hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);
ReleaseDC(hwnd,hdc);
//-tailgate------
hdc_tailgate=GetDC(hwnd);
hdcmem_tailgate=CreateCompatibleDC(hdc_tailgate);
ReleaseDC(hwnd,hdc_tailgate);
case WM_PAINT:
//---logo-----
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdcmem,hBm);
BitBlt(hdc,180,80,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
//----tailgate------------
展开
 我来答
jiushini0101
2008-11-25
知道答主
回答量:1
采纳率:0%
帮助的人:0
展开全部
hdc_tailgate=BeginPaint(hwnd,&ps_tailgate);
SelectObject(hdcmem_tailgate,hBm_tailgate);
if(pos<=0)
{ BitBlt(hdc_tailgate,0,370,bm_tailgate.bmWidth,bm_tailgate.bmHeight,hdcmem_tailgate,0,0,SRCCOPY);
pos=0;
}
else if(pos>=530)
{ BitBlt(hdc_tailgate,540,370,bm_tailgate.bmWidth,bm_tailgate.bmHeight,hdcmem_tailgate,0,0,SRCCOPY);
pos=530;
}
else BitBlt(hdc_tailgate,pos,370,bm_tailgate.bmWidth,bm_tailgate.bmHeight,hdcmem_tailgate,0,0,SRCCOPY); //
EndPaint(hwnd,&ps_tailgate);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_LEFT:
pos-=50;
InvalidateRect (hwnd,NULL,TRUE) ;//整个客户区重画
return 0 ;
case VK_RIGHT:
pos+=50;
InvalidateRect (hwnd,NULL,TRUE) ;//整个客户区重画
return 0 ;
}
case WM_DESTROY:
DeleteObject(hBm);
DeleteObject(hBm_tailgate);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
//里头有两张位图,logo和tailgate
//补充上题的......
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
微测检测5.10
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇... 点击进入详情页
本回答由微测检测5.10提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式