From c5dd667b328736f0a040f1820ea6c8ede808678d Mon Sep 17 00:00:00 2001 From: Denis Malikov Date: Thu, 8 Mar 2018 21:03:04 +0700 Subject: [PATCH] [EXPLORER] getting toolbar in cpp manner --- base/shell/explorer/notifyiconscust.cpp | 17 +++++++++-------- base/shell/explorer/precomp.h | 12 ++++++++++-- base/shell/explorer/syspager.cpp | 24 ++++++++++++++++++------ base/shell/explorer/trayntfy.cpp | 17 +++++++++++++++++ base/shell/explorer/trayprop.cpp | 10 +++++----- base/shell/explorer/traywnd.cpp | 4 ++-- sdk/include/reactos/rosctrls.h | 5 +++++ 7 files changed, 66 insertions(+), 23 deletions(-) diff --git a/base/shell/explorer/notifyiconscust.cpp b/base/shell/explorer/notifyiconscust.cpp index 2315ffd507cb7..fe2aa281ca488 100644 --- a/base/shell/explorer/notifyiconscust.cpp +++ b/base/shell/explorer/notifyiconscust.cpp @@ -207,13 +207,14 @@ INT_PTR CALLBACK CustomizeNotifyIconsProc(HWND hwnd, UINT Message, WPARAM wParam return TRUE; } -VOID SetNotifyIcons(HWND hDialog, HWND hTrayNotify) +VOID SetNotifyIcons(HWND hDialog, IUnknown *TrayNotify) { HWND hListView = GetDlgItem(hDialog, IDC_NOTIFICATION_LIST); - HWND hSysPager = FindWindowEx(hTrayNotify, NULL, L"SysPager", NULL); - HWND hToolbar = FindWindowEx(hSysPager, NULL, L"ToolbarWindow32", NULL); + CToolbar* toolbar = CTrayNotifyWnd_GetTrayToolbar(TrayNotify); - HIMAGELIST tbImageList = (HIMAGELIST)SendMessage(hToolbar, TB_GETIMAGELIST, 0, 0); + if (toolbar == NULL) return; + + HIMAGELIST tbImageList = (HIMAGELIST)toolbar->GetImageList(); HIMAGELIST lvImageList = ImageList_Duplicate(tbImageList); ListView_SetImageList(hListView, lvImageList, LVSIL_SMALL); @@ -228,10 +229,10 @@ VOID SetNotifyIcons(HWND hDialog, HWND hTrayNotify) LVITEM lvItem; TBBUTTON tbtn; - DWORD nButtons = (DWORD)SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); + DWORD nButtons = toolbar->GetButtonCount(); for (UINT i = 0; i != nButtons; i++) { - if (SendMessage(hToolbar, TB_GETBUTTON, (WPARAM)i, (LPARAM)&tbtn)) + if (toolbar->GetButton(i, &tbtn)) { ZeroMemory(&lvItem, sizeof(lvItem)); lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID | LVIF_PARAM; @@ -253,11 +254,11 @@ VOID SetNotifyIcons(HWND hDialog, HWND hTrayNotify) } } -VOID ShowCustomizeNotifyIcons(HINSTANCE hInst, HWND hExplorer, HWND hTrayNotify) +VOID ShowCustomizeNotifyIcons(HINSTANCE hInst, HWND hExplorer, IUnknown *TrayNotify) { HWND hDlg = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_NOTIFICATIONS_CUSTOMIZE), hExplorer, CustomizeNotifyIconsProc); - SetNotifyIcons(hDlg, hTrayNotify); + SetNotifyIcons(hDlg, TrayNotify); ShowWindow(hDlg, SW_SHOW); } \ No newline at end of file diff --git a/base/shell/explorer/precomp.h b/base/shell/explorer/precomp.h index 76690bdb85e36..be4355db17ff3 100644 --- a/base/shell/explorer/precomp.h +++ b/base/shell/explorer/precomp.h @@ -242,7 +242,7 @@ ProcessStartupItems(VOID); */ VOID -DisplayTrayProperties(IN HWND hwndOwner, IN HWND hwndTaskbar, IN HWND hTrayNotify); +DisplayTrayProperties(IN HWND hwndOwner, IN HWND hwndTaskbar, IN IUnknown *Tray); /* * desktop.cpp @@ -258,7 +258,7 @@ DesktopDestroyShellWindow(IN HANDLE hDesktop); * notifyiconscust.cpp */ VOID -ShowCustomizeNotifyIcons(HINSTANCE, HWND, HWND); +ShowCustomizeNotifyIcons(HINSTANCE, HWND, IUnknown*); /* * taskband.cpp @@ -344,10 +344,18 @@ HRESULT CTrayClockWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv); #define NTNWM_REALIGN (0x1) +struct InternalIconData : NOTIFYICONDATA +{ + // Must keep a separate copy since the original is unioned with uTimeout. + UINT uVersionCopy; +}; + HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv); +CToolbar* CTrayNotifyWnd_GetTrayToolbar(IUnknown *pTray); /* SysPagerWnd */ HRESULT CSysPagerWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv); +CToolbar* CSysPagerWnd_GetTrayToolbar(IUnknown *pPager); /* * taskswnd.c diff --git a/base/shell/explorer/syspager.cpp b/base/shell/explorer/syspager.cpp index fa2aa73b3674d..a1904a9ef75ee 100644 --- a/base/shell/explorer/syspager.cpp +++ b/base/shell/explorer/syspager.cpp @@ -21,12 +21,6 @@ #include "precomp.h" -struct InternalIconData : NOTIFYICONDATA -{ - // Must keep a separate copy since the original is unioned with uTimeout. - UINT uVersionCopy; -}; - struct IconWatcherData { HANDLE hProcess; @@ -208,6 +202,7 @@ class CSysPagerWnd : LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + CNotifyToolbar* GetToolbar(); public: @@ -1463,7 +1458,24 @@ HRESULT CSysPagerWnd::Initialize(IN HWND hWndParent) return S_OK; } +CNotifyToolbar* CSysPagerWnd::GetToolbar() +{ + return &Toolbar; +} + HRESULT CSysPagerWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv) { return ShellObjectCreatorInit(hwndParent, riid, ppv); } + +CToolbar* CSysPagerWnd_GetTrayToolbar(IUnknown *pPager) +{ + CSysPagerWnd *pager = static_cast(pPager); + + if (pager != NULL) + { + return pager->GetToolbar(); + } + + return NULL; +} diff --git a/base/shell/explorer/trayntfy.cpp b/base/shell/explorer/trayntfy.cpp index 4326ca727ea55..97123d3d5ce81 100644 --- a/base/shell/explorer/trayntfy.cpp +++ b/base/shell/explorer/trayntfy.cpp @@ -330,6 +330,11 @@ class CTrayNotifyWnd : return E_NOTIMPL; } + IUnknown* GetPager() + { + return m_pager; + } + DECLARE_NOT_AGGREGATABLE(CTrayNotifyWnd) DECLARE_PROTECT_FINAL_CONSTRUCT() @@ -369,3 +374,15 @@ HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv) { return ShellObjectCreatorInit(hwndParent, riid, ppv); } + +CToolbar* CTrayNotifyWnd_GetTrayToolbar(IUnknown* pTray) +{ + CTrayNotifyWnd *tray = static_cast(pTray); + + if (tray != NULL) + { + return CSysPagerWnd_GetTrayToolbar(tray->GetPager()); + } + + return NULL; +} diff --git a/base/shell/explorer/trayprop.cpp b/base/shell/explorer/trayprop.cpp index de1002634820b..cae6aded1daa4 100644 --- a/base/shell/explorer/trayprop.cpp +++ b/base/shell/explorer/trayprop.cpp @@ -50,7 +50,7 @@ class CTaskBarSettingsPage : public CPropertyPageImpl HBITMAP m_hbmpTaskbar; HBITMAP m_hbmpTray; HWND m_hwndTaskbar; - HWND m_TrayNotify; + IUnknown *m_TrayNotify; void UpdateDialog() { @@ -124,11 +124,11 @@ class CTaskBarSettingsPage : public CPropertyPageImpl CHAIN_MSG_MAP(CPropertyPageImpl) END_MSG_MAP() - CTaskBarSettingsPage(HWND hwnd, HWND hTrayNotify): + CTaskBarSettingsPage(HWND hwnd, IUnknown *Tray): m_hbmpTaskbar(NULL), m_hbmpTray(NULL), m_hwndTaskbar(hwnd), - m_TrayNotify(hTrayNotify) + m_TrayNotify(Tray) { } @@ -248,11 +248,11 @@ class CStartMenuSettingsPage : public CPropertyPageImpl }; VOID -DisplayTrayProperties(IN HWND hwndOwner, IN HWND hwndTaskbar, IN HWND hTrayNotify) +DisplayTrayProperties(IN HWND hwndOwner, IN HWND hwndTaskbar, IN IUnknown *Tray) { PROPSHEETHEADER psh; HPROPSHEETPAGE hpsp[2]; - CTaskBarSettingsPage tbSettingsPage(hwndTaskbar, hTrayNotify); + CTaskBarSettingsPage tbSettingsPage(hwndTaskbar, Tray); CStartMenuSettingsPage smSettingsPage; CStringW caption; diff --git a/base/shell/explorer/traywnd.cpp b/base/shell/explorer/traywnd.cpp index 2613c8464a140..425dbf3b1369f 100644 --- a/base/shell/explorer/traywnd.cpp +++ b/base/shell/explorer/traywnd.cpp @@ -405,7 +405,7 @@ class CTrayWindow : m_TrayPropertiesOwner = hwnd; - DisplayTrayProperties(hwnd, m_hWnd, m_TrayNotify); + DisplayTrayProperties(hwnd, m_hWnd, m_TrayNotifyInstance); m_TrayPropertiesOwner = NULL; ::DestroyWindow(hwnd); @@ -515,7 +515,7 @@ class CTrayWindow : break; case ID_SHELL_CMD_CUST_NOTIF: - ShowCustomizeNotifyIcons(hExplorerInstance, m_hWnd, m_TrayNotify); + ShowCustomizeNotifyIcons(hExplorerInstance, m_hWnd, m_TrayNotifyInstance); break; case ID_SHELL_CMD_ADJUST_DAT: diff --git a/sdk/include/reactos/rosctrls.h b/sdk/include/reactos/rosctrls.h index f332aca915a25..59eda94080236 100644 --- a/sdk/include/reactos/rosctrls.h +++ b/sdk/include/reactos/rosctrls.h @@ -400,6 +400,11 @@ class CToolbar : return SendMessageW(TB_SETIMAGELIST, 0, reinterpret_cast(himl)); } + HIMAGELIST GetImageList() + { + return (HIMAGELIST)SendMessageW(TB_GETIMAGELIST, 0, 0); + } + public: // Other methods INT HitTest(PPOINT ppt) {