69,373
社区成员
发帖
与我相关
我的任务
分享
#include"Beauty.h"
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wndclass; MSG msg;
HWND hwnd;
int Screen_Height,Screen_Width;//记录屏幕尺寸
wndclass.cbClsExtra=wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=L"美化窗口类";
wndclass.lpszMenuName=0;
wndclass.style=CS_HREDRAW |CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,L"Error with Registing window class !",L"Information",MB_OK);
return -1;
}
Screen_Height=GetSystemMetrics(SM_CYSCREEN);
Screen_Width=GetSystemMetrics(SM_CXSCREEN);
Screen_Width=Screen_Width/2-300;
Screen_Height=Screen_Height/2-205;
hwnd=CreateWindow(L"美化窗口类",L"惜雨出品", WS_VISIBLE|WS_MINIMIZEBOX|WS_CLIPSIBLINGS\
|WS_CAPTION|WS_SYSMENU,Screen_Width,Screen_Height,600,410,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HINSTANCE hInstance;//实例句柄
static HBITMAP hbitmap;
static int BMP_Height,BMP_Width;//位图宽度和高度
BITMAP bitmap;
HANDLE handle;
HDC hdc,hdcmem;//创建兼容设备句柄
int error;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT)lParam)->hInstance;
hbitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
error=GetLastError();
GetObject(hbitmap,sizeof(BITMAP),&bitmap);
BMP_Width=bitmap.bmWidth;
BMP_Height=bitmap.bmHeight;
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//EndPaint(hwnd,&ps);
//DeleteDC(hdc);
//return 0;
//case WM_ERASEBKGND:
// hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);
handle=SelectObject(hdcmem,hbitmap);
BitBlt(hdc,0,0,BMP_Width,BMP_Height,hdcmem,0,0,SRCCOPY);
SelectObject(hdc,handle);
DeleteDC(hdc);
EndPaint(hwnd,&ps);
return 1;
case WM_CLOSE:
DestroyWindow(hwnd);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
不应该是这样的啊!!!