面向对象编程技术实验报告
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 #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