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, 23.07.2003
27 // Credits: Thanks to Leon Finker for his explorer window example
31 #include "utility/utility.h"
32 #include "utility/shellclasses.h"
37 #include "explorer_intres.h"
38 #include "externals.h"
41 ExplorerGlobals g_Globals
;
44 ExplorerGlobals::ExplorerGlobals()
50 _prescan_nodes
= false;
51 _desktop_mode
= false;
55 ResString::ResString(UINT nid
)
57 TCHAR buffer
[BUFFER_LEN
];
59 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
65 void explorer_show_frame(HWND hwndDesktop
, int cmdshow
)
67 if (g_Globals
._hMainWnd
)
70 g_Globals
._prescan_nodes
= false;
72 HMENU hMenuFrame
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(IDM_MAINFRAME
));
75 g_Globals
._hMainWnd
= Window::Create(WINDOW_CREATOR(MainFrame
), 0,
76 (LPCTSTR
)(int)g_Globals
._hframeClass
, ResString(IDS_TITLE
), WS_OVERLAPPEDWINDOW
,
77 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
78 0/*hwndDesktop*/, hMenuFrame
);
80 ShowWindow(g_Globals
._hMainWnd
, cmdshow
);
82 UpdateWindow(g_Globals
._hMainWnd
);
84 // Open the first child window after initialiszing the whole application
85 PostMessage(g_Globals
._hMainWnd
, WM_OPEN_WINDOW
, 0, 0);
89 static void InitInstance(HINSTANCE hinstance
)
91 g_Globals
._hInstance
= hinstance
;
93 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
96 // register frame window class
98 WindowClass
wcFrame(CLASSNAME_FRAME
);
100 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_EXPLORER
));
101 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
102 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
103 MAKEINTRESOURCE(IDI_EXPLORER
),
105 GetSystemMetrics(SM_CXSMICON
),
106 GetSystemMetrics(SM_CYSMICON
),
109 g_Globals
._hframeClass
= wcFrame
.Register();
112 // register child windows class
114 WindowClass
wcChild(CLASSNAME_CHILDWND
);
116 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
117 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
122 // register tree windows class
124 WindowClass
wcTreeChild(CLASSNAME_WINEFILETREE
);
126 wcTreeChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
127 wcTreeChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
129 wcTreeChild
.Register();
132 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
136 int explorer_main(HINSTANCE hinstance
, HWND hwndDesktop
, int cmdshow
)
138 // initialize COM and OLE
141 // initialize Common Controls library
142 CommonControlInit
usingCmnCtrl(ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
);
147 InitInstance(hinstance
);
150 g_Globals
._desktop_mode
= true;
152 if (cmdshow
!= SW_HIDE
) {
153 #ifndef _ROS_ // don't maximize if being called from the ROS desktop
154 if (cmdshow
== SW_SHOWNORMAL
)
155 /*TODO: read window placement from registry */
156 cmdshow
= SW_MAXIMIZE
;
159 explorer_show_frame(hwndDesktop
, cmdshow
);
162 while(GetMessage(&msg
, 0, 0, 0)) {
163 if (g_Globals
._hMainWnd
&& SendMessage(g_Globals
._hMainWnd
, WM_TRANSLATE_MSG
, 0, (LPARAM
)&msg
))
166 TranslateMessage(&msg
);
169 DispatchMessage(&msg
);
170 } catch(COMException
& e
) {
171 HandleException(e
, g_Globals
._hMainWnd
);
177 } catch(COMException
& e
) {
178 HandleException(e
, g_Globals
._hMainWnd
);
185 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
187 // create desktop window and task bar only, if there is no other shell and we are
188 // the first explorer instance
189 BOOL startup_desktop
= !IsAnyDesktopRunning();
191 // If there is given the command line option "-desktop", create desktop window anyways
192 if (!lstrcmp(lpCmdLine
,TEXT("-desktop")))
193 startup_desktop
= TRUE
;
195 if (!lstrcmp(lpCmdLine
,TEXT("-noexplorer"))) {
197 startup_desktop
= TRUE
;
200 HWND hwndDesktop
= 0;
204 hwndDesktop
= create_desktop_window(hInstance
);
206 // Initialize the explorer bar
207 HWND hwndExplorerBar
= InitializeExplorerBar(hInstance
);
210 // LoadAvailablePlugIns(hwndExplorerBar);
212 #ifndef _DEBUG //MF: disabled for debugging
220 int ret
= explorer_main(hInstance
, hwndDesktop
, nShowCmd
);
222 // ReleaseAvailablePlugIns();