1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <Windows.h>
#include <math.h>
#define screen_width 800
#define screen_height 600
#define pi 3.14159
COLORREF blue = RGB(0, 0, 255);
double _amp = 50;
int _sTime = 5;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void wavefunc(HDC, double);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
HDC hDC;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = (HICON)LoadImage(NULL, "C:\\Visual Studio 2010\\Icons\\Smiley.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
wc.lpszClassName = "SineWave";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
"SineWave",
"Wave",
WS_OVERLAPPEDWINDOW,
0, 45,
screen_width, screen_height,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
hDC = GetDC(hWnd);
MSG msg;
while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
wavefunc(hDC, _amp);
ScrollWindow(hWnd, -1, 0, NULL, NULL);
Sleep(_sTime);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_UP:
_amp--;
break;
case VK_DOWN:
_amp++;
break;
case VK_LEFT:
_sTime++;
if(_sTime > 50)
_sTime = 50;
break;
case VK_RIGHT:
_sTime--;
if(_sTime < 1)
_sTime = 1;
break;
}
return 0;
} break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void wavefunc(HDC hDC, double _amp)
{
static int _x = 0;
int _y;
_y = sin(_x/_amp)*100 + 300;
SetPixel(hDC, 600, _y, blue);
_x += 1;
}
|