diff --git a/Tutorial/GacUI_Controls/TextEditor/Main.cpp b/Tutorial/GacUI_Controls/TextEditor/Main.cpp index 49da4924..299c998f 100644 --- a/Tutorial/GacUI_Controls/TextEditor/Main.cpp +++ b/Tutorial/GacUI_Controls/TextEditor/Main.cpp @@ -4,6 +4,8 @@ using namespace vl::collections; using namespace vl::stream; +#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow) { return SetupWindowsDirect2DRenderer(); diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml b/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml index fff4ae40..38a94562 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml @@ -16,7 +16,7 @@ - + diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Source/DemoPartialClasses.cpp b/Tutorial/GacUI_Controls/TextEditor/UI/Source/DemoPartialClasses.cpp index a7f0a8a0..6ac617e2 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Source/DemoPartialClasses.cpp +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Source/DemoPartialClasses.cpp @@ -40,6 +40,7 @@ namespace vl CLASS_MEMBER_GUIEVENT_HANDLER(commandFileOpen_Executed, vl::presentation::compositions::GuiEventArgs) CLASS_MEMBER_GUIEVENT_HANDLER(commandFileSaveAs_Executed, vl::presentation::compositions::GuiEventArgs) CLASS_MEMBER_GUIEVENT_HANDLER(commandFileSave_Executed, vl::presentation::compositions::GuiEventArgs) + CLASS_MEMBER_GUIEVENT_HANDLER(window_Closing, vl::presentation::compositions::GuiRequestEventArgs) END_CLASS_MEMBER(demo::MainWindow) #undef _ diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp index a392ce08..bc6fca0a 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp @@ -131,10 +131,7 @@ namespace demo void MainWindow::commandFileExit_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments) { - if (CanCloseFile()) - { - Close(); - } + Close(); } void MainWindow::commandFileNewText_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments) @@ -182,14 +179,34 @@ namespace demo SaveFile(false); } + void MainWindow::window_Closing(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiRequestEventArgs& arguments) + { + arguments.cancel = !CanCloseFile(); + } + // #endregion CLASS_MEMBER_GUIEVENT_HANDLER bool MainWindow::CanCloseFile() { - return true; + if (textBox->GetModified()) + { + switch (dialogQueryClose->ShowDialog()) + { + case INativeDialogService::MessageBoxButtonsOutput::SelectYes: + return SaveFile(false); + case INativeDialogService::MessageBoxButtonsOutput::SelectNo: + return true; + default: + return false; + } + } + else + { + return true; + } } - void MainWindow::OpenFile(vint filterIndex) + bool MainWindow::OpenFile(vint filterIndex) { if (CanCloseFile()) { @@ -216,6 +233,7 @@ namespace demo { SetupTextConfig(); } + return true; } else { @@ -223,9 +241,10 @@ namespace demo } } } + return false; } - void MainWindow::SaveFile(bool saveAs) + bool MainWindow::SaveFile(bool saveAs) { WString targetFileName = fileName; if (saveAs || targetFileName == L"") @@ -237,7 +256,7 @@ namespace demo } else { - return; + return false; } } @@ -259,11 +278,13 @@ namespace demo { SetupTextConfig(); } + return true; } else { dialogCannotSave->ShowDialog(); } + return false; } void MainWindow::SetupTextConfig() diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h index 00f4e5a0..e3d84c83 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h @@ -37,6 +37,7 @@ namespace demo void commandFileOpen_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments); void commandFileSaveAs_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments); void commandFileSave_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments); + void window_Closing(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiRequestEventArgs& arguments); // #endregion CLASS_MEMBER_GUIEVENT_HANDLER private: @@ -44,8 +45,8 @@ namespace demo bool isXml = false; bool CanCloseFile(); - void OpenFile(vint filterIndex); - void SaveFile(bool saveAs); + bool OpenFile(vint filterIndex); + bool SaveFile(bool saveAs); void SetupTextConfig(); void SetupXmlConfig(); public: diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/a.txt b/Tutorial/GacUI_Controls/TextEditor/UI/a.txt deleted file mode 100644 index a4f4c2db..00000000 Binary files a/Tutorial/GacUI_Controls/TextEditor/UI/a.txt and /dev/null differ diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/a.xml b/Tutorial/GacUI_Controls/TextEditor/UI/a.xml deleted file mode 100644 index a4f4c2db..00000000 Binary files a/Tutorial/GacUI_Controls/TextEditor/UI/a.xml and /dev/null differ diff --git a/Tutorial/GacUI_Controls/UIRes/TextEditor.bin b/Tutorial/GacUI_Controls/UIRes/TextEditor.bin index 34fb05f2..348c68cb 100644 Binary files a/Tutorial/GacUI_Controls/UIRes/TextEditor.bin and b/Tutorial/GacUI_Controls/UIRes/TextEditor.bin differ