diff --git a/Demo/ControlsDemoWindow.cpp b/Demo/ControlsDemoWindow.cpp index 51c63d3..868742d 100644 --- a/Demo/ControlsDemoWindow.cpp +++ b/Demo/ControlsDemoWindow.cpp @@ -6,8 +6,32 @@ ControlsDemoWindow::ControlsDemoWindow() void ControlsDemoWindow::ButtonClick() { std::wstring res = textBox->GetText(); + /*textBox->EnableHorizontalScrollbar(!textBox->HorizontalScrollbarEnabled()); + textBox->EnableVerticalScrollbar(!textBox->VerticalScrollbarEnabled());*/ MessageBox(NULL, res.c_str(), L"TextBox text is", MB_OK); } +void ControlsDemoWindow::ContextMenuOpen() +{ + ContextMenu* menu = new ContextMenu(); + Menu* test = new Menu(L"Test"); + Menu* test2 = new Menu(L"Test2"); + menu->Add(test); + menu->Add(new Separator()); + menu->Add(test2); + menu->Add(new Separator()); + menu->Add(test); + menu->Add(new Separator()); + menu->Add(test2); + menu->Add(new Separator()); + menu->Add(test); + menu->Add(new Separator()); + menu->Add(test2); + menu->Add(new Separator()); + menu->Add(test); + menu->Add(new Separator()); + menu->Add(test2); + menu->Open(); +} void ControlsDemoWindow::RadioGroupChanged() { int index = group->CurrentRadioButton(); diff --git a/Demo/ControlsDemoWindow.h b/Demo/ControlsDemoWindow.h index d548ef0..6240cef 100644 --- a/Demo/ControlsDemoWindow.h +++ b/Demo/ControlsDemoWindow.h @@ -12,33 +12,37 @@ class ControlsDemoWindow : public Window TextBox* textBox; void RadioGroupChanged(); void ButtonClick(); + void ContextMenuOpen(); void InitializeComponent() { + this->Create(L"MUI Controls Demo", (DWORD)IDI_ICON1); textBox = new TextBox(L"Test-TextBox", FALSE, 0, 0, 100, 100); /* * Add vertical scroll bar. - * If before window creation it shows correctly, if after, only scroll wheel works(could be a bug ? ) + * If before adding to window it shows correctly, if after, only scroll wheel works(could be a bug ? ) */ textBox->SetStyle(textBox->GetStyle() | WS_VSCROLL); - Button* button = new Button(L"Input-Box text",FALSE, 0, 100, 100, 20); - radioBlock = new TextBlock(L"Radio Index: -1", 120, 50, 100, 15); - group = new RadioGroup(L"Window Mode", 120, 70, 209, 85); + Button* button = new Button(L"Input-Box text", FALSE, 0, 100, 100, 20); + Button* button4 = new Button(L"Open contextmenu", FALSE, 0, 200, 200, 20); RadioButton* button1 = new RadioButton(L"Fullscreen", 130, 90, 90, 15); RadioButton* button2 = new RadioButton(L"Windowed Fullscreen", 130, 110, 140, 15); RadioButton* button3 = new RadioButton(L"Windowed", 130, 130, 140, 15); - group->AddRadioButton(button1); - group->AddRadioButton(button2); - group->AddRadioButton(button3); - button->OnClick = std::bind(&ControlsDemoWindow::ButtonClick, this); - group->OnChange = std::bind(&ControlsDemoWindow::RadioGroupChanged, this); - this->Create(L"MUI Controls Demo", (DWORD)IDI_ICON1); + radioBlock = new TextBlock(L"Radio Index: -1", 120, 50, 100, 15); + group = new RadioGroup(L"Window Mode", 120, 70, 209, 85); this->AddComponent(button1); this->AddComponent(button2); this->AddComponent(button3); this->AddComponent(button); + this->AddComponent(button4); this->AddComponent(textBox); this->AddComponent(group); this->AddComponent(radioBlock); + group->AddRadioButton(button1); + group->AddRadioButton(button2); + group->AddRadioButton(button3); + button->OnClick = std::bind(&ControlsDemoWindow::ButtonClick, this); + group->OnChange = std::bind(&ControlsDemoWindow::RadioGroupChanged, this); + button4->OnClick = std::bind(&ControlsDemoWindow::ContextMenuOpen, this); } }; diff --git a/Demo/GridDemoWindow.cpp b/Demo/GridDemoWindow.cpp index c71bad8..d77c23c 100644 --- a/Demo/GridDemoWindow.cpp +++ b/Demo/GridDemoWindow.cpp @@ -7,16 +7,14 @@ void GridDemoWindow::WindowClose() { OutputDebugString(L"Window is closed!\n"); } -void GridDemoWindow::CheckBoxClick(UIComponent* sender,EventArgs_t e) +void GridDemoWindow::CheckBoxClick() { if (checkBox->IsChecked()) { - //button.SetStyle(button.GetStyle() | BS_OWNERDRAW); textBlock->SetText(L"Checked"); listView->Show(); } else { - //button.SetStyle(button.GetStyle() & ~BS_OWNERDRAW); textBlock->SetText(L"UnChecked"); listView->Hide(); } diff --git a/Demo/GridDemoWindow.h b/Demo/GridDemoWindow.h index 3b43c46..1df34af 100644 --- a/Demo/GridDemoWindow.h +++ b/Demo/GridDemoWindow.h @@ -10,45 +10,45 @@ class GridDemoWindow : public Window CheckBox* checkBox; TextBlock* textBlock; ListView* listView; - void WindowClose(/*UIComponent* sender, EventArgs_t e*/); - void CheckBoxClick(UIComponent* sender,EventArgs_t e); + void WindowClose(); + void CheckBoxClick(); void InitializeComponent() { - Grid* grid = new Grid(); + this->Create(L"MUI Grid Demo", (DWORD)IDI_ICON1); + this->OnClose = std::bind(&GridDemoWindow::WindowClose, this); this->SetBackroundColor(MUI::Color::PURPLE); this->m_StaticBacgkround = MUI::Color::PURPLE; this->m_StaticTextColor = MUI::Color::LIGHT_PURPLE; this->m_EditBacgkround = MUI::Color::LIGHT_PURPLE; this->m_ButtonBacgkround = MUI::Color::WHITE; this->m_ButtonTextColor = MUI::Color::DARK_PURPLE; - grid->AddColumn(0, L"Auto"); - grid->AddColumn(0, L"*"); - grid->AddColumn(0, L"Auto"); + Grid* grid = new Grid(); checkBox = new CheckBox(L"CheckBox", 100, 300, 70, 15); checkBox->SetVerticalAligment(Center); - checkBox->OnClick = std::bind(&GridDemoWindow::CheckBoxClick, this, std::placeholders::_1, std::placeholders::_2); + checkBox->OnClick = std::bind(&GridDemoWindow::CheckBoxClick, this); listView = new ListView(10, 10, 200, 200); listView->SetHorizontalAligment(Stretch); listView->SetVerticalAligment(Stretch); textBlock = new TextBlock(L"", 180, 0, 70, 15); textBlock->SetVerticalAligment(Center); textBlock->SetText(L"Checked"); + grid->AddColumn(0, L"Auto"); + grid->AddColumn(0, L"*"); + grid->AddColumn(0, L"Auto"); grid->AddItem(listView, 0, 1); grid->AddItem(checkBox, 0, 2); grid->AddItem(textBlock, 0, 0); - this->OnClose = std::bind(&GridDemoWindow::WindowClose, this); - this->Create(L"MUI Grid Demo", (DWORD)IDI_ICON1); this->SetGrid(grid); listView->Clear(); HICON ico = LoadIcon(this->GetHINSTACE(), MAKEINTRESOURCE(IDI_ICON1)); listView->AddIcon(ico); listView->AddColumn(L"Test", 100); listView->AddColumn(L"Test2", 100); - ListItem itm(0, std::vector {L"TEST1", L"TEST2"}); - listView->AddItem(&itm); - ListItem itm2(0, std::vector {L"TEST3", L"TEST4"}); - listView->AddItem(&itm2); - checkBox->SetChecked(1); + ListItem* itm = new ListItem(0, std::vector {L"TEST1", L"TEST2"}); + listView->AddItem(itm); + ListItem* itm2 = new ListItem(0, std::vector {L"TEST3", L"TEST4"}); + listView->AddItem(itm2); + checkBox->SetChecked(1); } }; diff --git a/Demo/MainWindow.cpp b/Demo/MainWindow.cpp index 2da7386..2d005d0 100644 --- a/Demo/MainWindow.cpp +++ b/Demo/MainWindow.cpp @@ -7,6 +7,8 @@ void MainWindow::OpenGridExample() { if (!gridDemo || gridDemo->IsHidden()) { + if (gridDemo) + delete gridDemo; gridDemo = new GridDemoWindow(); gridDemo->Show(); } @@ -15,13 +17,16 @@ void MainWindow::OpenGridExample() } void MainWindow::OpenControlsDemo() { - if (!controlsDemo || controlsDemo->IsHidden()) - { - controlsDemo = new ControlsDemoWindow(); - controlsDemo->Show(); - } - else - controlsDemo->Activate(); + + if (!controlsDemo || controlsDemo->IsHidden()) + { + if(controlsDemo) + delete controlsDemo; + controlsDemo = new ControlsDemoWindow(); + controlsDemo->Show(); + } + else + controlsDemo->Activate(); } void MainWindow::ShowAbout() { diff --git a/Demo/MainWindow.h b/Demo/MainWindow.h index 2be41cd..b8a7b33 100644 --- a/Demo/MainWindow.h +++ b/Demo/MainWindow.h @@ -13,6 +13,8 @@ class MainWindow : public Window void OpenGridExample(); void OpenControlsDemo(); void ShowAbout(); + void ControlsDemoClosed(); + void GridDemoClosed(); GridDemoWindow* gridDemo; ControlsDemoWindow* controlsDemo; void InitializeComponent() diff --git a/Demo/main.cpp b/Demo/main.cpp index faa46f4..e7a2de6 100644 --- a/Demo/main.cpp +++ b/Demo/main.cpp @@ -4,19 +4,25 @@ #include "MainWindow.h" -INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { - (void)hPrevInstance; - (void)lpCmdLine; - - MainWindow* mainWind = new MainWindow(); - mainWind->Show(); +INT WINAPI WinMain( + _In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPSTR lpCmdLine, + _In_ int nShowCmd +) +{ + (void)hPrevInstance; + (void)lpCmdLine; - MSG msg = {}; + MainWindow* mainWind = new MainWindow(); + mainWind->Show(); - while (GetMessage(&msg, nullptr, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + MSG msg = {}; - return static_cast(msg.wParam); + while (GetMessage(&msg, nullptr, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return static_cast(msg.wParam); } \ No newline at end of file diff --git a/MUI/ContextMenu.cpp b/MUI/ContextMenu.cpp new file mode 100644 index 0000000..fad0c49 --- /dev/null +++ b/MUI/ContextMenu.cpp @@ -0,0 +1,164 @@ +#include "MUI.h" +namespace MUI +{ + ContextMenu::~ContextMenu() + { + m_Assets.clear(); + m_childs.clear(); + m_menus.clear(); + } + void ContextMenu::Open() + { + WNDCLASSEX wcex = {}; + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = ContextMenu::SubclassWndProc; + wcex.hInstance = GetModuleHandleW(NULL); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.lpszClassName = L"MUI_ContextMenu"; + + if (!RegisterClassEx(&wcex)) { + DWORD error = GetLastError(); + if(error != ERROR_CLASS_ALREADY_EXISTS) + return; + } + + HWND dummyHWND = CreateWindowEx + ( + 0, + L"MUI_ContextMenu", + L"", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + 0, + 0, + NULL, + NULL, + wcex.hInstance, + this + ); + } + LRESULT CALLBACK ContextMenu::SubclassWndProc(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam) + { + ContextMenu* menu; + if (wm == WM_NCCREATE) { + CREATESTRUCT* pCreate = reinterpret_cast(lParam); + menu = reinterpret_cast(pCreate->lpCreateParams); + SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(menu)); + } + else + { + LONG_PTR ptr = GetWindowLongPtr(hwnd, GWLP_USERDATA); + menu = (ContextMenu*)ptr; + } + if (menu) { + switch (wm) { + case WM_COMMAND: + { + if (menu->m_Assets.find((UINT)wParam) != menu->m_Assets.end()) + { + UIComponent* comp = menu->m_Assets[(UINT)wParam]; + comp->HandleEvents(wm, wParam, lParam); + } + } + break; + case WM_CREATE: + { + SetForegroundWindow(hwnd); + HMENU hMenuPop = CreatePopupMenu(); + for (size_t i = 0; i < menu->m_childs.size(); i++) + { + HMENU hMenu = CreateMenu(); + uint64_t index = menu->m_Index; + UIComponent* comp = menu->m_childs[i]; + if (comp->type != UISeparator) { + menu->m_Index++; + menu->m_Assets[index] = comp; + } + if (comp->type == UIMenu) + { + menu->m_menus[i]->m_ParentHMENU = hMenu; + menu->m_menus[i]->id = (DWORD)index; + if (menu->m_menus[i]->m_childs.size() > 0) + { + HMENU newHMenu = CreateMenu(); + menu->m_menus[i]->m_hMenu = newHMenu; + menu->m_menus[i]->SetStyle(MF_POPUP); + menu->AppendChilds(menu->m_menus[i], newHMenu); + AppendMenuW(hMenuPop, menu->m_menus[i]->style, (UINT_PTR)newHMenu, comp->m_WindowName); + } + else + AppendMenuW(hMenuPop, comp->style, index, comp->m_WindowName); + } + else + { + AppendMenuW(hMenuPop, comp->style, index, comp->m_WindowName); + } + } + + // Get current mouse position. + POINT curPoint; + GetCursorPos(&curPoint); + + TrackPopupMenu( + hMenuPop, + TPM_LEFTBUTTON, + curPoint.x, + curPoint.y, + 0, + hwnd, + NULL + ); + + DestroyMenu(hMenuPop); + delete menu; + DestroyWindow(hwnd); + } + break; + } + } + return DefWindowProc(hwnd, wm, wParam, lParam); + } + void ContextMenu::AppendChilds(Menu* menu, HMENU hMenu) + { + for (size_t i = 0; i < menu->m_childs.size(); i++) + { + uint64_t index = this->m_Index; + UIComponent* comp = menu->m_childs[i]; + if (comp->type != UISeparator) { + this->m_Index++; + m_Assets[index] = comp; + } + if (comp->type == UIMenu) + { + menu->m_menus[i]->m_ParentHMENU = hMenu; + menu->m_menus[i]->id = (DWORD)index; + if (menu->m_menus[i]->m_childs.size() > 0) + { + HMENU newHMenu = CreateMenu(); + menu->m_menus[i]->m_hMenu = newHMenu; + menu->m_menus[i]->SetStyle(MF_POPUP); + AppendChilds(menu->m_menus[i], newHMenu); + AppendMenuW(hMenu, menu->m_menus[i]->style, (UINT_PTR)newHMenu, comp->m_WindowName); + } + else + AppendMenuW(hMenu, comp->style, index, comp->m_WindowName); + } + else + { + AppendMenuW(hMenu, comp->style, index, comp->m_WindowName); + } + } + } + void ContextMenu::Add(Menu* menu) + { + this->m_childs.push_back(menu); + this->m_menus.push_back(menu); + } + void ContextMenu::Add(Separator* menu) + { + this->m_menus.push_back(NULL); + this->m_childs.push_back(menu); + } +} \ No newline at end of file diff --git a/MUI/Grid.cpp b/MUI/Grid.cpp index 4e85d3b..cedf5c2 100644 --- a/MUI/Grid.cpp +++ b/MUI/Grid.cpp @@ -1,6 +1,21 @@ #include "MUI.h" namespace MUI { + Grid::~Grid() + { + for (size_t i = 0; i < m_rows.size(); i++) + delete m_rows[i]; + for (size_t i = 0; i < m_columns.size(); i++) + delete m_columns[i]; + for (size_t i = 0; i < m_items.size(); i++) + delete m_items[i]; + if(!m_items.empty()) + m_items.clear(); + if (!m_rows.empty()) + m_rows.clear(); + if (!m_columns.empty()) + m_columns.clear(); + } Grid::Grid() { this->AddColumn(0, L"*"); diff --git a/MUI/ListItem.cpp b/MUI/ListItem.cpp index 7729856..44b8d45 100644 --- a/MUI/ListItem.cpp +++ b/MUI/ListItem.cpp @@ -1,6 +1,10 @@ #include "MUI.h" namespace MUI { + ListItem::~ListItem() + { + values.clear(); + } ListItem::ListItem(int imageIndex, std::vector values) { this->imageIndex = imageIndex; diff --git a/MUI/ListView.cpp b/MUI/ListView.cpp index 789265f..12292f6 100644 --- a/MUI/ListView.cpp +++ b/MUI/ListView.cpp @@ -2,6 +2,10 @@ namespace MUI { + ListView::~ListView() + { + this->Clear(); + } ListView::ListView(int x,int y,int width, int height) { this->columnIndex = 0; @@ -26,6 +30,10 @@ namespace MUI { ImageList_RemoveAll(this->hLarge); ImageList_RemoveAll(this->hSmall); + if (hLarge) + ImageList_Destroy(hLarge); + if (hSmall) + ImageList_Destroy(hSmall); this->hLarge = ImageList_Create(32, 32, ILC_COLOR32, 3, 0); @@ -41,12 +49,15 @@ namespace MUI void ListView::DeleteItemAt(int i) { ListView_DeleteItem(this->handle,i); + delete m_Items[i]; this->m_Items.erase(this->m_Items.begin() + i); this->itemIndex--; } void ListView::ClearItems() { ListView_DeleteAllItems(this->handle); + for (size_t i = 0; i < m_Items.size(); i++) + delete m_Items[i]; this->m_Items.erase(this->m_Items.begin(), this->m_Items.end()); this->itemIndex = 0; } @@ -68,13 +79,13 @@ namespace MUI } ListItem* ListView::GetItemAt(int i) { - return &this->m_Items[i]; + return this->m_Items[i]; } ListItem* ListView::GetSelected() { int iPos = ListView_GetNextItem(this->handle, -1, LVNI_SELECTED); if(iPos != -1) - return &this->m_Items[iPos]; + return this->m_Items[iPos]; return NULL; } BOOL ListView::AddIcon(HICON icon) @@ -114,7 +125,7 @@ namespace MUI ListView_SetItem(this->handle, (LPARAM)&lvi); index++; } - this->m_Items.push_back(ListItem(*item)); + this->m_Items.push_back(item); return GetLastError() == 0; } } \ No newline at end of file diff --git a/MUI/MUI.h b/MUI/MUI.h index f15777f..28f6aff 100644 --- a/MUI/MUI.h +++ b/MUI/MUI.h @@ -35,7 +35,6 @@ using namespace Gdiplus; #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 #endif #pragma endregion - namespace MUI { static inline bool IsDarkMode() { @@ -115,7 +114,9 @@ namespace MUI { friend class Grid; friend class GridRow; friend class GridColumn; + friend class ContextMenu; public: + virtual ~UIComponent() {}; BOOL SetStyle(DWORD newStyle); DWORD GetStyle(); void SetColumnSpan(int span) { this->columnSpan = max(0, span); } @@ -151,7 +152,7 @@ namespace MUI { DWORD style = NULL; COLORREF backgroundColor = NULL; UIComponent* parent = NULL; - int x, y, width, height; + int x, y, width, height = 0; int columnSpan = 0; int rowSpan = 0; }; @@ -170,7 +171,9 @@ namespace MUI { class Menu : public MUI::UIComponent { friend class Window; + friend class ContextMenu; public: + ~Menu(); Menu(LPCWSTR text); void Add(Menu* menu); void Add(Separator* sep); @@ -182,12 +185,30 @@ namespace MUI { HMENU m_ParentHMENU; virtual void HandleEvents(UINT uMsg, WPARAM wParam, LPARAM lParam) override; std::vector m_menus; + std::vector m_separators; std::vector m_childs; }; - class MenuBar : public MUI::UIComponent + class ContextMenu : private MUI::UIComponent + { + friend class Window; + public: + ~ContextMenu(); + void Add(Menu* menu); + void Add(Separator* sep); + void Open(); + private: + std::vector m_menus; + std::vector m_childs; + std::unordered_map m_Assets; + static LRESULT CALLBACK SubclassWndProc(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam); + void AppendChilds(Menu* menu, HMENU hMenu); + UINT m_Index = 1; + }; + class MenuBar /*: public MUI::UIComponent*/ { friend class Window; public: + ~MenuBar(); void Add(Menu* menu); private: std::vector m_menus; @@ -240,6 +261,7 @@ namespace MUI { class Grid { friend class Window; public: + ~Grid(); Grid(); std::vector GetComponents(); std::vector GetItems() { return this->m_items; } @@ -271,6 +293,7 @@ namespace MUI { { friend class ListView; public: + ~ListItem(); ListItem(int imageIndex, std::vector values); void SetImageIndex(int index); std::vector GetValues(); @@ -282,6 +305,7 @@ namespace MUI { class ListView : public MUI::UIComponent { public: + ~ListView(); ListView(int x, int y, int width, int height); BOOL AddColumn(const wchar_t* title, int length = 100); BOOL AddItem(ListItem* item); @@ -297,7 +321,7 @@ namespace MUI { void ClearItems(); void Clear(); private: - std::vector m_Items; + std::vector m_Items; UINT columnIndex; UINT itemIndex; HIMAGELIST hLarge; // Image list for icon view. @@ -347,6 +371,10 @@ namespace MUI { TextBox(LPCWSTR text, BOOL number, int x, int y, int width, int height); std::wstring GetText(); int GetNumber(); + /*void EnableHorizontalScrollbar(BOOL isEnabled); + void EnableVerticalScrollbar(BOOL isEnabled); + BOOL HorizontalScrollbarEnabled(); + BOOL VerticalScrollbarEnabled();*/ private: BOOL isNum; }; @@ -402,7 +430,7 @@ namespace MUI { { int width = rect.right - rect.left; int height = rect.bottom - rect.top; - SIZE res; + SIZE res{}; res.cx = width; res.cy = height; return res; diff --git a/MUI/MUI.vcxproj b/MUI/MUI.vcxproj index 7f54e69..f1c44f6 100644 --- a/MUI/MUI.vcxproj +++ b/MUI/MUI.vcxproj @@ -136,6 +136,7 @@ + diff --git a/MUI/MUI.vcxproj.filters b/MUI/MUI.vcxproj.filters index e4ec7e8..dc52e9b 100644 --- a/MUI/MUI.vcxproj.filters +++ b/MUI/MUI.vcxproj.filters @@ -59,6 +59,9 @@ Source Files + + Source Files + diff --git a/MUI/Menu.cpp b/MUI/Menu.cpp index ecd3e1a..75d7c37 100644 --- a/MUI/Menu.cpp +++ b/MUI/Menu.cpp @@ -5,11 +5,21 @@ namespace MUI { this->m_menus.push_back(menu); } + MenuBar::~MenuBar() + { + for (size_t i = 0; i < m_menus.size(); i++) + delete m_menus[i]; + } Separator::Separator() { this->style = MF_SEPARATOR; this->type = UISeparator; } + Menu::~Menu() + { + for (size_t i = 0; i < m_separators.size(); i++) + delete m_separators[i]; + } Menu::Menu(LPCWSTR text) { this->m_WindowName = text; @@ -25,6 +35,7 @@ namespace MUI { this->m_childs.push_back(sep); this->m_menus.push_back(NULL); + this->m_separators.push_back(sep); } BOOL Menu::IsChecked() { diff --git a/MUI/TextBox.cpp b/MUI/TextBox.cpp index b2bbb52..ee3cdab 100644 --- a/MUI/TextBox.cpp +++ b/MUI/TextBox.cpp @@ -10,13 +10,14 @@ namespace MUI { this->y = y; this->width = width; this->height = height; - this->style = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL; + this->style = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE; if (number) this->style |= ES_NUMBER; this->isNum = number; } std::wstring TextBox::GetText() { + std::wstring res; int len = GetWindowTextLengthW(this->handle) + 1; wchar_t* buffer = new wchar_t[len]; int suc = GetDlgItemText( @@ -26,8 +27,11 @@ namespace MUI { len ); if (suc) - return std::wstring(buffer); - return std::wstring(L""); + res = std::wstring(buffer); + else + res = std::wstring(L""); + delete[] buffer; + return res; } int TextBox::GetNumber() { @@ -37,4 +41,31 @@ namespace MUI { return res; return NULL; } + /*void TextBox::EnableHorizontalScrollbar(BOOL isEnabled) + { + if(isEnabled) + this->SetStyle(this->GetStyle() | WS_HSCROLL); + else + this->SetStyle(this->GetStyle() & ~WS_HSCROLL); + BOOL suc = ShowScrollBar(this->handle, SB_HORZ, isEnabled); + SetWindowPos(this->handle,this->handle,this->x,this->y,this->x,this->y, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE); + suc = InvalidateRect(this->handle,NULL,NULL); + } + void TextBox::EnableVerticalScrollbar(BOOL isEnabled) + { + if (isEnabled) + this->SetStyle(this->GetStyle() | WS_VSCROLL); + else + this->SetStyle(this->GetStyle() & ~WS_VSCROLL); + BOOL suc = ShowScrollBar(this->handle, SB_VERT, isEnabled); + suc = InvalidateRect(this->handle, NULL, NULL); + } + BOOL TextBox::HorizontalScrollbarEnabled() + { + return this->GetStyle() & WS_HSCROLL; + } + BOOL TextBox::VerticalScrollbarEnabled() + { + return this->GetStyle() & WS_VSCROLL; + }*/ } \ No newline at end of file diff --git a/MUI/Window.cpp b/MUI/Window.cpp index e4b1d56..9b01f4a 100644 --- a/MUI/Window.cpp +++ b/MUI/Window.cpp @@ -59,7 +59,7 @@ namespace MUI this->m_hInstance, this ); - m_Windows += 1; + m_Windows++; m_Destroyed = FALSE; #ifdef DEBUG GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); @@ -391,17 +391,25 @@ namespace MUI } } void Window::OnDestroy() { - DeleteObject(this->m_hFont); - DeleteObject(this->m_hBrushBackground); - this->m_Assets.erase(this->m_Assets.begin(), this->m_Assets.end()); - this->m_UnusedIndexes.erase(this->m_UnusedIndexes.begin(), this->m_UnusedIndexes.end()); - m_Index = 1; - m_Windows--; - m_Destroyed = TRUE; + if (!m_Destroyed) { + DeleteObject(this->m_hFont); + DeleteObject(this->m_hBrushBackground); + for (size_t i = 1; i < this->m_Index; i++) + delete this->m_Assets[i]; + this->m_Assets.erase(this->m_Assets.begin(), this->m_Assets.end()); + this->m_UnusedIndexes.erase(this->m_UnusedIndexes.begin(), this->m_UnusedIndexes.end()); + if (m_grid) + delete m_grid; + if (m_dockMenu) + delete m_dockMenu; + m_Index = 1; + m_Windows--; + m_Destroyed = TRUE; #if EXIT_ON_CLOSE - if (m_Windows <= 0) - PostQuitMessage(0); + if (m_Windows <= 0) + PostQuitMessage(0); #endif // EXIT_ON_CLOSE + } } void Window::OnCreate() {