first draft of explorer 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 #include "utility/shellclasses.h"
33
34 #include "explorer.h"
35 #include "globals.h"
36
37 #include "explorer_intres.h"
38 #include "externals.h"
39
40
41 ExplorerGlobals g_Globals;
42
43
44 ExplorerGlobals::ExplorerGlobals()
45 {
46 _hInstance = 0;
47 _hframeClass = 0;
48 _cfStrFName = 0;
49 _hMainWnd = 0;
50 _prescan_nodes = false;
51 _desktop_mode = false;
52 }
53
54
55 ResString::ResString(UINT nid)
56 {
57 TCHAR buffer[BUFFER_LEN];
58
59 int len = LoadString(g_Globals._hInstance, nid, buffer, sizeof(buffer)/sizeof(TCHAR));
60
61 assign(buffer, len);
62 }
63
64
65 ResIcon::ResIcon(UINT nid)
66 {
67 _hicon = LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(nid));
68 }
69
70 SmallIcon::SmallIcon(UINT nid)
71 {
72 _hicon = (HICON)LoadImage(g_Globals._hInstance, MAKEINTRESOURCE(nid), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
73 }
74
75
76 void explorer_show_frame(HWND hwndDesktop, int cmdshow)
77 {
78 if (g_Globals._hMainWnd)
79 return;
80
81 g_Globals._prescan_nodes = false;
82
83 // create main window
84 g_Globals._hMainWnd = MainFrame::Create();
85
86 ShowWindow(g_Globals._hMainWnd, cmdshow);
87
88 UpdateWindow(g_Globals._hMainWnd);
89
90 // Open the first child window after initialiszing the whole application
91 PostMessage(g_Globals._hMainWnd, WM_OPEN_WINDOW, 0, 0);
92 }
93
94
95 static void InitInstance(HINSTANCE hInstance)
96 {
97 setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName
98
99 // register frame window class
100 g_Globals._hframeClass = IconWindowClass(CLASSNAME_FRAME,IDI_EXPLORER);
101
102 // register child windows class
103 WindowClass(CLASSNAME_CHILDWND, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
104
105 // register tree windows class
106 WindowClass(CLASSNAME_WINEFILETREE, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
107
108 g_Globals._cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
109 }
110
111
112 int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow)
113 {
114 // initialize COM and OLE
115 OleInit usingCOM;
116
117 // initialize Common Controls library
118 CommonControlInit usingCmnCtrl(ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES);
119
120 try {
121 InitInstance(hInstance);
122
123 if (hwndDesktop)
124 g_Globals._desktop_mode = true;
125
126 if (cmdshow != SW_HIDE) {
127 #ifndef _ROS_ // don't maximize if being called from the ROS desktop
128 if (cmdshow == SW_SHOWNORMAL)
129 /*TODO: read window placement from registry */
130 cmdshow = SW_MAXIMIZE;
131 #endif
132
133 explorer_show_frame(hwndDesktop, cmdshow);
134 }
135
136 return Window::MessageLoop();
137 } catch(COMException& e) {
138 HandleException(e, g_Globals._hMainWnd);
139 }
140
141 return -1;
142 }
143
144
145 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
146 {
147 // create desktop window and task bar only, if there is no other shell and we are
148 // the first explorer instance
149 BOOL startup_desktop = !IsAnyDesktopRunning();
150
151 // If there is given the command line option "-desktop", create desktop window anyways
152 if (!lstrcmp(lpCmdLine,TEXT("-desktop")))
153 startup_desktop = TRUE;
154
155 if (!lstrcmp(lpCmdLine,TEXT("-noexplorer"))) {
156 nShowCmd = SW_HIDE;
157 startup_desktop = TRUE;
158 }
159
160 g_Globals._hInstance = hInstance;
161
162 HWND hwndDesktop = 0;
163
164 if (startup_desktop)
165 {
166 hwndDesktop = create_desktop_window();
167
168 // Initialize the explorer bar
169 HWND hwndExplorerBar = InitializeExplorerBar(hInstance);
170
171 // Load plugins
172 // LoadAvailablePlugIns(hwndExplorerBar);
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 // ReleaseAvailablePlugIns();
185
186 return ret;
187 }