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"
36 #include "../shell/mainframe.h" // for MainFrame::Create()
38 #include "../externals.h"
39 #include "../explorer_intres.h"
42 static BOOL (WINAPI
*SetShellWindow
)(HWND
);
43 static BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
46 BOOL
IsAnyDesktopRunning()
48 HINSTANCE shell32
= GetModuleHandle(_T("user32"));
50 SetShellWindow
= (BOOL(WINAPI
*)(HWND
)) GetProcAddress(shell32
, "SetShellWindow");
51 SetShellWindowEx
= (BOOL(WINAPI
*)(HWND
,HWND
)) GetProcAddress(shell32
, "SetShellWindowEx");
53 return GetShellWindow() != 0;
57 static void draw_desktop_background(HWND hwnd
, HDC hdc
)
59 ClientRect
rect(hwnd
);
63 HBRUSH bkgndBrush = CreateSolidBrush(RGB(0,32,160)); // dark blue
64 FillRect(hdc, &rect, bkgndBrush);
65 DeleteBrush(bkgndBrush);
68 rect
.left
= rect
.right
- 280;
69 rect
.top
= rect
.bottom
- 56 - DESKTOPBARBAR_HEIGHT
;
70 rect
.right
= rect
.left
+ 250;
71 rect
.bottom
= rect
.top
+ 40;
73 #include "../buildno.h"
74 static const LPCTSTR BkgndText
= _T("ReactOS ")_T(KERNEL_VERSION_STR
)_T(" Explorer\nby Martin Fuchs");
76 BkMode
bkMode(hdc
, TRANSPARENT
);
78 TextColor
textColor(hdc
, RGB(128,128,192));
79 DrawText(hdc
, BkgndText
, -1, &rect
, DT_RIGHT
);
81 SetTextColor(hdc
, RGB(255,255,255));
84 DrawText(hdc
, BkgndText
, -1, &rect
, DT_RIGHT
);
88 LRESULT
BackgroundWindow::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
92 PaintDesktop((HDC
)wparam
);
95 case WM_MBUTTONDBLCLK
:
96 explorer_show_frame(_hwnd
, SW_SHOWNORMAL
);
100 return super::WndProc(nmsg
, wparam
, lparam
);
107 DesktopWindow::DesktopWindow(HWND hwnd
)
113 DesktopWindow::~DesktopWindow()
116 _pShellView
->Release();
120 HWND
DesktopWindow::Create()
122 IconWindowClass
wcDesktop(_T("Progman"), IDI_REACTOS
, CS_DBLCLKS
);
123 wcDesktop
.hbrBackground
= (HBRUSH
)(COLOR_BACKGROUND
+1);
125 int width
= GetSystemMetrics(SM_CXSCREEN
);
126 int height
= GetSystemMetrics(SM_CYSCREEN
);
128 HWND hwndDesktop
= Window::Create(WINDOW_CREATOR(DesktopWindow
),
129 WS_EX_TOOLWINDOW
, wcDesktop
, _T("Program Manager"), WS_POPUP
|WS_VISIBLE
|WS_CLIPCHILDREN
,
130 0, 0, width
, height
, 0);
132 // work around to display desktop bar in Wine
133 ShowWindow(GET_WINDOW(DesktopWindow
, hwndDesktop
)->_desktopBar
, SW_SHOW
);
135 // work around for Windows NT, Win 98, ...
136 // Without this the desktop has mysteriously only a size of 800x600 pixels.
137 MoveWindow(hwndDesktop
, 0, 0, width
, height
, TRUE
);
143 LRESULT
DesktopWindow::Init(LPCREATESTRUCT pcs
)
145 if (super::Init(pcs
))
148 HRESULT hr
= Desktop()->CreateViewObject(_hwnd
, IID_IShellView
, (void**)&_pShellView
);
150 SFV_CREATE sfv_create;
152 sfv_create.cbSize = sizeof(SFV_CREATE);
153 sfv_create.pshf = Desktop();
154 sfv_create.psvOuter = NULL;
155 sfv_create.psfvcb = NULL;
157 HRESULT hr = SHCreateShellFolderView(&sfv_create, &_pShellView);
164 fs
.ViewMode
= FVM_ICON
;
165 fs
.fFlags
= FWF_DESKTOP
|FWF_NOCLIENTEDGE
|FWF_NOSCROLL
|FWF_BESTFITWINDOW
|FWF_SNAPTOGRID
;
167 ClientRect
rect(_hwnd
);
169 hr
= _pShellView
->CreateViewWindow(NULL
, &fs
, this, &rect
, &hWndView
);
171 //TODO: use IShellBrowser::GetViewStateStream() to restore previous view state -> see SHOpenRegStream()
174 _pShellView
->UIActivate(SVUIA_ACTIVATE_FOCUS
);
177 IShellView2* pShellView2;
179 hr = _pShellView->QueryInterface(IID_IShellView2, (void**)&pShellView2);
181 SV2CVW2_PARAMS params;
182 params.cbSize = sizeof(SV2CVW2_PARAMS);
183 params.psvPrev = _pShellView;
185 params.psbOwner = this;
186 params.prcView = ▭
187 params.pvid = params.pvid;//@@
189 hr = pShellView2->CreateViewWindow2(¶ms);
194 IFolderView* pFolderView;
196 hr = _pShellView->QueryInterface(IID_IFolderView, (void**)&pFolderView);
199 hr = pFolderView->GetAutoArrange();
200 hr = pFolderView->SetCurrentViewMode(FVM_DETAILS);
204 HWND hwndFolderView
= ::GetNextWindow(hWndView
, GW_CHILD
);
206 // work around for Windows NT, Win 98, ...
207 // Without this the desktop has mysteriously only a size of 800x600 pixels.
208 MoveWindow(hwndFolderView
, 0, 0, rect
.right
, rect
.bottom
, TRUE
);
210 new BackgroundWindow(hwndFolderView
);
214 if (hWndView
&& SetShellWindowEx
)
215 SetShellWindowEx(_hwnd
, hWndView
);
216 else if (SetShellWindow
)
217 SetShellWindow(_hwnd
);
219 // create the explorer bar
220 _desktopBar
= DesktopBar::Create();
226 LRESULT
DesktopWindow::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
230 draw_desktop_background(_hwnd
, PaintCanvas(_hwnd
));
233 case WM_LBUTTONDBLCLK
:
234 case WM_RBUTTONDBLCLK
:
235 case WM_MBUTTONDBLCLK
:
236 explorer_show_frame(_hwnd
, SW_SHOWNORMAL
);
239 case WM_GETISHELLBROWSER
:
240 return (LRESULT
)static_cast<IShellBrowser
*>(this);
244 //TODO: use IShellBrowser::GetViewStateStream() and _pShellView->SaveViewState() to store view state
251 break; // Over-ride close. We need to close desktop some other way.
254 if (wparam
== SC_TASKLIST
) {
256 SendMessage(_desktopBar
, nmsg
, wparam
, lparam
);
261 return super::WndProc(nmsg
, wparam
, lparam
);
268 HRESULT
DesktopWindow::OnDefaultCommand(LPIDA pIDList
)
270 if (MainFrame::OpenShellFolders(pIDList
, 0))