2 Desktop creation example
4 Silver Blade (silverblade_uk@hotmail.com)
11 #include "externals.h"
20 /* GetShellWindow is already present in the header files
21 static HWND (WINAPI*GetShellWindow)(); */
22 static BOOL (WINAPI*SetShellWindow)(HWND);
25 BOOL IsAnyDesktopRunning()
28 HINSTANCE shell32 = GetModuleHandle(TEXT("user32"));
30 SetShellWindow = (BOOL(WINAPI*)(HWND)) GetProcAddress(shell32, "SetShellWindow");
32 /* GetShellWindow is already present in the header files
33 GetShellWindow = (HWND(WINAPI*)()) GetProcAddress(shell32, "GetShellWindow");
35 if (GetShellWindow) */
36 return GetShellWindow() != 0;
41 return WindowFromPoint(pt) != GetDesktopWindow(); */
45 LRESULT CALLBACK DeskWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
51 // Over-ride close. We need to close desktop some other way.
57 // We'd want to draw the desktop wallpaper here. Need to
58 // maintain a copy of the wallpaper in an off-screen DC and then
59 // bitblt (or stretchblt?) it to the screen appropriately. For
60 // now, though, we'll just draw some text.
63 HDC DesktopDC = BeginPaint(hwnd, &ps);
65 TCHAR Text [] = TEXT("ReactOS 0.1.2 Desktop Example\nby Silver Blade");
69 Width = GetSystemMetrics(SM_CXSCREEN);
70 Height = GetSystemMetrics(SM_CYSCREEN);
72 // This next part could be improved by working out how much
73 // space the text actually needs...
79 r.right = r.left + 250;
80 r.bottom = r.top + 40;
82 SetTextColor(DesktopDC, 0x00ffffff);
83 SetBkMode(DesktopDC, TRANSPARENT);
84 DrawText(DesktopDC, Text, -1, &r, DT_RIGHT);
92 case WM_LBUTTONDBLCLK:
93 explorer_show_frame(hwnd, SW_SHOWNORMAL);
102 return DefWindowProc(hwnd, uMsg, wParam, lParam);
109 const TCHAR DesktopClassName[] = TEXT("DesktopWindow");
112 HWND create_desktop_window(HINSTANCE hInstance)
118 wc.cbSize = sizeof(WNDCLASSEX);
119 wc.style = CS_DBLCLKS;
120 wc.lpfnWndProc = &DeskWndProc;
123 wc.hInstance = hInstance;
124 wc.hIcon = LoadIcon(0, IDI_APPLICATION);
125 wc.hCursor = LoadCursor(0, IDC_ARROW);
126 wc.hbrBackground= (HBRUSH) GetStockObject(BLACK_BRUSH);
127 wc.lpszMenuName = NULL;
128 wc.lpszClassName= DesktopClassName;
131 if (!RegisterClassEx(&wc))
134 Width = GetSystemMetrics(SM_CXSCREEN);
135 Height = GetSystemMetrics(SM_CYSCREEN);
137 hwndDesktop = CreateWindowEx(0, DesktopClassName, TEXT("Desktop"),
138 WS_VISIBLE | WS_POPUP | WS_CLIPCHILDREN,
140 NULL, NULL, hInstance, NULL);
143 SetShellWindow(hwndDesktop);
150 int main(int argc, char *argv[])
152 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
156 HWND hwndDesktop = 0;
159 STARTUPINFO startupinfo;
160 int nShowCmd = SW_SHOWNORMAL;
162 HINSTANCE hInstance = GetModuleHandle(NULL);
165 // create desktop window and task bar only, if there is no other shell and we are
166 // the first explorer instance (just in case SetShellWindow() is not supported by the OS)
167 BOOL startup_desktop = !IsAnyDesktopRunning() && !find_window_class(DesktopClassName);
170 if (argc>1 && !strcmp(argv[1],"-desktop"))
172 if (!lstrcmp(lpCmdLine,TEXT("-desktop")))
174 startup_desktop = TRUE;
178 HWND hwndExplorerBar;
180 hwndDesktop = create_desktop_window(hInstance);
184 fprintf(stderr,"FATAL: Desktop window could not be initialized properly - Exiting.\n");
189 // call winefile startup routine
190 GetStartupInfo(&startupinfo);
192 if (startupinfo.dwFlags & STARTF_USESHOWWINDOW)
193 nShowCmd = startupinfo.wShowWindow;
196 // Initializing the Explorer Bar
197 if (!(hwndExplorerBar=InitializeExplorerBar(hInstance)))
199 fprintf(stderr,"FATAL: Explorer bar could not be initialized properly ! Exiting !\n");
204 if (!LoadAvailablePlugIns(hwndExplorerBar))
206 fprintf(stderr,"WARNING: No plugin for desktop bar could be loaded.\n");
209 #ifndef _DEBUG //MF: disabled for debugging
211 startup(argc, argv); // invoke the startup groups
221 ret = explorer_main(hInstance, hwndDesktop, nShowCmd);
223 ReleaseAvailablePlugIns();