2 * Copyright 2003 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 09.08.2003
29 #include "../utility/utility.h"
30 #include "../utility/shellclasses.h"
31 #include "../utility/shellbrowserimpl.h"
32 #include "../utility/window.h"
35 #include "../taskbar/desktopbar.h"
37 #include "../externals.h"
38 #include "../explorer_intres.h"
41 static BOOL (WINAPI*SetShellWindow)(HWND);
42 static BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
45 BOOL IsAnyDesktopRunning()
47 HINSTANCE shell32 = GetModuleHandle(_T("user32"));
49 SetShellWindow = (BOOL(WINAPI*)(HWND)) GetProcAddress(shell32, "SetShellWindow");
50 SetShellWindowEx = (BOOL(WINAPI*)(HWND,HWND)) GetProcAddress(shell32, "SetShellWindowEx");
52 return GetShellWindow() != 0;
56 static void draw_desktop_background(HWND hwnd, HDC hdc)
58 ClientRect rect(hwnd);
62 HBRUSH bkgndBrush = CreateSolidBrush(RGB(0,32,160)); // dark blue
63 FillRect(hdc, &rect, bkgndBrush);
64 DeleteBrush(bkgndBrush);
67 rect.left = rect.right - 280;
68 rect.top = rect.bottom - 56 - DESKTOPBARBAR_HEIGHT;
69 rect.right = rect.left + 250;
70 rect.bottom = rect.top + 40;
72 #include "../buildno.h"
73 static const LPCTSTR BkgndText = _T("ReactOS ")_T(KERNEL_VERSION_STR)_T(" Explorer\nby Martin Fuchs");
75 BkMode bkMode(hdc, TRANSPARENT);
77 TextColor textColor(hdc, RGB(128,128,192));
78 DrawText(hdc, BkgndText, -1, &rect, DT_RIGHT);
80 SetTextColor(hdc, RGB(255,255,255));
83 DrawText(hdc, BkgndText, -1, &rect, DT_RIGHT);
87 LRESULT BackgroundWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
91 PaintDesktop((HDC)wparam);
94 case WM_MBUTTONDBLCLK:
95 explorer_show_frame(_hwnd, SW_SHOWNORMAL);
99 return super::WndProc(nmsg, wparam, lparam);
106 DesktopWindow::DesktopWindow(HWND hwnd)
112 DesktopWindow::~DesktopWindow()
115 _pShellView->Release();
119 HWND DesktopWindow::Create()
121 IconWindowClass wcDesktop(_T("Progman"), IDI_REACTOS, CS_DBLCLKS);
122 wcDesktop.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
124 int width = GetSystemMetrics(SM_CXSCREEN);
125 int height = GetSystemMetrics(SM_CYSCREEN);
127 HWND hwndDesktop = Window::Create(WINDOW_CREATOR(DesktopWindow),
128 WS_EX_TOOLWINDOW, wcDesktop, _T("Program Manager"), WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN,
129 0, 0, width, height, 0);
131 // work around to display desktop bar in Wine
132 ShowWindow(GET_WINDOW(DesktopWindow, hwndDesktop)->_desktopBar, SW_SHOW);
134 // work around for Windows NT, Win 98, ...
135 // Without this the desktop has mysteriously only a size of 800x600 pixels.
136 MoveWindow(hwndDesktop, 0, 0, width, height, TRUE);
142 LRESULT DesktopWindow::Init(LPCREATESTRUCT pcs)
144 if (super::Init(pcs))
147 HRESULT hr = Desktop()->CreateViewObject(_hwnd, IID_IShellView, (void**)&_pShellView);
149 SFV_CREATE sfv_create;
151 sfv_create.cbSize = sizeof(SFV_CREATE);
152 sfv_create.pshf = Desktop();
153 sfv_create.psvOuter = NULL;
154 sfv_create.psfvcb = NULL;
156 HRESULT hr = SHCreateShellFolderView(&sfv_create, &_pShellView);
163 fs.ViewMode = FVM_ICON;
164 fs.fFlags = FWF_DESKTOP|FWF_NOCLIENTEDGE|FWF_NOSCROLL|FWF_BESTFITWINDOW|FWF_SNAPTOGRID;
166 ClientRect rect(_hwnd);
168 hr = _pShellView->CreateViewWindow(NULL, &fs, this, &rect, &hWndView);
170 //TODO: use IShellBrowser::GetViewStateStream() to restore previous view state -> see SHOpenRegStream()
173 _pShellView->UIActivate(SVUIA_ACTIVATE_FOCUS);
176 IShellView2* pShellView2;
178 hr = _pShellView->QueryInterface(IID_IShellView2, (void**)&pShellView2);
180 SV2CVW2_PARAMS params;
181 params.cbSize = sizeof(SV2CVW2_PARAMS);
182 params.psvPrev = _pShellView;
184 params.psbOwner = this;
185 params.prcView = ▭
186 params.pvid = params.pvid;//@@
188 hr = pShellView2->CreateViewWindow2(¶ms);
193 IFolderView* pFolderView;
195 hr = _pShellView->QueryInterface(IID_IFolderView, (void**)&pFolderView);
198 hr = pFolderView->GetAutoArrange();
199 hr = pFolderView->SetCurrentViewMode(FVM_DETAILS);
203 HWND hwndFolderView = ::GetNextWindow(hWndView, GW_CHILD);
205 // work around for Windows NT, Win 98, ...
206 // Without this the desktop has mysteriously only a size of 800x600 pixels.
207 MoveWindow(hwndFolderView, 0, 0, rect.right, rect.bottom, TRUE);
209 new BackgroundWindow(hwndFolderView);
213 if (hWndView && SetShellWindowEx)
214 SetShellWindowEx(_hwnd, hWndView);
215 else if (SetShellWindow)
216 SetShellWindow(_hwnd);
218 // create the explorer bar
219 _desktopBar = DesktopBar::Create();
225 LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
229 draw_desktop_background(_hwnd, PaintCanvas(_hwnd));
232 case WM_LBUTTONDBLCLK:
233 case WM_RBUTTONDBLCLK:
234 case WM_MBUTTONDBLCLK:
235 explorer_show_frame(_hwnd, SW_SHOWNORMAL);
238 case WM_GETISHELLBROWSER:
239 return (LRESULT)static_cast<IShellBrowser*>(this);
243 //TODO: use IShellBrowser::GetViewStateStream() and _pShellView->SaveViewState() to store view state
250 break; // Over-ride close. We need to close desktop some other way.
253 if (wparam == SC_TASKLIST) {
255 SendMessage(_desktopBar, nmsg, wparam, lparam);
260 return super::WndProc(nmsg, wparam, lparam);