CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/W32Util/DialogManager.cpp
Views: 1401
#include "Common/CommonWindows.h"1#include <vector>2#include <algorithm>3#include "Windows/W32Util/DialogManager.h"456Dialog::Dialog(LPCSTR res, HINSTANCE _hInstance, HWND _hParent)7{8m_hInstance = _hInstance;9m_hParent = _hParent;10m_hResource = res;11m_bValid = true;12Create();13}1415Dialog::~Dialog()16{17m_bValid = false;18Destroy();19}2021void Dialog::Create()22{23m_hDlg = CreateDialogParam(m_hInstance, (LPCWSTR)m_hResource, m_hParent, DlgProcStatic, (LPARAM)this);24SetWindowLongPtr(m_hDlg, GWLP_USERDATA, (LONG_PTR)this);25}2627void Dialog::Destroy()28{29DestroyWindow(m_hDlg);30}3132void Dialog::Show(bool _bShow, bool includeToTop)33{34if (_bShow && includeToTop)35m_bShowState = SW_SHOWNORMAL;36else if (_bShow)37m_bShowState = SW_SHOWNOACTIVATE;38else39m_bShowState = SW_HIDE;40ShowWindow(m_hDlg, m_bShowState);41if (_bShow && includeToTop)42BringWindowToTop(m_hDlg);43}4445INT_PTR Dialog::DlgProcStatic(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)46{47Dialog *dis = (Dialog*)GetWindowLongPtr(hdlg, GWLP_USERDATA);48if (dis && dis->m_bValid)49return dis->DlgProc(message,wParam,lParam);50else51{52return 0;53/*54if (message == WM_INITDIALOG)55{56SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR)lParam);57return ((Dialog*)lParam)->DlgProc(message,wParam,lParam);58}59else60{61return 0;62}*/63}64}656667typedef std::vector <Dialog *> WindowList;68WindowList dialogs;697071void DialogManager::AddDlg(Dialog *dialog)72{73dialogs.push_back(dialog);74}7576void DialogManager::RemoveDlg(Dialog *dialog)77{78if (!dialog) {79return;80}81dialogs.erase(std::remove(dialogs.begin(), dialogs.end(), dialog), dialogs.end());82}838485bool DialogManager::IsDialogMessage(LPMSG message)86{87WindowList::iterator iter;88for (iter = dialogs.begin(); iter != dialogs.end(); iter++) {89if (::IsDialogMessage((*iter)->GetDlgHandle(), message))90return true;91}92return false;93}949596void DialogManager::EnableAll(BOOL enable)97{98WindowList::iterator iter;99for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)100EnableWindow((*iter)->GetDlgHandle(),enable);101}102103void DialogManager::UpdateAll()104{105WindowList::iterator iter;106for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)107(*iter)->Update();108}109110void DialogManager::DestroyAll()111{112WindowList::iterator iter;113for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)114delete (*iter);115dialogs.clear();116}117118119