[Win32]曲线绘制

1. 用直线拟合正弦曲线以及矩形、椭圆线等的绘制:

// sinewave_linedemo.c

#include 
#include 

#define NUM		1000
#define DPI		( 2 * 3.1415926 )

POINT	apt[NUM]; // 用1000个点来拟合一个周期的sin

LRESULT CALLBACK WndPorc( HWND hWnd, UINT message, WPARAM wPram, LPARAM lParam );

int WINAPI WinMain(
	HINSTANCE	hInstance,
	HINSTANCE	hPrevInstance,
	LPSTR		lpszCmdLine,
	int			nCmdShow
	)
{
	static TCHAR	szAppName[] = TEXT("sinewave_linedemo");

	WNDCLASS	wndclass;
	HWND		hWnd;
	MSG			msg;

	wndclass.style			= CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc	= WndPorc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hInstance;
	wndclass.hIcon			= LoadIcon( NULL, IDI_APPLICATION );
	wndclass.hCursor		= LoadCursor( NULL, IDC_ARROW );
	wndclass.hbrBackground	= (HBRUSH)GetStockObject( WHITE_BRUSH );
	wndclass.lpszMenuName	= NULL;
	wndclass.lpszClassName	= szAppName;

	RegisterClass( &wndclass );

	hWnd = CreateWindow(
		szAppName,
		TEXT("Sine Wave & Line Demo"),
		WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, // 上半部显示正弦波下半部显示各种曲线,因此窗口开到最大
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, NULL, hInstance, NULL
	);
	
	ShowWindow( hWnd, SW_MAXIMIZE );
	UpdateWindow( hWnd );

	while ( GetMessage( &msg, NULL, 0, 0 ) )
	{
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}

	return msg.wParam;
}

LRESULT CALLBACK WndPorc( HWND hWnd, UINT message, WPARAM wPram, LPARAM lParam )
{
	static int		cxClient, cyClient;

	HDC				hDC;
	PAINTSTRUCT		ps;

	int		i;

	switch ( message)
	{
	case WM_SIZE:
		cxClient = LOWORD( lParam );
		cyClient = HIWORD( lParam );
		return 0;

	case WM_PAINT:
		hDC = BeginPaint( hWnd, &ps );

		// 在任何时候环境设备都有一个当前位置,即一个点
		// 很多画线函

你可能感兴趣的:(Win32,曲线绘制,Win32)