From 9bb7f2473921b2b4b0b546251d9e9aae5ef51964 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 27 Dec 2018 14:18:15 +0300 Subject: more code cleaning --- plugins/CrashDumper/src/crshdmp.cpp | 16 --- plugins/CrashDumper/src/stdafx.h | 26 +--- plugins/CrashDumper/src/ui.cpp | 237 ++++++++++++++++++++---------------- 3 files changed, 133 insertions(+), 146 deletions(-) (limited to 'plugins/CrashDumper') diff --git a/plugins/CrashDumper/src/crshdmp.cpp b/plugins/CrashDumper/src/crshdmp.cpp index 8c76065ec6..024da9fd36 100644 --- a/plugins/CrashDumper/src/crshdmp.cpp +++ b/plugins/CrashDumper/src/crshdmp.cpp @@ -112,22 +112,6 @@ INT_PTR UploadVersionInfo(WPARAM, LPARAM lParam) return 0; } - -INT_PTR ViewVersionInfo(WPARAM wParam, LPARAM) -{ - if (pViewDialog == nullptr) { - DWORD dwFlags = wParam ? (VI_FLAG_PRNVAR | VI_FLAG_PRNDLL) : VI_FLAG_PRNVAR; - pViewDialog = new CViewVersionInfo(dwFlags); - pViewDialog->Show(); - } - else { - SetForegroundWindow(pViewDialog->GetHwnd()); - SetFocus(pViewDialog->GetHwnd()); - } - - return 0; -} - INT_PTR GetVersionInfo(WPARAM wParam, LPARAM lParam) { int result = 1; //failure diff --git a/plugins/CrashDumper/src/stdafx.h b/plugins/CrashDumper/src/stdafx.h index 51c44fa0e4..911fd55b5d 100644 --- a/plugins/CrashDumper/src/stdafx.h +++ b/plugins/CrashDumper/src/stdafx.h @@ -144,8 +144,6 @@ void SetExceptionHandler(void); void RemoveExceptionHandler(void); extern CDlgBase *pViewDialog; -//INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -//INT_PTR CALLBACK DlgProcView(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); void DestroyAllWindows(void); void UploadInit(void); @@ -155,28 +153,6 @@ void __cdecl VersionInfoUploadThread(void* arg); void InitIcons(void); HICON LoadIconEx(int iconId, bool big = false); -void ReleaseIconEx(int iconId); HANDLE GetIconHandle(int iconId); -class CViewVersionInfo : public CDlgBase -{ -private: - DWORD m_flags; - - CCtrlButton m_btnCancel, m_btnCopyClip, m_btnCopyFile; - CCtrlRichEdit m_redtViewVersionInfo; - -protected: - bool OnInitDialog() override; - bool OnClose() override; - int Resizer(UTILRESIZECONTROL*) override; - INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override; - - void OnCancelClick(CCtrlBase*); - void OnCopyClipClick(CCtrlBase*); - void OnCopyFileClick(CCtrlBase*); - void OnViewVersionInfoBuildMenu(CCtrlBase*); - -public: - CViewVersionInfo(DWORD flags); -}; \ No newline at end of file +INT_PTR ViewVersionInfo(WPARAM wParam, LPARAM); diff --git a/plugins/CrashDumper/src/ui.cpp b/plugins/CrashDumper/src/ui.cpp index 13ba7a5b1c..43f52356aa 100644 --- a/plugins/CrashDumper/src/ui.cpp +++ b/plugins/CrashDumper/src/ui.cpp @@ -56,136 +56,163 @@ BOOL MyResizeGetOffset(HWND hwndCtrl, int nWidth, int nHeight, int* nDx, int* nD return rcinit.bottom != rcinit.top && nHeight > 0; } -CViewVersionInfo::CViewVersionInfo(DWORD flags) : - CDlgBase(g_plugin, IDD_VIEWVERSION), - m_btnCancel(this, IDCANCEL), - m_btnCopyClip(this, IDC_CLIPVER), - m_btnCopyFile(this, IDC_FILEVER), - m_redtViewVersionInfo(this, IDC_VIEWVERSIONINFO) +class CViewVersionInfo : public CDlgBase { - m_flags = flags; - m_btnCancel.OnClick = Callback(this, &CViewVersionInfo::OnCancelClick); - m_btnCopyClip.OnClick = Callback(this, &CViewVersionInfo::OnCopyClipClick); - m_btnCopyFile.OnClick = Callback(this, &CViewVersionInfo::OnCopyFileClick); - m_redtViewVersionInfo.OnBuildMenu = Callback(this, &CViewVersionInfo::OnViewVersionInfoBuildMenu); -} + DWORD m_flags; -bool CViewVersionInfo::OnInitDialog() -{ - Window_SetIcon_IcoLib(m_hwnd, GetIconHandle(IDI_VI)); + CCtrlButton m_btnCancel, m_btnCopyClip, m_btnCopyFile; + CCtrlRichEdit m_redtViewVersionInfo; + +public: + CViewVersionInfo::CViewVersionInfo(DWORD flags) : + CDlgBase(g_plugin, IDD_VIEWVERSION), + m_btnCancel(this, IDCANCEL), + m_btnCopyClip(this, IDC_CLIPVER), + m_btnCopyFile(this, IDC_FILEVER), + m_redtViewVersionInfo(this, IDC_VIEWVERSIONINFO) { - CHARFORMAT2 chf; - chf.cbSize = sizeof(chf); - m_redtViewVersionInfo.SendMsg(EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&chf); - mir_wstrcpy(chf.szFaceName, L"Courier New"); - m_redtViewVersionInfo.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&chf); - - CMStringW buffer; - PrintVersionInfo(buffer, m_flags); - m_redtViewVersionInfo.SetText(buffer.c_str()); + m_flags = flags; + m_btnCancel.OnClick = Callback(this, &CViewVersionInfo::OnCancelClick); + m_btnCopyClip.OnClick = Callback(this, &CViewVersionInfo::OnCopyClipClick); + m_btnCopyFile.OnClick = Callback(this, &CViewVersionInfo::OnCopyFileClick); + m_redtViewVersionInfo.OnBuildMenu = Callback(this, &CViewVersionInfo::OnViewVersionInfoBuildMenu); } - if (m_flags & VI_FLAG_PRNDLL) - SetWindowText(m_hwnd, TranslateT("View Version Information (with DLLs)")); + bool CViewVersionInfo::OnInitDialog() override + { + Window_SetIcon_IcoLib(m_hwnd, GetIconHandle(IDI_VI)); + { + CHARFORMAT2 chf; + chf.cbSize = sizeof(chf); + m_redtViewVersionInfo.SendMsg(EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&chf); + mir_wstrcpy(chf.szFaceName, L"Courier New"); + m_redtViewVersionInfo.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&chf); + + CMStringW buffer; + PrintVersionInfo(buffer, m_flags); + m_redtViewVersionInfo.SetText(buffer.c_str()); + } - Utils_RestoreWindowPositionNoMove(m_hwnd, NULL, MODULENAME, "ViewInfo_"); - Show(); - return true; -} + if (m_flags & VI_FLAG_PRNDLL) + SetWindowText(m_hwnd, TranslateT("View Version Information (with DLLs)")); -int CViewVersionInfo::Resizer(UTILRESIZECONTROL *) -{ - RECT rc; - GetWindowRect(m_btnCopyFile.GetHwnd(), &rc); - - int dx, dy; - if (MyResizeGetOffset(m_redtViewVersionInfo.GetHwnd(), LOWORD(m_flags) - 20, HIWORD(m_flags) - 30 - (rc.bottom - rc.top), &dx, &dy)) { - HDWP hDwp = BeginDeferWindowPos(4); - hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCopyFile.GetHwnd(), 0, dy, 0, 0); - hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCopyClip.GetHwnd(), dx / 2, dy, 0, 0); - hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCancel.GetHwnd(), dx, dy, 0, 0); - hDwp = MyResizeWindow(hDwp, m_hwnd, m_redtViewVersionInfo.GetHwnd(), 0, 0, dx, dy); - EndDeferWindowPos(hDwp); + Utils_RestoreWindowPositionNoMove(m_hwnd, NULL, MODULENAME, "ViewInfo_"); + Show(); + return true; } - return 0; -} -void CViewVersionInfo::OnCancelClick(CCtrlBase*) -{ - Close(); -} - -void CViewVersionInfo::OnCopyClipClick(CCtrlBase*) -{ - CallService(MS_CRASHDUMPER_STORETOCLIP, 0, m_flags); -} - -void CViewVersionInfo::OnCopyFileClick(CCtrlBase*) -{ - CallService(MS_CRASHDUMPER_STORETOFILE, 0, m_flags); -} + bool CViewVersionInfo::OnClose() override + { + hViewWnd = nullptr; + Window_FreeIcon_IcoLib(m_hwnd); + Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "ViewInfo_"); + if (pViewDialog == this) + pViewDialog = nullptr; + if (servicemode) + PostQuitMessage(0); + return true; + } -bool CViewVersionInfo::OnClose() -{ - hViewWnd = nullptr; - Window_FreeIcon_IcoLib(m_hwnd); - Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "ViewInfo_"); - if (pViewDialog == this) - pViewDialog = nullptr; - if (servicemode) - PostQuitMessage(0); - return true; -} -void CViewVersionInfo::OnViewVersionInfoBuildMenu(CCtrlBase*) -{ - RECT rc; - GetWindowRect(m_redtViewVersionInfo.GetHwnd(), &rc); + INT_PTR CViewVersionInfo::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override + { + if (msg == WM_GETMINMAXINFO) { + LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; + mmi->ptMinTrackSize.x = 400; // The minimum width in points + mmi->ptMinTrackSize.y = 300; // The minimum height in points + return 0; + } - POINT pt = { GET_X_LPARAM(m_flags), GET_Y_LPARAM(m_flags) }; - if (PtInRect(&rc, pt)) { - static const CHARRANGE all = { 0, -1 }; + return CDlgBase::DlgProc(msg, wParam, lParam); + } - HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXT)); - HMENU hSubMenu = GetSubMenu(hMenu, 0); - TranslateMenu(hSubMenu); + int CViewVersionInfo::Resizer(UTILRESIZECONTROL *) override + { + RECT rc; + GetWindowRect(m_btnCopyFile.GetHwnd(), &rc); + + int dx, dy; + if (MyResizeGetOffset(m_redtViewVersionInfo.GetHwnd(), LOWORD(m_flags) - 20, HIWORD(m_flags) - 30 - (rc.bottom - rc.top), &dx, &dy)) { + HDWP hDwp = BeginDeferWindowPos(4); + hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCopyFile.GetHwnd(), 0, dy, 0, 0); + hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCopyClip.GetHwnd(), dx / 2, dy, 0, 0); + hDwp = MyResizeWindow(hDwp, m_hwnd, m_btnCancel.GetHwnd(), dx, dy, 0, 0); + hDwp = MyResizeWindow(hDwp, m_hwnd, m_redtViewVersionInfo.GetHwnd(), 0, 0, dx, dy); + EndDeferWindowPos(hDwp); + } + return 0; + } - CHARRANGE sel; - SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin == sel.cpMax) - EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); + void CViewVersionInfo::OnCancelClick(CCtrlBase*) + { + Close(); + } - switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, m_hwnd, nullptr)) { - case IDM_COPY: - SendMessage(m_redtViewVersionInfo.GetHwnd(), WM_COPY, 0, 0); - break; + void CViewVersionInfo::OnCopyClipClick(CCtrlBase*) + { + CallService(MS_CRASHDUMPER_STORETOCLIP, 0, m_flags); + } - case IDM_COPYALL: - SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&all); - SendMessage(m_redtViewVersionInfo.GetHwnd(), WM_COPY, 0, 0); - SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&sel); - break; + void CViewVersionInfo::OnCopyFileClick(CCtrlBase*) + { + CallService(MS_CRASHDUMPER_STORETOFILE, 0, m_flags); + } - case IDM_SELECTALL: - SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&all); - break; + void CViewVersionInfo::OnViewVersionInfoBuildMenu(CCtrlBase*) + { + RECT rc; + GetWindowRect(m_redtViewVersionInfo.GetHwnd(), &rc); + + POINT pt = { GET_X_LPARAM(m_flags), GET_Y_LPARAM(m_flags) }; + if (PtInRect(&rc, pt)) { + static const CHARRANGE all = { 0, -1 }; + + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXT)); + HMENU hSubMenu = GetSubMenu(hMenu, 0); + TranslateMenu(hSubMenu); + + CHARRANGE sel; + SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin == sel.cpMax) + EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); + + switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, m_hwnd, nullptr)) { + case IDM_COPY: + SendMessage(m_redtViewVersionInfo.GetHwnd(), WM_COPY, 0, 0); + break; + + case IDM_COPYALL: + SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&all); + SendMessage(m_redtViewVersionInfo.GetHwnd(), WM_COPY, 0, 0); + SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&sel); + break; + + case IDM_SELECTALL: + SendMessage(m_redtViewVersionInfo.GetHwnd(), EM_EXSETSEL, 0, (LPARAM)&all); + break; + } + DestroyMenu(hMenu); } - DestroyMenu(hMenu); } -} +}; -INT_PTR CViewVersionInfo::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) +INT_PTR ViewVersionInfo(WPARAM wParam, LPARAM) { - if (msg == WM_GETMINMAXINFO) { - LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; - mmi->ptMinTrackSize.x = 400; // The minimum width in points - mmi->ptMinTrackSize.y = 300; // The minimum height in points - return 0; + if (pViewDialog == nullptr) { + DWORD dwFlags = wParam ? (VI_FLAG_PRNVAR | VI_FLAG_PRNDLL) : VI_FLAG_PRNVAR; + pViewDialog = new CViewVersionInfo(dwFlags); + pViewDialog->Show(); + } + else { + SetForegroundWindow(pViewDialog->GetHwnd()); + SetFocus(pViewDialog->GetHwnd()); } - return CDlgBase::DlgProc(msg, wParam, lParam); + return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + void DestroyAllWindows(void) { if (hViewWnd != nullptr) { -- cgit v1.2.3