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
31 #include "../externals.h"
34 static BOOL (WINAPI
*SetShellWindow
)(HWND
);
35 static BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
38 BOOL
IsAnyDesktopRunning()
40 HINSTANCE shell32
= GetModuleHandle(TEXT("user32"));
42 SetShellWindow
= (BOOL(WINAPI
*)(HWND
)) GetProcAddress(shell32
, "SetShellWindow");
43 SetShellWindowEx
= (BOOL(WINAPI
*)(HWND
,HWND
)) GetProcAddress(shell32
, "SetShellWindowEx");
45 return GetShellWindow() != 0;
49 DesktopWindow::DesktopWindow(HWND hwnd
)
55 DesktopWindow::~DesktopWindow()
58 _pShellView
->Release();
62 LRESULT
DesktopWindow::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
66 // We'd want to draw the desktop wallpaper here. Need to
67 // maintain a copy of the wallpaper in an off-screen DC and then
68 // bitblt (or stretchblt?) it to the screen appropriately. For
69 // now, though, we'll just draw some text.
72 HDC DesktopDC
= BeginPaint(_hwnd
, &ps
);
74 static const TCHAR Text
[] = TEXT("ReactOS 0.1.2 Desktop Example\nby Silver Blade, Martin Fuchs");
77 GetClientRect(_hwnd
, &rect
);
79 // This next part could be improved by working out how much
80 // space the text actually needs...
82 rect
.left
= rect
.right
- 260;
83 rect
.top
= rect
.bottom
- 80;
84 rect
.right
= rect
.left
+ 250;
85 rect
.bottom
= rect
.top
+ 40;
87 SetTextColor(DesktopDC
, 0x00ffffff);
88 SetBkMode(DesktopDC
, TRANSPARENT
);
89 DrawText(DesktopDC
, Text
, -1, &rect
, DT_RIGHT
);
94 case WM_LBUTTONDBLCLK
:
95 explorer_show_frame(_hwnd
, SW_SHOWNORMAL
);
98 case WM_GETISHELLBROWSER
:
99 return (LRESULT
)static_cast<IShellBrowser
*>(this);
102 HRESULT hr
= Desktop()->CreateViewObject(_hwnd
, IID_IShellView
, (void**)&_pShellView
);
104 HWND hWndListView
= 0;
109 fs
.ViewMode
= FWF_DESKTOP
|FWF_TRANSPARENT
|FWF_NOSUBFOLDERS
|FWF_BESTFITWINDOW
|FWF_ABBREVIATEDNAMES
;
110 fs
.fFlags
= FVM_ICON
;
113 GetClientRect(_hwnd
, &rect
);
115 hr
= _pShellView
->CreateViewWindow(NULL
, &fs
, this, &rect
, &hWndListView
);
118 HWND hwndFolderView
= ::GetNextWindow(hWndListView
, GW_CHILD
);
120 ShowWindow(hwndFolderView
, SW_SHOW
);
124 if (hWndListView
&& SetShellWindowEx
)
125 SetShellWindowEx(_hwnd
, hWndListView
);
126 else if (SetShellWindow
)
127 SetShellWindow(_hwnd
);
136 break; // Over-ride close. We need to close desktop some other way.
139 return super::WndProc(nmsg
, wparam
, lparam
);
146 HWND
create_desktop_window(HINSTANCE hInstance
)
148 WindowClass
wcDesktop(_T("Program Manager"));
150 wcDesktop
.style
= CS_DBLCLKS
;
151 wcDesktop
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
152 wcDesktop
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
153 wcDesktop
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
156 ATOM desktopClass
= wcDesktop
.Register();
158 int width
= GetSystemMetrics(SM_CXSCREEN
);
159 int height
= GetSystemMetrics(SM_CYSCREEN
);
161 return Window::Create(WINDOW_CREATOR(DesktopWindow
),
162 0, (LPCTSTR
)(int)desktopClass
, _T("Progman"), WS_POPUP
|WS_VISIBLE
|WS_CLIPCHILDREN
,
163 0, 0, width
, height
, 0);