nclude<windows.h>
#include<time.h>#define ID_TIME 1
#define CXB 10
#define CXCLIENT (800/CXB)#define CYCLIENT 101void DrawLine(HDC *phdc,POINT *pt)
{
SetMapMode(*phdc,MM_ANISOTROPIC);
SetWindowExtEx(*phdc,1,1,NULL);
SetViewportExtEx(*phdc,CXB,-1,NULL);
SetWindowOrgEx(*phdc,0,CYCLIENT/2,NULL);
Polyline(*phdc,pt,CXCLIENT);
}void SetWindowSize(int *pcx,int *pcy)
{ *pcx = 2*GetSystemMetrics(SM_CXBORDER)+CXCLIENT*CXB;
*pcy = 2*GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYCAPTION)+CYCLIENT+3;
}LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
TCHAR WinAppName[] = TEXT("灵异探测器");
HWND hWnd;
MSG msg;
int cxWindow,cyWindow;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wc.hCursor = LoadCursor(hInstance,IDC_ARROW);
wc.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = WinAppName;
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); SetWindowSize(&cxWindow,&cyWindow); hWnd = CreateWindow(WinAppName,WinAppName,
WS_SYSMENU | WS_BORDER |WS_CAPTION,
CW_USEDEFAULT,CW_USEDEFAULT,
cxWindow,cyWindow,
NULL,NULL,hInstance,0); ShowWindow(hWnd,nShowCmd);
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)
{
int i,y;
static int iResult,cxClient,cyClient,sum;
HDC hdc;
static POINT pt[CXCLIENT];
PAINTSTRUCT ps;
TCHAR szBuffer[32]; switch(message) {
case WM_CREATE: srand((unsigned)time(0));
SetTimer(hWnd,ID_TIME,200,NULL);
for(i=0; i<CXCLIENT; i++)
pt[i].x = i; return 0; case WM_SIZE: cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam); return 0; case WM_TIMER:
hdc = GetDC(hWnd); for(i=0; i < CXCLIENT-1; i++)
pt[i].y = pt[i+1].y;
y = rand()%((int)(CYCLIENT/2));
if(rand()%2)
{
pt[CXCLIENT-1].y = y;
sum++;
}
else
{
pt[CXCLIENT-1].y = -y;
sum--;
}
ReleaseDC(hWnd,hdc);
InvalidateRect(hWnd,NULL,true);
return 0; case WM_PAINT:
hdc = BeginPaint(hWnd,&ps);
DrawLine(&hdc,pt); SelectObject(hdc,CreatePen(PS_SOLID,0,RGB(255,0,0)));
MoveToEx(hdc,0,0,NULL);
LineTo(hdc,CXCLIENT,0);
DeleteObject(SelectObject(hdc,(GetStockObject(BLACK_PEN))));
TextOut(hdc,0,0,szBuffer,wsprintf(szBuffer,TEXT("%d"),sum));
EndPaint(hWnd,&ps);
return 0; case WM_DESTROY:
KillTimer(hWnd,ID_TIME);
PostQuitMessage(0);
return 0; } return DefWindowProc(hWnd,message,wParam,lParam);
}
#include<time.h>#define ID_TIME 1
#define CXB 10
#define CXCLIENT (800/CXB)#define CYCLIENT 101void DrawLine(HDC *phdc,POINT *pt)
{
SetMapMode(*phdc,MM_ANISOTROPIC);
SetWindowExtEx(*phdc,1,1,NULL);
SetViewportExtEx(*phdc,CXB,-1,NULL);
SetWindowOrgEx(*phdc,0,CYCLIENT/2,NULL);
Polyline(*phdc,pt,CXCLIENT);
}void SetWindowSize(int *pcx,int *pcy)
{ *pcx = 2*GetSystemMetrics(SM_CXBORDER)+CXCLIENT*CXB;
*pcy = 2*GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYCAPTION)+CYCLIENT+3;
}LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
TCHAR WinAppName[] = TEXT("灵异探测器");
HWND hWnd;
MSG msg;
int cxWindow,cyWindow;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wc.hCursor = LoadCursor(hInstance,IDC_ARROW);
wc.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = WinAppName;
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); SetWindowSize(&cxWindow,&cyWindow); hWnd = CreateWindow(WinAppName,WinAppName,
WS_SYSMENU | WS_BORDER |WS_CAPTION,
CW_USEDEFAULT,CW_USEDEFAULT,
cxWindow,cyWindow,
NULL,NULL,hInstance,0); ShowWindow(hWnd,nShowCmd);
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)
{
int i,y;
static int iResult,cxClient,cyClient,sum;
HDC hdc;
static POINT pt[CXCLIENT];
PAINTSTRUCT ps;
TCHAR szBuffer[32]; switch(message) {
case WM_CREATE: srand((unsigned)time(0));
SetTimer(hWnd,ID_TIME,200,NULL);
for(i=0; i<CXCLIENT; i++)
pt[i].x = i; return 0; case WM_SIZE: cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam); return 0; case WM_TIMER:
hdc = GetDC(hWnd); for(i=0; i < CXCLIENT-1; i++)
pt[i].y = pt[i+1].y;
y = rand()%((int)(CYCLIENT/2));
if(rand()%2)
{
pt[CXCLIENT-1].y = y;
sum++;
}
else
{
pt[CXCLIENT-1].y = -y;
sum--;
}
ReleaseDC(hWnd,hdc);
InvalidateRect(hWnd,NULL,true);
return 0; case WM_PAINT:
hdc = BeginPaint(hWnd,&ps);
DrawLine(&hdc,pt); SelectObject(hdc,CreatePen(PS_SOLID,0,RGB(255,0,0)));
MoveToEx(hdc,0,0,NULL);
LineTo(hdc,CXCLIENT,0);
DeleteObject(SelectObject(hdc,(GetStockObject(BLACK_PEN))));
TextOut(hdc,0,0,szBuffer,wsprintf(szBuffer,TEXT("%d"),sum));
EndPaint(hWnd,&ps);
return 0; case WM_DESTROY:
KillTimer(hWnd,ID_TIME);
PostQuitMessage(0);
return 0; } return DefWindowProc(hWnd,message,wParam,lParam);
}











