|
Программирование >> Программирование на языке c++
protected: TDC *DragDC; TPoint tp[5]; TOpenSaveDialog::TData *FileData; BOOL IsFig, IsNew, Stop; int Rect, El, Pol, i; BOOL CanCloseO; void CmClearO; функции отклика для первого void CmDrawRectO; раздела меню void CmDrawCircO; void CmDrawPolygon{); void CmNew(); функции отклика void CmOpenO; для второго раздела меню void CmSaveO; void CmSave as(); void SaveFile{); дополнительные функции void OpenFileQ; DECLARE RESPONSE TABLE(TMyWindow); }; DEFINE RESP0NSE TABLE1(TMyWindow, TWindow) EV COMMAND(CM CLEAR, CmClear), EV COMMAND{CM RECT, CmDrawRect), EV COMMAND(CM CIRCLE, CmDrawCirc), EV COMMAND(CM POLYGON, CmDrawPolygon), EV COMMAND(CM NEW, CmNew), EV COMMAND(CM OPEN, CmOpen), EV COMMAND(CM SAVE, CmSave), EV COMMAND(CM SAVE AS, CmSave as), END RESPONSE TABLE; TMyWindow::TMyWindow(TWindow *parent) { lnit(parent, 0, 0); Drag DC = 0; i= 0; Stop = FALSE; IsNew = TRUE; IsFig = FALSE; Rect = 0; El = 0; Pol = 0; FileData = newTOpenSaveDialog ::TData(OFN HIDEREADONLYOFN FILEMUSTEXIST, V.Sklyarov: (*.SKL)*.skl , 0, , SKL ); } BOOL TMyWindow::CanClose() { if (IsFig) switch(MessageBox{ Do you want to save? , Drawing has been changed , MB YESNOCANCEL MBJCONQUESTION)) { case IDCANCEL:return FALSE; case IDYES: CmSave(); } return TRUE;} void TMyWindow::CmClear{) { InvalidateO; i = 0; Rect = 0; El = 0; Pol = 0; } void TMyWindow::CmDrawRect{) { DragDC = new TClientDC(*this); DragDC -> FillRect(150,150,250,250,TBrush(TColor::LtRed)); delete DragDC; if (IStop) { Rect = +-H; IsFig = TRUE; } } void TMyWindow::CmDrawCirc{) { DragDC = new TClientDC(*this); DragDC -> Ellipse(100,100,200,200); delete DragDC; if (IStop) { El = +-H; IsFig = TRUE; } } void TMyWindow::CmDrawPolygon() { DragDC = new TCIientDC(*this); tp[0].x = 200; задание координат для многоугольника tp[0].y = 150; tp[1].x = 300; tp[1].y = 180; tp[2].x = 300; tp[2].y = 220; tp[3].x = 200; tp[3].y = 250; tp[4].x = 150; tp[4].y = 200; DragDC -> Polygon(tp,5); delete DragDC; if (IStop) { Pol = ++i; IsFig = TRUE; } } void TMyWindow::CmNew() { if (CanCloseO) { InvalidateO; i = 0; IsFig = FALSE; Rect = 0; El = 0; Pol = 0; IsNew = TRUE; } } void TMyWindow::CmOpen() { if (CanCloseQ) if {(TFileOpenDialog(this, *FileData)).Execute() == IDOK) OpenFileO; } void TMyWindow::CmSave() { if (IsNew) CmSave as(); else SaveFileQ; } void TMyWindow::SaveFile() { ofstream os(FileData->FileName); if (los) MessageBox( Unable to open file , File Error , MB OK MBJCONEXCLAMATION); else OS Rect endl El endl Pol endl i endl; IsNew = IsFig = FALSE; } void TMyWindow::OpenFile() { ifstream is{FileData->FileName); if (lis) MessageBox( Unable to open file , File Error , MB OK MBJCONEXCLAMATION); else is Rect El Pol i; Stop = TRUE; for(int j = 1; j<=i; j++) if (Rect == j) CmDrawRectO; else if (El == j) CmDrawCircO; else if (Pol == j) CmDrawPolygonO; Stop = FALSE; IsNew = IsFig = FALSE; } void TMyWindow::CmSave asO { if (IsNew) strcpy(FileData -> FileName, ); if ((TFileSaveDialog(this,*FileData)).ExecuteO == IDOK) SaveFileO; } class TMyApp : public TApplication {
|
© 2006 - 2024 pmbk.ru. Генерация страницы: 0
При копировании материалов приветствуются ссылки. |