Author: gadamopoulos Date: Wed Aug 3 15:52:27 2016 New Revision: 72099
URL: http://svn.reactos.org/svn/reactos?rev=72099&view=rev Log: [SHELL32] - CDesktopBrowser: Convert to an ATL CWindow class, remove unused fields and cleanup.
Modified: trunk/reactos/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp
Modified: trunk/reactos/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shelldesk... ============================================================================== --- trunk/reactos/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp [iso-8859-1] Wed Aug 3 15:52:27 2016 @@ -22,42 +22,27 @@
WINE_DEFAULT_DEBUG_CHANNEL(desktop);
-#define SHDESK_TAG 'KSED' - static const WCHAR szProgmanClassName[] = L"Progman"; static const WCHAR szProgmanWindowName[] = L"Program Manager";
class CDesktopBrowser : + public CWindowImpl<CDesktopBrowser, CWindow, CFrameWinTraits>, public CComObjectRootEx<CComMultiThreadModelNoCS>, public IShellBrowser, - public ICommDlgBrowser, public IServiceProvider { -public: - DWORD Tag; +private: HACCEL m_hAccel; -private: - HWND hWnd; - HWND hWndShellView; - HWND hWndDesktopListView; // FIXME: Unused - CComPtr<IShellDesktopTray> ShellDesk; - CComPtr<IShellView> DesktopView; - CComPtr<IShellBrowser> DefaultShellBrowser; - LPITEMIDLIST pidlDesktopDirectory; - LPITEMIDLIST pidlDesktop; + HWND m_hWndShellView; + CComPtr<IShellDesktopTray> m_Tray; + CComPtr<IShellView> m_ShellView;
LRESULT _NotifyTray(UINT uMsg, WPARAM wParam, LPARAM lParam);
public: CDesktopBrowser(); ~CDesktopBrowser(); - HRESULT Initialize(HWND hWndx, IShellDesktopTray *ShellDeskx); - HWND FindDesktopListView(); - BOOL CreateDeskWnd(); - HWND DesktopGetWindowControl(IN UINT id); - LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK ProgmanWindowProc(IN HWND hwnd, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam); - BOOL MessageLoop(); + HRESULT Initialize(IShellDesktopTray *ShellDeskx);
// *** IOleWindow methods *** virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd); @@ -78,128 +63,96 @@ virtual HRESULT STDMETHODCALLTYPE OnViewWindowActive(struct IShellView *ppshv); virtual HRESULT STDMETHODCALLTYPE SetToolbarItems(LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags);
- // *** ICommDlgBrowser methods *** - virtual HRESULT STDMETHODCALLTYPE OnDefaultCommand (struct IShellView *ppshv); - virtual HRESULT STDMETHODCALLTYPE OnStateChange (struct IShellView *ppshv, ULONG uChange); - virtual HRESULT STDMETHODCALLTYPE IncludeObject (struct IShellView *ppshv, LPCITEMIDLIST pidl); - // *** IServiceProvider methods *** virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject); + + // message handlers + LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnOpenNewWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); + +DECLARE_WND_CLASS_EX(szProgmanClassName, CS_DBLCLKS, COLOR_DESKTOP) + +BEGIN_MSG_MAP(CBaseBar) + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) + MESSAGE_HANDLER(WM_SIZE, OnSize) + MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSettingChange) + MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange) + MESSAGE_HANDLER(WM_CLOSE, OnClose) + MESSAGE_HANDLER(WM_EXPLORER_OPEN_NEW_WINDOW, OnOpenNewWindow) + MESSAGE_HANDLER(WM_COMMAND, OnCommand) + MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus) +END_MSG_MAP()
BEGIN_COM_MAP(CDesktopBrowser) COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow) COM_INTERFACE_ENTRY_IID(IID_IShellBrowser, IShellBrowser) - COM_INTERFACE_ENTRY_IID(IID_ICommDlgBrowser, ICommDlgBrowser) COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider) END_COM_MAP() };
-CDesktopBrowser::CDesktopBrowser() -{ - Tag = SHDESK_TAG; - hWnd = NULL; - hWndShellView = NULL; - hWndDesktopListView = NULL; - DefaultShellBrowser = NULL; - pidlDesktopDirectory = NULL; - pidlDesktop = NULL; +CDesktopBrowser::CDesktopBrowser(): + m_hWndShellView(NULL), + m_hAccel(NULL) +{ }
CDesktopBrowser::~CDesktopBrowser() { - if (DesktopView.p != NULL) - { - if (hWndShellView != NULL) - DesktopView->DestroyViewWindow(); - - hWndShellView = NULL; - hWndDesktopListView = NULL; - } - - if (pidlDesktopDirectory != NULL) - { - ILFree(pidlDesktopDirectory); - pidlDesktopDirectory = NULL; - } - - if (pidlDesktop != NULL) - { - ILFree(pidlDesktop); - pidlDesktop = NULL; - } -} - -HRESULT CDesktopBrowser::Initialize(HWND hWndx, IShellDesktopTray *ShellDeskx) -{ - CComPtr<IShellFolder> psfDesktopFolder; - CSFV csfv; + if (m_ShellView.p != NULL && m_hWndShellView != NULL) + { + m_ShellView->DestroyViewWindow(); + } +} + +HRESULT CDesktopBrowser::Initialize(IShellDesktopTray *ShellDesk) +{ + CComPtr<IShellFolder> psfDesktop; HRESULT hRet; - - hWnd = hWndx; - ShellDesk = ShellDeskx; - ShellDesk->AddRef(); - - pidlDesktopDirectory = SHCloneSpecialIDList(hWnd, CSIDL_DESKTOPDIRECTORY, FALSE); - hRet = SHGetSpecialFolderLocation(hWnd, CSIDL_DESKTOP, &pidlDesktop); - if (FAILED(hRet)) + hRet = SHGetDesktopFolder(&psfDesktop); + if (FAILED_UNEXPECTEDLY(hRet)) return hRet;
- hRet = SHGetDesktopFolder(&psfDesktopFolder); - if (FAILED(hRet)) + /* Calculate the size and pos of the window */ + RECT rect; + if (!GetSystemMetrics(SM_CXVIRTUALSCREEN) || GetSystemMetrics(SM_CYVIRTUALSCREEN)) + { + SetRect(&rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + } + else + { + SetRect(&rect, + GetSystemMetrics(SM_XVIRTUALSCREEN), + GetSystemMetrics(SM_YVIRTUALSCREEN), + GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN), + GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN)); + } + + + m_Tray = ShellDesk; + + Create(NULL, &rect, szProgmanWindowName, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_TOOLWINDOW); + if (!m_hWnd) + return E_FAIL; + + CSFV csfv = {sizeof(CSFV), psfDesktop}; + hRet = SHCreateShellFolderViewEx(&csfv, &m_ShellView); + if (FAILED_UNEXPECTEDLY(hRet)) return hRet;
- ZeroMemory(&csfv, sizeof(csfv)); - csfv.cbSize = sizeof(csfv); - csfv.pshf = psfDesktopFolder; - csfv.psvOuter = NULL; - - hRet = SHCreateShellFolderViewEx(&csfv, &DesktopView); - - return hRet; -} - -static CDesktopBrowser *SHDESK_Create(HWND hWnd, LPCREATESTRUCT lpCreateStruct) -{ - CComPtr<IShellDesktopTray> ShellDesk; - CComObject<CDesktopBrowser> *pThis; - HRESULT hRet; - - ShellDesk = (IShellDesktopTray *)lpCreateStruct->lpCreateParams; - if (ShellDesk == NULL) - { - WARN("No IShellDesk interface provided!"); - return NULL; - } - - pThis = new CComObject<CDesktopBrowser>; - - pThis->AddRef(); - - hRet = pThis->Initialize(hWnd, ShellDesk); - if (FAILED(hRet)) - { - pThis->Release(); - delete pThis; - return NULL; - } - - return pThis; -} - -HWND CDesktopBrowser::FindDesktopListView() -{ - return FindWindowExW(hWndShellView, NULL, WC_LISTVIEW, NULL); -} - -BOOL CDesktopBrowser::CreateDeskWnd() -{ + m_Tray->RegisterDesktopWindow(m_hWnd); + if (FAILED_UNEXPECTEDLY(hRet)) + return hRet; + FOLDERSETTINGS fs; RECT rcWorkArea; - HRESULT hRet;
// FIXME: Add support for multi-monitor? - SystemParametersInfoW(SPI_GETWORKAREA, - 0, &rcWorkArea, 0); + SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
// TODO: Call GetClientRect for the tray window and make small computation // to be sure the tray window rect is removed from the work area! @@ -208,38 +161,39 @@ HWND hWndTray;
/* Get client rect of the taskbar */ - hRet = ShellDesk->GetTrayWindow(&hWndTray); + hRet = m_Tray->GetTrayWindow(&hWndTray); if (SUCCEEDED(hRet)) GetClientRect(hWndTray, &rcTray); #endif
fs.ViewMode = FVM_ICON; fs.fFlags = FWF_DESKTOP | FWF_NOCLIENTEDGE | FWF_NOSCROLL | FWF_TRANSPARENT; - hRet = DesktopView->CreateViewWindow(NULL, &fs, (IShellBrowser *)this, &rcWorkArea, &hWndShellView); - if (!SUCCEEDED(hRet)) - return FALSE; - - SetShellWindowEx(hWnd, FindDesktopListView()); + hRet = m_ShellView->CreateViewWindow(NULL, &fs, (IShellBrowser *)this, &rcWorkArea, &m_hWndShellView); + if (FAILED_UNEXPECTEDLY(hRet)) + return hRet; + + HWND hwndListView = FindWindowExW(m_hWndShellView, NULL, WC_LISTVIEW, NULL); + SetShellWindowEx(m_hWnd, hwndListView); + + m_hAccel = LoadAcceleratorsW(shell32_hInstance, MAKEINTRESOURCEW(IDA_DESKBROWSER));
#if 1 /* A Windows8+ specific hack */ - ::ShowWindow(hWndShellView, SW_SHOW); - ::ShowWindow(FindDesktopListView(), SW_SHOW); + ::ShowWindow(m_hWndShellView, SW_SHOW); + ::ShowWindow(hwndListView, SW_SHOW); #endif - - return TRUE; -} - -HRESULT STDMETHODCALLTYPE CDesktopBrowser::GetWindow(HWND *phwnd) -{ - if (hWnd != NULL) - { - *phwnd = hWnd; - return S_OK; - } - - *phwnd = NULL; - return E_UNEXPECTED; + ShowWindow(SW_SHOW); + UpdateWindow(); + + return hRet; +} + +HRESULT STDMETHODCALLTYPE CDesktopBrowser::GetWindow(HWND *lphwnd) +{ + if (lphwnd == NULL) + return E_POINTER; + *lphwnd = m_hWnd; + return S_OK; }
HRESULT STDMETHODCALLTYPE CDesktopBrowser::ContextSensitiveHelp(BOOL fEnterMode) @@ -274,7 +228,7 @@
HRESULT STDMETHODCALLTYPE CDesktopBrowser::TranslateAcceleratorSB(LPMSG lpmsg, WORD wID) { - if (!::TranslateAcceleratorW(hWnd, m_hAccel, lpmsg)) + if (!::TranslateAcceleratorW(m_hWnd, m_hAccel, lpmsg)) return S_FALSE; return S_OK; } @@ -294,62 +248,27 @@ return E_NOTIMPL; }
-HWND CDesktopBrowser::DesktopGetWindowControl(IN UINT id) -{ - switch (id) - { - case FCW_TOOLBAR: - case FCW_STATUS: - case FCW_TREE: - case FCW_PROGRESS: - return NULL; - - default: - return NULL; - } - -} - HRESULT STDMETHODCALLTYPE CDesktopBrowser::GetControlWindow(UINT id, HWND *lphwnd) { - HWND hWnd; - - hWnd = DesktopGetWindowControl(id); - if (hWnd != NULL) - { - *lphwnd = hWnd; - return S_OK; - } - - *lphwnd = NULL; + if (lphwnd == NULL) + return E_POINTER; return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE CDesktopBrowser::SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret) { - HWND hWnd; - if (pret == NULL) return E_POINTER; - - hWnd = DesktopGetWindowControl(id); - if (hWnd != NULL) - { - *pret = SendMessageW(hWnd, - uMsg, - wParam, - lParam); - return S_OK; - } - return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE CDesktopBrowser::QueryActiveShellView(IShellView **ppshv) { - *ppshv = DesktopView; - if (DesktopView != NULL) - DesktopView->AddRef(); + if (ppshv == NULL) + return E_POINTER; + *ppshv = m_ShellView; + if (m_ShellView != NULL) + m_ShellView->AddRef();
return S_OK; } @@ -362,21 +281,6 @@ HRESULT STDMETHODCALLTYPE CDesktopBrowser::SetToolbarItems(LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags) { return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CDesktopBrowser::OnDefaultCommand(IShellView *ppshv) -{ - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CDesktopBrowser::OnStateChange(IShellView *ppshv, ULONG uChange) -{ - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CDesktopBrowser::IncludeObject(IShellView *ppshv, LPCITEMIDLIST pidl) -{ - return S_OK; }
HRESULT STDMETHODCALLTYPE CDesktopBrowser::QueryService(REFGUID guidService, REFIID riid, PVOID *ppv) @@ -385,40 +289,19 @@ return QueryInterface(riid, ppv); }
-BOOL CDesktopBrowser::MessageLoop() -{ - MSG Msg; - BOOL bRet; - - while ((bRet = GetMessageW(&Msg, NULL, 0, 0)) != 0) - { - if (bRet != -1) - { - if (DesktopView->TranslateAcceleratorW(&Msg) != S_OK) - { - TranslateMessage(&Msg); - DispatchMessage(&Msg); - } - } - } - - return TRUE; -} - LRESULT CDesktopBrowser::_NotifyTray(UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hWndTray; HRESULT hRet;
- hRet = ShellDesk->GetTrayWindow(&hWndTray); - + hRet = m_Tray->GetTrayWindow(&hWndTray); if (SUCCEEDED(hRet)) - PostMessageW(hWndTray, uMsg, wParam, lParam); - - return 0; -} - -LRESULT CDesktopBrowser::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam) + ::PostMessageW(hWndTray, uMsg, wParam, lParam); + + return 0; +} + +LRESULT CDesktopBrowser::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { switch (LOWORD(wParam)) { @@ -439,217 +322,102 @@ return 0; }
-LRESULT CALLBACK CDesktopBrowser::ProgmanWindowProc(IN HWND hwnd, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam) -{ - CDesktopBrowser *pThis = NULL; - LRESULT Ret = FALSE; - - if (uMsg != WM_NCCREATE) - { - pThis = reinterpret_cast<CDesktopBrowser *>(GetWindowLongPtrW(hwnd, 0)); - if (pThis == NULL) - goto DefMsgHandler; - } - - if (pThis != NULL || uMsg == WM_NCCREATE) - { - switch (uMsg) - { - case WM_ERASEBKGND: - return (LRESULT)PaintDesktop((HDC)wParam); - - case WM_GETISHELLBROWSER: - Ret = (LRESULT)((IShellBrowser *)pThis); - break; - - case WM_SIZE: - { - if (wParam == SIZE_MINIMIZED) - { - /* Hey, we're the desktop!!! */ - ShowWindow(hwnd, SW_RESTORE); - } - else - { - RECT rcDesktop; - - rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN); - rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN); - rcDesktop.right = GetSystemMetrics(SM_CXVIRTUALSCREEN); - rcDesktop.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN); - - /* FIXME: Update work area */ - DBG_UNREFERENCED_LOCAL_VARIABLE(rcDesktop); - } - break; - } - - case WM_SYSCOLORCHANGE: - case WM_SETTINGCHANGE: - { - if (pThis->hWndShellView != NULL) - { - /* Forward the message */ - SendMessageW(pThis->hWndShellView, - uMsg, - wParam, - lParam); - } - - if (uMsg == WM_SETTINGCHANGE && wParam == SPI_SETWORKAREA && - pThis->hWndShellView != NULL) - { - RECT rcWorkArea; - - // FIXME: Add support for multi-monitor! - // FIXME: Maybe merge with the code that retrieves the - // work area in CDesktopBrowser::CreateDeskWnd ? - SystemParametersInfoW(SPI_GETWORKAREA, - 0, &rcWorkArea, 0); - - SetWindowPos(pThis->hWndShellView, NULL, - rcWorkArea.left, rcWorkArea.top, - rcWorkArea.right - rcWorkArea.left, - rcWorkArea.bottom - rcWorkArea.top, - SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER); - } - break; - } - - case WM_CREATE: - { - pThis->ShellDesk->RegisterDesktopWindow(pThis->hWnd); - - if (!pThis->CreateDeskWnd()) - WARN("Could not create the desktop view control!\n"); - - pThis->m_hAccel = LoadAcceleratorsW(shell32_hInstance, MAKEINTRESOURCEW(IDA_DESKBROWSER)); - - break; - } - - case WM_NCCREATE: - { - LPCREATESTRUCT CreateStruct = (LPCREATESTRUCT)lParam; - - // FIXME: This is a "hack" to enforce the window title - // to be set to what it should be *on Windows* only. - // I don't understand why it is reset to NULL whereas - // the creation of the progman window proper is done in - // the standard way... (05/06/2016, hbelusca). - // - ::SetWindowTextW(hwnd, CreateStruct->lpszName); - - pThis = SHDESK_Create(hwnd, CreateStruct); - if (pThis == NULL) - { - WARN("Failed to create desktop structure\n"); - break; - } - - SetWindowLongPtrW(hwnd, 0, (LONG_PTR)pThis); - Ret = TRUE; - break; - } - - case WM_NCDESTROY: - { - pThis->Release(); - break; - } - - case WM_CLOSE: - return pThis->_NotifyTray(TWM_DOEXITWINDOWS, 0, 0); - - case WM_EXPLORER_OPEN_NEW_WINDOW: - TRACE("Proxy Desktop message 1035 received.\n"); - SHOnCWMCommandLine((HANDLE)lParam); - break; - - case WM_COMMAND: - return pThis->OnCommand(uMsg, wParam, lParam); - - case WM_SETFOCUS: - SetFocus(pThis->hWndShellView); - break; - - default: -DefMsgHandler: - Ret = DefWindowProcW(hwnd, uMsg, wParam, lParam); - break; - } - } - - return Ret; -} - -static BOOL -RegisterProgmanWindowClass(VOID) -{ - WNDCLASSW wcProgman; - - wcProgman.style = CS_DBLCLKS; - wcProgman.lpfnWndProc = CDesktopBrowser::ProgmanWindowProc; - wcProgman.cbClsExtra = 0; - wcProgman.cbWndExtra = sizeof(CDesktopBrowser *); - wcProgman.hInstance = shell32_hInstance; - wcProgman.hIcon = NULL; - wcProgman.hCursor = LoadCursorW(NULL, IDC_ARROW); - wcProgman.hbrBackground = (HBRUSH)(COLOR_DESKTOP + 1); - wcProgman.lpszMenuName = NULL; - wcProgman.lpszClassName = szProgmanClassName; - - return RegisterClassW(&wcProgman) != 0; -} - + +LRESULT CDesktopBrowser::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + return (LRESULT)PaintDesktop((HDC)wParam); +} + +LRESULT CDesktopBrowser::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + if (wParam == SIZE_MINIMIZED) + { + /* Hey, we're the desktop!!! */ + ::ShowWindow(m_hWnd, SW_RESTORE); + } + else + { + RECT rcDesktop; + rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN); + rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN); + rcDesktop.right = GetSystemMetrics(SM_CXVIRTUALSCREEN); + rcDesktop.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN); + + /* FIXME: Update work area */ + DBG_UNREFERENCED_LOCAL_VARIABLE(rcDesktop); + } + + return 0; +} + +LRESULT CDesktopBrowser::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + if (m_hWndShellView) + { + /* Forward the message */ + SendMessageW(m_hWndShellView, uMsg, wParam, lParam); + } + + if (uMsg == WM_SETTINGCHANGE && wParam == SPI_SETWORKAREA && + m_hWndShellView != NULL) + { + RECT rcWorkArea; + + // FIXME: Add support for multi-monitor! + // FIXME: Maybe merge with the code that retrieves the + // work area in CDesktopBrowser::CreateDeskWnd ? + SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + + ::SetWindowPos(m_hWndShellView, NULL, + rcWorkArea.left, rcWorkArea.top, + rcWorkArea.right - rcWorkArea.left, + rcWorkArea.bottom - rcWorkArea.top, + SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER); + } + return 0; +} + +LRESULT CDesktopBrowser::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + return _NotifyTray(TWM_DOEXITWINDOWS, 0, 0); +} + +LRESULT CDesktopBrowser::OnOpenNewWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + TRACE("Proxy Desktop message 1035 received.\n"); + SHOnCWMCommandLine((HANDLE)lParam); + return 0; +} + +LRESULT CDesktopBrowser::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) +{ + ::SetFocus(m_hWndShellView); + return 0; +} + +HRESULT CDesktopBrowser_CreateInstance(IShellDesktopTray *Tray, REFIID riid, void **ppv) +{ + return ShellObjectCreatorInit<CDesktopBrowser, IShellDesktopTray*>(Tray, riid, ppv); +}
/************************************************************************* * SHCreateDesktop [SHELL32.200] * */ -HANDLE WINAPI SHCreateDesktop(IShellDesktopTray *ShellDesk) -{ - HWND hWndDesk; - int x, y, cx, cy; - - if (ShellDesk == NULL) +HANDLE WINAPI SHCreateDesktop(IShellDesktopTray *Tray) +{ + if (Tray == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return NULL; }
- if (RegisterProgmanWindowClass() == 0) - { - WARN("Failed to register the Progman window class!\n"); + CComPtr<IShellBrowser> Browser; + HRESULT hr = CDesktopBrowser_CreateInstance(Tray, IID_PPV_ARG(IShellBrowser, &Browser)); + if (FAILED_UNEXPECTEDLY(hr)) return NULL; - } - - x = GetSystemMetrics(SM_XVIRTUALSCREEN); - y = GetSystemMetrics(SM_YVIRTUALSCREEN); - cx = GetSystemMetrics(SM_CXVIRTUALSCREEN); - cy = GetSystemMetrics(SM_CYVIRTUALSCREEN); - - if (!cx || !cy) - { - x = y = 0; - cx = GetSystemMetrics(SM_CXSCREEN); - cy = GetSystemMetrics(SM_CYSCREEN); - } - - hWndDesk = ::CreateWindowExW(WS_EX_TOOLWINDOW, szProgmanClassName, szProgmanWindowName, - WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - x, y, cx, cy, - NULL, NULL, shell32_hInstance, (LPVOID)ShellDesk); - - if (hWndDesk != NULL) - { - ::ShowWindow(hWndDesk, SW_SHOW); - ::UpdateWindow(hWndDesk); - - return (HANDLE)GetWindowLongPtrW(hWndDesk, 0); - } - - return NULL; + + return static_cast<HANDLE>(Browser.Detach()); }
/************************************************************************* @@ -658,13 +426,34 @@ */ BOOL WINAPI SHDesktopMessageLoop(HANDLE hDesktop) { - CDesktopBrowser *Desk = static_cast<CDesktopBrowser *>(hDesktop); - - if (Desk == NULL || Desk->Tag != SHDESK_TAG) + if (hDesktop == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
- return Desk->MessageLoop(); -} + MSG Msg; + BOOL bRet; + + CComPtr<IShellBrowser> browser; + CComPtr<IShellView> shellView; + + browser.Attach(static_cast<IShellBrowser*>(hDesktop)); + HRESULT hr = browser->QueryActiveShellView(&shellView); + if (FAILED_UNEXPECTEDLY(hr)) + return FALSE; + + while ((bRet = GetMessageW(&Msg, NULL, 0, 0)) != 0) + { + if (bRet != -1) + { + if (shellView->TranslateAcceleratorW(&Msg) != S_OK) + { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + } + } + + return TRUE; +}