#include <Windows.h>
#define ID_TIMER 1
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static BOOL f= false;
HBRUSH hbrush;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(uMsg)
{
case WM_CREATE:
{
SetTimer(hwnd,ID_TIMER,1000,NULL);
}break;
case WM_TIMER:
{
MessageBeep(-1);
f = !f;
InvalidateRect(hwnd,NULL,FALSE);
}
case WM_CHAR:
{
}break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
hbrush = CreateSolidBrush(f?RGB(255,0,0):RGB(0,0,255));
FillRect(hdc,&rect,hbrush);
EndPaint(hwnd,&ps);
DeleteObject(hbrush);
}break;
case WM_DESTROY:
{
KillTimer(hwnd,ID_TIMER);
PostQuitMessage(0);
}break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_HAND);
wndclass.hIcon = LoadIcon(NULL,IDI_QUESTION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WindowProc;
wndclass.lpszClassName = "2013_11_27(2)_demo";
wndclass.lpszMenuName =NULL;
wndclass.style = CS_HREDRAW |CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"创建窗口失败","失败",MB_OK);
}
HWND hwnd = CreateWindow("2013_11_27(2)_demo","time的demo",WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,500,500,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
MSG msg;
BOOL flag;
while((flag = GetMessage(&msg,hwnd,0,0))!=0)
{
if(flag==-1)
{
PostQuitMessage(0);
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}