我使用vc sdk 加载位图,编译通过,运行成功,但就是没显示 120
我的代码如下:#include<windows.h>#include<string.h>#include<stdlib.h>#include<stdio.h>LRESUL...
我的代码如下:
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
LRESULT CALLBACK wndproc(HWND,UINT,WPARAM,LPARAM);//窗口函数说明
HDC hdcmem;//内存环境句柄
HDC hdc;//设备环境句柄
HBITMAP hbm;//位图句柄
BITMAP bm;//位图结构
PAINTSTRUCT ps;
//int x1=0,y1=0,x2=0,y2=0;
//初始化窗口类
int WINAPI WinMain(HINSTANCE hinstance,//当前实例句柄
HINSTANCE hprevinst,//其他实例句柄
LPSTR lpszcmdline,//指向程序命令行参数的指针
int ncmdshow)//应用程序开始执行时窗口显示方式的整数值标识
{
HWND hwnd;//表示窗口句柄
MSG msg;
WNDCLASS wndclass;
char lpszclassname[]="窗口类名";//窗口类名
char lpsztitle[]="窗口标题名";
//窗口类的定义
wndclass.style=0;
wndclass.lpfnWndProc=wndproc;
wndclass.hInstance=hinstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszclassname;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
//一下进行窗口类的注册
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
//创建窗口
hwnd=CreateWindow(lpszclassname,
lpsztitle,
WS_OVERLAPPEDWINDOW |WS_SYSMENU|WS_CAPTION ,
200,
100,
500,
500,
NULL,
NULL,
hinstance,
NULL);
hbm=LoadBitmap(hinstance,"bitmap1.bmp");
GetObject(hbm,sizeof(BITMAP),(LPVOID)&bm);
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)
{
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdcmem,hbm);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
DeleteObject(hbm);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
} 展开
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
LRESULT CALLBACK wndproc(HWND,UINT,WPARAM,LPARAM);//窗口函数说明
HDC hdcmem;//内存环境句柄
HDC hdc;//设备环境句柄
HBITMAP hbm;//位图句柄
BITMAP bm;//位图结构
PAINTSTRUCT ps;
//int x1=0,y1=0,x2=0,y2=0;
//初始化窗口类
int WINAPI WinMain(HINSTANCE hinstance,//当前实例句柄
HINSTANCE hprevinst,//其他实例句柄
LPSTR lpszcmdline,//指向程序命令行参数的指针
int ncmdshow)//应用程序开始执行时窗口显示方式的整数值标识
{
HWND hwnd;//表示窗口句柄
MSG msg;
WNDCLASS wndclass;
char lpszclassname[]="窗口类名";//窗口类名
char lpsztitle[]="窗口标题名";
//窗口类的定义
wndclass.style=0;
wndclass.lpfnWndProc=wndproc;
wndclass.hInstance=hinstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszclassname;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
//一下进行窗口类的注册
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
//创建窗口
hwnd=CreateWindow(lpszclassname,
lpsztitle,
WS_OVERLAPPEDWINDOW |WS_SYSMENU|WS_CAPTION ,
200,
100,
500,
500,
NULL,
NULL,
hinstance,
NULL);
hbm=LoadBitmap(hinstance,"bitmap1.bmp");
GetObject(hbm,sizeof(BITMAP),(LPVOID)&bm);
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)
{
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdcmem,hbm);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
DeleteObject(hbm);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询