2 * SHDOCVW - Internet Explorer main frame window
4 * Copyright 2006 Mike McCormack (for CodeWeavers)
5 * Copyright 2006 Jacek Caban (for CodeWeavers)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
44 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
46 /* Windows uses "Microsoft Internet Explorer" */
47 static const WCHAR wszWineInternetExplorer[] =
48 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
50 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
58 switch(LOWORD(wparam))
62 EndDialog(hwnd, wparam);
69 static void ie_dialog_about(HWND hwnd)
71 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
73 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
78 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
80 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
84 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
86 if(This->doc_host.hwnd)
87 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
88 SWP_NOZORDER | SWP_NOACTIVATE);
93 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
97 This->frame_hwnd = NULL;
98 PostQuitMessage(0); /* FIXME */
103 static LRESULT CALLBACK iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
105 switch(LOWORD(wparam))
108 DialogBoxW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc);
111 case ID_BROWSE_PRINT:
112 if(This->doc_host.document)
114 IOleCommandTarget* target;
116 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
119 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
121 IOleCommandTarget_Release(target);
125 case ID_BROWSE_ABOUT:
126 ie_dialog_about(hwnd);
130 return DefWindowProcW(hwnd, msg, wparam, lparam);
135 static LRESULT CALLBACK
136 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
138 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
143 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
145 return iewnd_OnDestroy(This);
147 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
149 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
151 return process_dochost_task(&This->doc_host, lparam);
153 return DefWindowProcW(hwnd, msg, wparam, lparam);
156 void register_iewindow_class(void)
160 memset(&wc, 0, sizeof wc);
161 wc.cbSize = sizeof(wc);
163 wc.lpfnWndProc = ie_window_proc;
165 wc.cbWndExtra = sizeof(InternetExplorer*);
166 wc.hInstance = shdocvw_hinstance;
167 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
168 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
169 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
170 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
171 wc.hbrBackground = 0;
172 wc.lpszClassName = szIEWinFrame;
173 wc.lpszMenuName = NULL;
175 RegisterClassExW(&wc);
178 void unregister_iewindow_class(void)
180 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
183 static void create_frame_hwnd(InternetExplorer *This)
185 This->frame_hwnd = CreateWindowExW(
187 szIEWinFrame, wszWineInternetExplorer,
188 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
189 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
190 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
191 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
194 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
196 IWebBrowser2 *wb = NULL;
198 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
202 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
203 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE);
206 IWebBrowser2_GoHome(wb);
212 if(!strncasecmp(cmdline, "-nohome", 7))
214 while(*cmdline == ' ' || *cmdline == '\t')
216 cmdlen = lstrlenA(cmdline);
217 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
222 V_VT(&var_url) = VT_BSTR;
224 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
225 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
226 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
228 /* navigate to the first page */
229 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
231 SysFreeString(V_BSTR(&var_url));
237 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
239 InternetExplorer *ret;
242 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
244 ret = heap_alloc_zero(sizeof(InternetExplorer));
247 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
248 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
250 InternetExplorer_WebBrowser_Init(ret);
252 create_frame_hwnd(ret);
253 ret->doc_host.frame_hwnd = ret->frame_hwnd;
255 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
264 /******************************************************************
265 * IEWinMain (SHDOCVW.101)
267 * Only returns on error.
269 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
271 IWebBrowser2 *wb = NULL;
275 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
277 if(*szCommandLine == '-' || *szCommandLine == '/') {
278 if(!strcasecmp(szCommandLine+1, "regserver"))
279 return register_iexplore(TRUE);
280 if(!strcasecmp(szCommandLine+1, "unregserver"))
281 return register_iexplore(FALSE);
286 hres = register_class_object(TRUE);
292 if(strcasecmp(szCommandLine, "-embedding"))
293 wb = create_ie_window(szCommandLine);
295 /* run the message loop for this thread */
296 while (GetMessageW(&msg, 0, 0, 0))
298 TranslateMessage(&msg);
299 DispatchMessageW(&msg);
303 IWebBrowser2_Release(wb);
305 register_class_object(FALSE);