diff options
-rw-r--r-- | src/main.cpp | 9 | ||||
-rw-r--r-- | src/ui/window.cpp | 14 | ||||
-rw-r--r-- | src/ui/window.hpp | 1 |
3 files changed, 21 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index 264b3c7c..359b511b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,8 @@ int APIENTRY wWinMain( //test 2 + Window child_window(&window); + const auto layout = CreateWithLayout<LinearLayout>(LayoutSideParams::Exactly(500), LayoutSideParams::Content()); layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args) @@ -114,7 +116,11 @@ int APIENTRY wWinMain( { const auto button = Button::Create(); button->GetLayoutParams()->padding = Thickness(20, 5); - button->AddChild(TextBlock::Create(L"button")); + button->AddChild(TextBlock::Create(L"Show child window.")); + button->mouse_click_event.AddHandler([&child_window](auto) + { + child_window.Show(); + }); layout->AddChild(button); } @@ -170,6 +176,7 @@ int APIENTRY wWinMain( window.AddChild(linear_layout); */ + window.Show(); return application.Run(); diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 349b78ff..f7506f18 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -113,13 +113,23 @@ namespace cru::ui } } - Window::Window() : Control(WindowConstructorTag{}, this), control_list_({ this }) { + Window::Window() : Window(nullptr) + { + + } + + Window::Window(Window* parent) : Control(WindowConstructorTag{}, this), control_list_({ this }) { + + if (parent != nullptr && !parent->IsWindowValid()) + throw std::runtime_error("Parent window is not valid."); + const auto window_manager = WindowManager::GetInstance(); hwnd_ = CreateWindowEx(0, window_manager->GetGeneralWindowClass()->GetName(), L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - nullptr, nullptr, Application::GetInstance()->GetInstanceHandle(), nullptr + parent == nullptr ? nullptr : parent->GetWindowHandle(), + nullptr, Application::GetInstance()->GetInstanceHandle(), nullptr ); if (hwnd_ == nullptr) diff --git a/src/ui/window.hpp b/src/ui/window.hpp index d3e86f2d..82cbfc4f 100644 --- a/src/ui/window.hpp +++ b/src/ui/window.hpp @@ -90,6 +90,7 @@ namespace cru::ui static constexpr auto control_type = L"Window"; Window(); + explicit Window(Window* parent); Window(const Window& other) = delete; Window(Window&& other) = delete; Window& operator=(const Window& other) = delete; |