C++面向对象简易图形编辑器(6)

2018-12-23 23:24

面向对象编程技术实验报告

GetStockObject(SaveEllipse[j].brushColor)); break; case IDM_BRUSH_COLORSOLID: case IDM_BRUSH_CROSS: hOldBrush = (HBRUSH)SelectObject (hdc, SaveEllipse[j].hNewBrush); break; } Ellipse (hdc, SaveEllipse[j].ptS.x,SaveEllipse[j].ptS.y, SaveEllipse[j].ptE.x, SaveEllipse[j].ptE.y); SelectObject(hdc, hPenOld); DeleteObject(hPen); SelectObject(hdc, hOldBrush); } }

void ChooseFont(HWND hwnd) { static LOGFONT logfont; static CHOOSEFONT cf; static HFONT hFont; GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT), (PTSTR) &logfont); //初始化结构 logfont cf.lStructSize = sizeof (CHOOSEFONT); cf.hwndOwner = hwnd; cf.hDC = NULL; cf.lpLogFont = &logfont; cf.iPointSize = 0; cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS; cf.rgbColors = 0; cf.lCustData = 0; cf.lpfnHook = NULL; cf.lpTemplateName = NULL; cf.hInstance = NULL; cf.lpszStyle = NULL; cf.nFontType = 0; cf.nSizeMin = 0; cf.nSizeMax = 0; if (ChooseFont (&cf)) { if (SaveText[q].hFont) DeleteObject (SaveText[q].hFont); SaveText[q].hFont = CreateFontIndirect (&logfont);

24

面向对象编程技术实验报告

InvalidateRect (hwnd, NULL, TRUE); } }

void ChooseColor(HWND hwnd) { static CHOOSECOLOR cc; static COLORREF crCustomColors[16]; static COLORREF crText = RGB (0, 0, 0); //初始化结构 cc cc.lStructSize = sizeof (CHOOSECOLOR); cc.hwndOwner = hwnd; cc.hInstance = NULL; cc.rgbResult = RGB (0, 0, 0); cc.lpCustColors = crCustomColors; cc.Flags = CC_RGBINIT | CC_FULLOPEN; cc.lCustData = 0; cc.lpfnHook = NULL; cc.lpTemplateName = NULL; if (ChooseColor (&cc)) { SaveText[q].crText = crCustomColors[0]; InvalidateRect (hwnd, NULL, TRUE); } }

void DrawMyText(HDC hdc) { int j; for(j=0;j

25

面向对象编程技术实验报告

} }

void SaveMyData(struct MySaveLine* SaveLine,int LineCount,struct MySaveRectangle* SaveRectangle,int RectangleCount,struct MySaveEllipse* SaveEllipse,int EllipseCount,struct MySaveText* SaveText,int TextCount) { static HANDLE hFile; hFile = CreateFile (\

NULL, CREATE_ALWAYS, 0, NULL); if(hFile!=INVALID_HANDLE_VALUE) { DWORD dwByte1=0; DWORD dwByte2=0; DWORD dwByte3=0; DWORD dwByte4=0; WriteFile (hFile, &LineCount, sizeof(int), &dwByte1, NULL); WriteFile (hFile, &RectangleCount, sizeof(int), &dwByte2, NULL); WriteFile (hFile, &EllipseCount, sizeof(int), &dwByte3, NULL); WriteFile (hFile, &TextCount, sizeof(int), &dwByte4, NULL); WriteFile (hFile, SaveLine, LineCount*sizeof(MySaveLine), &dwByte1, NULL); WriteFile (hFile, SaveRectangle, RectangleCount*sizeof(MySaveRectangle), &dwByte2, NULL); WriteFile (hFile, SaveEllipse, EllipseCount*sizeof(MySaveEllipse), &dwByte3, NULL); WriteFile (hFile, SaveText, TextCount*sizeof(MySaveText), &dwByte4, NULL); CloseHandle(hFile); } }

void LoadMyData(struct MySaveLine* SaveLine,int LineCount,struct MySaveRectangle* SaveRectangle,int RectangleCount,struct MySaveEllipse* SaveEllipse,int EllipseCount,struct MySaveText* SaveText,int TextCount) {

26

面向对象编程技术实验报告

static HANDLE hFile; hFile = CreateFile (\ NULL,OPEN_EXISTING, 0, NULL); if(hFile!=INVALID_HANDLE_VALUE) { DWORD dwByte1=0; DWORD dwByte2=0; DWORD dwByte3=0; DWORD dwByte4=0; ReadFile (hFile, &LineCount, sizeof(int), &dwByte1, NULL); ReadFile (hFile, &RectangleCount, sizeof(int), &dwByte2, NULL); ReadFile (hFile, &EllipseCount, sizeof(int), &dwByte3, NULL); ReadFile (hFile, &TextCount, sizeof(int), &dwByte4, NULL); ReadFile (hFile, SaveLine, LineCount*sizeof( MySaveLine), &dwByte1, NULL); ReadFile (hFile, SaveRectangle, RectangleCount*sizeof( MySaveRectangle), &dwByte2, NULL); ReadFile (hFile, SaveEllipse, EllipseCount*sizeof(MySaveEllipse), &dwByte3, NULL); ReadFile (hFile, SaveText, TextCount*sizeof(MySaveText), &dwByte4, NULL); CloseHandle(hFile); } }

BOOL CALLBACK InputDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)//返回用户输入的文本 {

switch (message) {

case WM_COMMAND:

switch (LOWORD (wParam)) {

case IDOK:

GetDlgItemText(hDlg, IDC_EDIT1, SaveText[q].g_EditInput,1024);

27

面向对象编程技术实验报告

EndDialog (hDlg, TRUE); return TRUE;

case IDCANCEL:

EndDialog (hDlg, FALSE); return TRUE; }

break; }

return FALSE; };//结束 InputDlgProc

三、头文件

/******************************************************************* 程序:draw 文件:draw.h 功能:头文件

********************************************************************/ #ifndef _DRAW_H_ #define _DRAW_H_ #include #include #include \

#define MAX 100

/*static TCHAR szAppName[] = TEXT (\ int lineCount=0;

int rectangleCount=0; int ellipseCount=0; int textCount=0;

HACCEL hAccel; HDC hdc;

static int i=0,m=0,n=0,p=0,q=0;*/

struct MySaveLine // 直线保存 { POINT ptS; POINT ptE; COLORREF color;

28


C++面向对象简易图形编辑器(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:计算机基础

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: