#include<Windows.h>
#include<math.h> #define NUM 1000
#define PI 3.14159 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) ;
void Draw(HWND) ; static int cxClient, cyClient, xOffset, yOffset;
POINT apt[NUM] ;
static int A = ; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("谐振动合成") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ; wndclass.cbClsExtra = NULL ;
wndclass.cbWndExtra = NULL ;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH) ;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION) ;
wndclass.hInstance = hInstance ;
wndclass.lpfnWndProc = WndProc ;
wndclass.lpszClassName = szAppName ;
wndclass.lpszMenuName = NULL ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ; if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This Program Requires Windows NT !"), szAppName, MB_ICONERROR) ;
return ;
} hwnd = CreateWindow(szAppName, TEXT("谐振动合成"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow(hwnd, iCmdShow) ;
UpdateWindow(hwnd) ; while(TRUE)
{
if(PeekMessage(&msg, NULL, , , PM_REMOVE))
{
if(msg.message == WM_QUIT)
break ;
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
else
{
Draw(hwnd) ;
}
}
return msg.wParam ;
} LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ switch(message)
{
case WM_SIZE :
cxClient = LOWORD(lParam) ;
cyClient = HIWORD(lParam) ;
xOffset = cxClient / ;
yOffset = cyClient / ;
A = xOffset < yOffset ? xOffset : yOffset ; return ; case WM_DESTROY :
PostQuitMessage() ;
return ;
}
return DefWindowProc(hwnd, message, wParam, lParam) ;
} void Draw(HWND hwnd)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
int t ;
static double w1 = , w2 = ; // w1 : w2 = 1 : 2
static double g = PI / ; // 初相位之差 hdc = GetDC(hwnd) ; apt[].x = xOffset ;
apt[].y = yOffset + A * sin(g) ;
MoveToEx(hdc, apt[].x, apt[].y, NULL) ;
for(t = ; t < NUM ; t++)
{
apt[t].x = xOffset + A * sin(t * * w1 * w2 * PI /( NUM * w1 ));
apt[t].y = yOffset + A * sin(t * * w1 * w2 * PI /( NUM * w2 ) + g ) ;
LineTo(hdc, apt[t].x, apt[t].y) ;
MoveToEx(hdc, apt[t].x, apt[t].y, NULL) ;
}
// Polyline(hdc, apt, NUM ) ; rect.bottom = cyClient ;
rect.left = ;
rect.right = cxClient ;
rect.top = ; // Sleep(1000) ;
// w1 ++ ;
// w2 ++ ;
// g += PI / 4 ;
// InvalidateRect(hwnd, &rect, TRUE) ; ReleaseDC(hwnd, hdc) ;
}