⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sin a.c

📁 windows高级程序设计
💻 C
字号:
/*
* Sine.c
* An application that draws a sine wave.
* Developed with the swp template.
* Copyright (c) William H. Murray and Chris H. Pappas, 1998
*/

#include <windows.h>
#include <math.h>

#define pi 3.14159265359

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

char szProgName[]="ProgName";

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPreInst,
                   LPSTR lpszCmdLine,int nCmdShow)
{
	HWND hWnd;
	MSG  lpMsg;
	WNDCLASS wcApp;
	
	wcApp.lpszClassName=szProgName;
	wcApp.hInstance    =hInst;
	wcApp.lpfnWndProc  =WndProc;
	wcApp.hCursor      =LoadCursor(NULL,IDC_ARROW);
	wcApp.hIcon        =NULL;
	wcApp.lpszMenuName =NULL;
	wcApp.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	wcApp.style        =CS_HREDRAW|CS_VREDRAW;
	wcApp.cbClsExtra   =0;
	wcApp.cbWndExtra   =0;
	if (!RegisterClass (&wcApp))
		return 0;
	
	hWnd=CreateWindow(szProgName,"A Sine Wave",
		WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
		CW_USEDEFAULT,CW_USEDEFAULT,
		CW_USEDEFAULT,(HWND)NULL,(HMENU)NULL,
		hInst,(LPSTR)NULL);
	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);
	while (GetMessage(&lpMsg,0,0,0)) {
		TranslateMessage(&lpMsg);
		DispatchMessage(&lpMsg);
	}
	return(lpMsg.wParam);
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT message,
                         WPARAM wParam,LPARAM lParam)
{
	HDC	hdc;
	PAINTSTRUCT ps;
	
	int i;
	
	switch (message)
	{
    case WM_PAINT:
		hdc=BeginPaint(hWnd,&ps);
		
		/* draw the x & y coordinate axes */
		MoveToEx(hdc,100,50,NULL);
		LineTo(hdc,100,350);
		MoveToEx(hdc,100,200,NULL);
		LineTo(hdc,500,200);
		MoveToEx(hdc,100,200,NULL);
		
		/* draw the sine wave */
		MoveToEx(hdc,100,200,NULL);
		for (i=0;i<400;i++)
		{
			LineTo(hdc, 100+i, (int)(200+120*sin(pi*i*(360.0/400.0)/180.0)));
			Sleep(10);
		}
		
		EndPaint(hWnd,&ps);
		break;
    case WM_DESTROY:
		PostQuitMessage(0);
		break;
    default:
		return(DefWindowProc(hWnd,message,wParam,lParam));
		break;
	}
	return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -