GDI함수의 래퍼클래스 제작으로 Sine 곡선그리기

By | 2014년 6월 13일

sine

#include <windows.h>
#include <math.h>
#include "stdafx.h"
#include "CView.h"
#include "DC.h"

CView app;

//{{AFX_MESSAGE
BEGIN_MESSAGE_MAP(CView)
    {WM_CREATE,&CView::OnCreate},
	{WM_PAINT,&CView::OnDraw},
	{WM_DESTROY,&CView::OnDestroy},
	{WM_SIZE,&CView::OnSize},
	{WM_LBUTTONDOWN,&CView::OnLButtonDown},
END_MESSAGE_MAP()
//}}AFX_MESSAGE

LRESULT CView::OnCreate(WPARAM wParam,LPARAM lParam){
	return 0L;
}

LRESULT CView::OnDraw(WPARAM wParam,LPARAM lParam){
	HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;

	hdc=BeginPaint(hwnd,&ps);
	GetClientRect(hwnd,&rect);
	DrawText(hdc,"Hello Window",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
	EndPaint(hwnd,&ps);
	return 0L;
}

LRESULT CView::OnDestroy(WPARAM wParam,LPARAM lParam){
	PostQuitMessage(0);
	return 0L;
}

LRESULT CView::OnLButtonDown(WPARAM wParam,LPARAM lParam) {
	//PostQuitMessage(0);
	//{{SCHEO
	int i;
	//hdc = GetDC(hwnd);	
	CDC dc(this);
	//MoveToEx(hdc,0,cyClient/2,NULL);
	//LineTo(hdc,cxClient,cyClient/2);
	dc.MoveToEx(0,cyClient/2,NULL);
	dc.LineTo(cxClient,cyClient/2);
	for(i=1;i<NUM;i++)
	{
		pt[i].x = i * cxClient / NUM;
		pt[i].y = (int)(cyClient/2 * (1-sin((TWOPI*i)/NUM)));
	}
	//Polyline(hdc,pt,NUM);
	dc.Polyline(pt,NUM);
	//ReleaseDC(hwnd,hdc);
	//}}SCHEO
	return 0L;
}

//{{SCHEO
LRESULT CView::OnSize(WPARAM wParma,LPARAM lParam)
{
//#define LOWORD(a) ( (a) & 0x0000ffff)
//#define HIWORD(a) ( ((a) & 0xffff0000) >> 16)
	cxClient = LOWORD(lParam);
	cyClient = HIWORD(lParam);
		
	return 0L;
}
//}}SCHE

소스 다운로드

Category: C++