#include "windows.h"
#include "resource.h"
#include "draw.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpcmdLine,int nCmdShow)
{
static TCHAR szAppName[]=TEXT("计算机图形学");
static TCHAR szClassName[]=TEXT("计算机图形学");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
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(GRAY_BRUSH);
wndclass.lpszMenuName="IDR_MENU";
wndclass.lpszClassName=szClassName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("ERROR"),TEXT("ERROR"),MB_ICONSTOP);
return 0;
}
hwnd =CreateWindow(szAppName,szClassName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
static POINT apt[4];
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
if (DrawMode==DRAWNULL)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode== DRAWDDALINE)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
SetColor(RGB(255,0,0),hdc);
DDALine(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode== DRAWBRESENHAMLINE)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
SetColor(RGB(255,0,0),hdc);
BresenhamLine(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWBEZIER)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
SetColor(RGB(255,0,0),hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWCIRCEL)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
DDACircel(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWCIRCELNEW)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
BresenhamCircle(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWSEED)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
Seed_Fill_Draw(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWHERMIT)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
HermitCurve(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWCARDINAL)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
CardinalCurve(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWSCANLINE)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
Scanline_seed_fill_draw(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWB)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
B_spline(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAW2DTURN)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
SetColor(RGB(255,0,0),hdc);
TextOut(hdc,10,10,TEXT("正常直线"),8);
DDALine(hdc);
TextOut(hdc,87,204,TEXT("移位"),4);
DDALineMove(hdc);
TextOut(hdc,400,300,TEXT("缩放加旋转"),10);
DDALineRotate(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (DrawMode==DRAWSELFBEZIER)
{
DoInvalidate(hwnd,TRUE);
hdc=BeginPaint(hwnd,&ps);
SelfBezier(hdc);
EndPaint(hwnd,&ps);
return 0;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MOUSEMOVE:
if (DrawMode==DRAWBEZIER)
{
if(wParam & MK_LBUTTON || wParam & MK_RBUTTON)
{
hdc = GetDC(hwnd);
SetColor(RGB(128,128,128),hdc);
DrawBezier(hdc, apt);
if(wParam & MK_LBUTTON)
{
apt[1].x = LOWORD(lParam);
apt[1].y = HIWORD(lParam);
}
if(wParam & MK_RBUTTON)
{
apt[2].x = LOWORD(lParam);
apt[2].y = HIWORD(lParam);
}
SetColor(RGB(255,0,0),hdc);
DrawBezier(hdc, apt);
ReleaseDC(hwnd, hdc);
}
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_SYSTEM_AUTHOR:
MessageBox(hwnd,Authorname,TEXT("Authors"),64);
return 0;
case ID_LINE_DDA:
DrawMode=DRAWDDALINE;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_LINE_BRESENHAM:
DrawMode=DRAWBRESENHAMLINE;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_FILL_SEED:
DrawMode=DRAWSEED;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_FILL_SCANLINE:
DrawMode=DRAWSCANLINE;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CIRCEL_DDA:
DrawMode=DRAWCIRCEL;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CIRCEL_OTHER:
DrawMode=DRAWCIRCELNEW;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_DRAW_NULL:
DrawMode=DRAWNULL;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CURVE_CARDINAL:
DrawMode=DRAWCARDINAL;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CURVE_HERMIT:
DrawMode=DRAWHERMIT;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CURVE_BEZIER:
DrawMode=DRAWBEZIER;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CURVE_B:
DrawMode=DRAWB;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_DRAW_2DTURN:
DrawMode=DRAW2DTURN;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
case ID_CURVE_SELFBEZIER:
DrawMode=DRAWSELFBEZIER;
PostMessage(hwnd,WM_PAINT,wParam,lParam);
return 0;
}
}
return DefWindowProc(hwnd,message,wParam,lParam);
}