#include
#include
#include "resource.h"
#include
BOOLEAN InitWindowClass(HINSTANCE hinstance,int nCmdshow);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HBITMAP hBitmap;
BITMAP Bitmap;
HBITMAP hmemBitmap;
HDC hdc,hmemdc,hmemdc_1;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[] = "窗口";
char lpszTitle[]= "My_Windows";
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
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;
if(!RegisterClass(&wndclass))
{
MessageBeep(0) ;
return FALSE ;
}
hwnd=CreateWindow(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
hBitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP01));
GetObject(hBitmap,sizeof(BITMAP),&Bitmap);
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 PtStr;
RECT rect;
HBRUSH hbrush;
static WORD x,y;
int X=200,Y=100;
switch(message)
{
case WM_MOUSEMOVE: //处理鼠标移动信息.
x=LOWORD(lParam); //获得鼠标的X坐标.
y=HIWORD(lParam); //获得鼠标的Y坐标.
// hcursor= LoadCursorFromFile(".\\chuizi.cur");
SetCursor((HCURSOR)LoadImage(NULL,".\\chuizi.cur",IMAGE_ICON,50,50,LR_LOADFROMFILE));
return 0;
case WM_LBUTTONDOWN:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,1);
ReleaseDC(hwnd,hdc);
break;
case WM_CREATE:
hdc=GetDC(hwnd);
hmemdc=CreateCompatibleDC(NULL);
hmemdc_1=CreateCompatibleDC(NULL);
SetTimer(hwnd,1,100,NULL);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&PtStr);
GetClientRect(hwnd,&rect);
hbrush=CreateSolidBrush(RGB(0,135,0));
SelectObject(hdc,hbrush);
Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
SelectObject(hmemdc_1,hBitmap);
hmemBitmap=CreateCompatibleBitmap(hdc,rect.right , rect.bottom );
SelectObject(hmemdc,hmemBitmap);
FillRect(hmemdc,&rect,NULL);
// SelectObject(hmemdc,hBitmap);
BitBlt(hmemdc,0,0,Bitmap.bmWidth,Bitmap.bmHeight,hmemdc_1,0,0,SRCCOPY);
BitBlt(hdc,0,0,Bitmap.bmWidth,Bitmap.bmHeight,hmemdc,0,0,SRCCOPY);
EndPaint(hwnd,&PtStr);
break;
case WM_TIMER:
//如果按下开始按钮则开始刷新
InvalidateRect(hwnd,NULL,0);
break;
case WM_DESTROY:
DeleteObject(hBitmap);
DeleteObject(hmemBitmap);
ReleaseDC(hwnd,hdc);
ReleaseDC(hwnd,hmemdc);
ReleaseDC(hwnd,hmemdc_1);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}