pnengl建立项目的步骤: 7892、在 visual c中的建立控制台项目的步骤: 101112 实验三 二维图元的填充一、实验学时 2 学时二、实验类型 设计型实验三、实验目的和要求 1、掌握二维图元填充的递归算法; 2、掌握二维图元填充的种子填充算法四、实验内容 构造任意一个边界表示的多边形,假定该多边形内部是四连通的。
要求: (参 1、用递归算法实现对多边形内部的填充,要求内部颜色和边界不一致。
照教案进行) 2、用种子填充扫描线算法实现多边形内部的填充。
五、建立 win32 应用程序工程。
1、visual c 6.0 下的界面接下来,请按实验二中的方法给上面建立的空项目添加文件“recursion.cpp”,由于同学们初次接触 WIN32 编程,所以对于下文中很多代码可暂时不要求理解,重点了解红色代码。
递归算法源码如下: 13// INCLUDES ///////////////////////////////////////////////define WIN32_LEAN_AND_MEAN // just say no to MFCinclude // include all the windows headersinclude // include useful macros// DEFINES ////////////////////////////////////////////////// defines for windowsdefine WINDOW_CLASS_NAME WINCLASS1define WINDOW_WIDTH 400define WINDOW_HEIGHT 300// GLOBALS ////////////////////////////////////////////////HWND main_window_handle NULL // globally track main windowHINSTANCE hinstance_app NULL // globally track hinstancevoid BoundaryFill4HDCintintCOLORREFCOLORREF// FUNCTIONS //////////////////////////////////////////////LRESULT CALLBACK WindowProcHWND hwnd UINT message WPARAM wParam LPARAM lParam// this is the main message handler of the systemHDC hdc// handle to a device contextHPEN hnewpenHPEN holdpen 14// what is the messageswitchmessage case WM_RBUTTONDOWN: hdcGetDChwnd hnewpenCreatePenPS_SOLID1RGB02550 holdpenHPENSelectObjecthdchnewpen // 构造多边形 MoveToExhdc3040NULL LineTohdc6040 LineTohdc90100 LineTohdc60150 LineTohdc30150 LineTohdc3040 SelectObjecthdcholdpen DeleteObjecthnewpen ReleaseDChwndhdc return0 break case WM_LBUTTONDOWN: hdc GetDChwnd BoundaryFill4hdcLOWORDlParamHIWORDlParamRGB02550RGB25500 // release the dc ReleaseDChwndhdc return0 break case WM_DESTROY: 15 // kill the application this sends a WM_QUIT message PostQuitMessage0 // return success return0 break default:break // end switch// process any messages that we didnt take care ofreturn DefWindowProchwnd message wParam lParam // end WinProc// WINMAIN ////////////////////////////////////////////////int WINAPI WinMain HINSTANCE hinstance HINSTANCE hprevinstance LPSTR lpcmdline int ncmdshowWNDCLASSEX winclass // this will hold the class we createHWND hwnd // generic window handleMSG message // generic message// first fill in the window class stucturewinclass.cbSize sizeofWNDCLASSEXwinclass.style CS_DBLCLKS CS_OWNDC CS_HREDRAW CS_VREDRAWwinclass.lpfnWndProc WindowProcwinclass.cbClsExtra 0winclass.cbWndExtra 0 16winclass.hInstance hinstancewinclass.hIcon LoadIconNULL IDI_APPLICATIONwinclass.hCursor LoadCursorNULL IDC_ARROWwinclass.hbrBackground HBRUSHGetStockObjectWHITE_BRUSHwinclass.lpszMenuName NULLwinclass.lpszClassName WINDOW_CLASS_NAMEwinclass.hIconSm LoadIconNULL IDI_APPLICATION// save hinstance in globalhinstance_app hinstance// register the window classif RegisterClassExwinclass return0// create the windowif hwnd CreateWindowExNULL // extended style WINDOW_CLASS_NAME // class Scanline Fill Demo // title WS_OVERLAPPEDWINDOW WS_VISIBLE 00 // initial xy WINDOW_WIDTH // initial width WINDOW_HEIGHT// initial height NULL // handle to parent NULL // handle to menu hinstance// instance of this application NULL // extra creation parmsreturn0// save main window handlemain_window_handle hwnd 17whileGetMessagemessageNULL00 // translate any accelerator keys TranslateMessagemessage // send the message to the window proc DispatchMessagemessage // end while// return to Windows like thisreturnmessage.wParam // end WinMain///////////////////////////////////////////////////////////void BoundaryFill4HDC hdcint xint yCOLORREF boundarycolorCOLORREFnewcolor COLORREF color colorGetPixelhdcxy ifcolor boundarycolor color newcolor SetPixelhdcxynewcolor BoundaryFill4hdcxy1boundarycolornewcolor BoundaryFill4hdcxy-1boundarycolornewcolor BoundaryFill4hdcx-1yboundarycolornewcolor BoundaryFill4hdcx1yboundarycolornewcolor 2、vc.net 中建立 Win32 工程 18更改项目中 recursion.cpp 文件代码:1)声明函数void BoundaryFill4HDCintintCOLORREFCOLORREF2)修改 LRESULT CALLBACK WndProcHWND hWnd UINT message WPARAM wParamLPARAM lParam函数中代码,把 visualc6.0 介绍的 recursion.cpp 中的WndProc 函数体复制即可。
3)在 recursion.cpp 文件末尾添加 BoundaryFill4 函数。
19
上一篇:
毕业设计(论文)
下一篇:
高等数学课程复习资料(word论文|下载论文)