//---------------------------------------------------------------------------- // ObjectWindows - (C) Copyright 1991, 1994 by Borland International // Tutorial application -- step12.cpp //---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include "step12.rc" class TDrawApp : public TApplication { public: TDrawApp() : TApplication() {} protected: // Override methods of TApplication void InitInstance(); void InitMainWindow(); // Event handlers void EvNewView (TView& view); void EvCloseView(TView& view); void EvDropFiles(TDropInfo dropInfo); void CmAbout(); DECLARE_RESPONSE_TABLE(TDrawApp); }; DEFINE_RESPONSE_TABLE1(TDrawApp, TApplication) EV_OWLVIEW(dnCreate, EvNewView), EV_OWLVIEW(dnClose, EvCloseView), EV_WM_DROPFILES, EV_COMMAND(CM_ABOUT, CmAbout), END_RESPONSE_TABLE; void TDrawApp::InitMainWindow() { // Construct the decorated frame window TDecoratedFrame* frame = new TDecoratedFrame(0, "Drawing Pad", 0, true); // Construct a status bar TStatusBar* sb = new TStatusBar(frame, TGadget::Recessed); // Construct a control bar TControlBar* cb = new TControlBar(frame); cb->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW, TButtonGadget::Command)); cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN, TButtonGadget::Command)); cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE, TButtonGadget::Command)); cb->Insert(*new TButtonGadget(CM_FILESAVEAS, CM_FILESAVEAS, TButtonGadget::Command)); cb->Insert(*new TSeparatorGadget); cb->Insert(*new TButtonGadget(CM_PENSIZE, CM_PENSIZE, TButtonGadget::Command)); cb->Insert(*new TButtonGadget(CM_PENCOLOR, CM_PENCOLOR, TButtonGadget::Command)); cb->Insert(*new TSeparatorGadget); cb->Insert(*new TButtonGadget(CM_ABOUT, CM_ABOUT, TButtonGadget::Command)); // Insert the status bar and control bar into the frame frame->Insert(*sb, TDecoratedFrame::Bottom); frame->Insert(*cb, TDecoratedFrame::Top); // Set the main window and its menu SetMainWindow(frame); GetMainWindow()->SetMenuDescr(TMenuDescr("COMMANDS",1,0,0,0,0,1)); // Install the document manager SetDocManager(new TDocManager(dmSDI | dmMenu)); } void TDrawApp::InitInstance() { TApplication::InitInstance(); GetMainWindow()->DragAcceptFiles(true); GetDocManager()->CmFileNew(); } void TDrawApp::EvDropFiles(TDropInfo dropInfo) { if (dropInfo.DragQueryFileCount() != 1) ::MessageBox(0, "Can only drop 1 file in SDI mode", "Drag/Drop Error", MB_OK); else { int fileLength = dropInfo.DragQueryFileNameLen(0)+1; char* filePath = new char [fileLength]; dropInfo.DragQueryFile(0, filePath, fileLength); TDocTemplate* tpl = GetDocManager()->MatchTemplate(filePath); if (tpl) tpl->CreateDoc(filePath); delete filePath; } dropInfo.DragFinish(); } void TDrawApp::EvNewView(TView& view) { GetMainWindow()->SetClientWindow(view.GetWindow()); if (!view.IsOK()) GetMainWindow()->SetClientWindow(0); else if (view.GetViewMenu()) GetMainWindow()->MergeMenu(*view.GetViewMenu()); } void TDrawApp::EvCloseView(TView& /*view*/) { GetMainWindow()->SetClientWindow(0); GetMainWindow()->RestoreMenu(); GetMainWindow()->SetCaption("Drawing Pad"); } void TDrawApp::CmAbout() { TDialog(GetMainWindow(), IDD_ABOUT).Execute(); } int OwlMain(int /*argc*/, char* /*argv*/ []) { return TDrawApp().Run(); }