from:
//Copyright (c) LeafCore#include#include #include LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);void draw(HDC);char szClassName[ ] = "LeafCore";int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil){ HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); if (!RegisterClassEx(&wincl)) return 0; hwnd=CreateWindowEx( 0, szClassName, "LeafCore", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow(hwnd, nFunsterStil); while(GetMessage(&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam;}LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_PAINT: hdc=BeginPaint(hwnd, &ps); HPEN green_pen=CreatePen(PS_SOLID, 1, RGB(0, 127, 0)); HPEN old_pen=(HPEN) SelectObject(hdc, green_pen); draw(hdc); SelectObject(hdc, old_pen); DeleteObject(green_pen); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0;}void draw(HDC hdc){ //q的数量 const int const_q=1000; double q[const_q]; double x, y; //q中的最大数 double greatest; //q中的最小数 double least; //初始化随机数产生器 srand(time(0)); //产生q for (int i=0; i q[i]) { least=q[i]; } } //画出代表最大数的直线 MoveToEx(hdc, -100*4+450, (int)-greatest+600, 0); LineTo(hdc, 100*4+450, (int)-greatest+600); //画出代表最小数的直线 MoveToEx(hdc, -100*4+450, (int)-least+600, 0); LineTo(hdc, 100*4+450, (int)-least+600); //依次画出x取-100、-99、……、-1时的点 for (int i=-100; i<0; i++) { x=i; y=0; for (int j=0; j