Added logo in start menu.
[reactos.git] / reactos / subsys / system / explorer / explorer.cpp
1 /*
2 * Copyright 2003 Martin Fuchs
3 *
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.
8 *
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.
13 *
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
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // explorer.cpp
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27 // Credits: Thanks to Leon Finker for his explorer window example
28 //
29
30
31 #include "utility/utility.h"
32
33 #include "explorer.h"
34 #include "desktop/desktop.h"
35
36 #include "globals.h"
37 #include "externals.h"
38
39 #include "explorer_intres.h"
40
41
42 ExplorerGlobals g_Globals;
43
44
45 ExplorerGlobals::ExplorerGlobals()
46 {
47 _hInstance = 0;
48 _hframeClass = 0;
49 _cfStrFName = 0;
50 _hMainWnd = 0;
51 _prescan_nodes = false;
52 _desktop_mode = false;
53 }
54
55
56 ResString::ResString(UINT nid)
57 {
58 TCHAR buffer[BUFFER_LEN];
59
60 int len = LoadString(g_Globals._hInstance, nid, buffer, sizeof(buffer)/sizeof(TCHAR));
61
62 assign(buffer, len);
63 }
64
65
66 ResIcon::ResIcon(UINT nid)
67 {
68 _hIcon = LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(nid));
69 }
70
71 SmallIcon::SmallIcon(UINT nid)
72 {
73 _hIcon = (HICON)LoadImage(g_Globals._hInstance, MAKEINTRESOURCE(nid), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
74 }
75
76
77 ResBitmap::ResBitmap(UINT nid)
78 {
79 _hBmp = LoadBitmap(g_Globals._hInstance, MAKEINTRESOURCE(nid));
80 }
81
82
83 void explorer_show_frame(HWND hwndDesktop, int cmdshow)
84 {
85 if (g_Globals._hMainWnd)
86 return;
87
88 g_Globals._prescan_nodes = false;
89
90 // create main window
91 g_Globals._hMainWnd = MainFrame::Create();
92
93 ShowWindow(g_Globals._hMainWnd, cmdshow);
94
95 UpdateWindow(g_Globals._hMainWnd);
96
97 // Open the first child window after initialiszing the whole application
98 PostMessage(g_Globals._hMainWnd, PM_OPEN_WINDOW, 0, 0);
99 }
100
101
102 static void InitInstance(HINSTANCE hInstance)
103 {
104 setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName
105
106 // register frame window class
107 g_Globals._hframeClass = IconWindowClass(CLASSNAME_FRAME,IDI_EXPLORER);
108
109 // register child windows class
110 WindowClass(CLASSNAME_CHILDWND, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
111
112 // register tree windows class
113 WindowClass(CLASSNAME_WINEFILETREE, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
114
115 g_Globals._cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
116 }
117
118
119 int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow)
120 {
121 // initialize COM and OLE
122 OleInit usingCOM;
123
124 // initialize Common Controls library
125 CommonControlInit usingCmnCtrl;
126
127 try {
128 InitInstance(hInstance);
129 } catch(COMException& e) {
130 HandleException(e, g_Globals._hMainWnd);
131 return -1;
132 }
133
134 if (hwndDesktop)
135 g_Globals._desktop_mode = true;
136
137 if (cmdshow != SW_HIDE) {
138 #ifndef _ROS_ // don't maximize if being called from the ROS desktop
139 if (cmdshow == SW_SHOWNORMAL)
140 /*TODO: read window placement from registry */
141 cmdshow = SW_MAXIMIZE;
142 #endif
143
144 explorer_show_frame(hwndDesktop, cmdshow);
145 }
146
147 return Window::MessageLoop();
148 }
149
150
151 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
152 {
153 // create desktop window and task bar only, if there is no other shell and we are
154 // the first explorer instance
155 BOOL startup_desktop = !IsAnyDesktopRunning();
156
157 // If there is given the command line option "-desktop", create desktop window anyways
158 if (!lstrcmp(lpCmdLine,TEXT("-desktop")))
159 startup_desktop = TRUE;
160
161 if (!lstrcmp(lpCmdLine,TEXT("-noexplorer"))) {
162 nShowCmd = SW_HIDE;
163 startup_desktop = TRUE;
164 }
165
166 g_Globals._hInstance = hInstance;
167
168 HWND hwndDesktop = 0;
169
170 if (startup_desktop)
171 {
172 hwndDesktop = DesktopWindow::Create();
173
174 #ifndef _DEBUG //MF: disabled for debugging
175 {
176 char* argv[] = {""};
177 startup(1, argv);
178 }
179 #endif
180 }
181
182 int ret = explorer_main(hInstance, hwndDesktop, nShowCmd);
183
184 return ret;
185 }