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)
52 static InternetExplorer* This;
57 This = (InternetExplorer*)lparam;
58 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
62 switch(LOWORD(wparam))
64 case IDC_BROWSE_OPEN_URL:
66 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
67 int len = GetWindowTextLengthW(hwndurl);
69 EnableWindow(GetDlgItem(hwnd, IDOK), len ? TRUE : FALSE);
74 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
75 int len = GetWindowTextLengthW(hwndurl);
82 V_BSTR(&url) = SysAllocStringLen(NULL, len);
84 GetWindowTextW(hwndurl, V_BSTR(&url), len);
85 IWebBrowser2_Navigate2(WEBBROWSER2(This), &url, NULL, NULL, NULL, NULL);
87 SysFreeString(V_BSTR(&url));
92 EndDialog(hwnd, wparam);
99 static void ie_dialog_about(HWND hwnd)
101 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
103 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
108 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
110 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
114 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
116 if(This->doc_host.hwnd)
117 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
118 SWP_NOZORDER | SWP_NOACTIVATE);
123 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
127 This->frame_hwnd = NULL;
128 PostQuitMessage(0); /* FIXME */
133 static LRESULT CALLBACK iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
135 switch(LOWORD(wparam))
138 DialogBoxParamW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This);
141 case ID_BROWSE_PRINT:
142 if(This->doc_host.document)
144 IOleCommandTarget* target;
146 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
149 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
151 IOleCommandTarget_Release(target);
155 case ID_BROWSE_ABOUT:
156 ie_dialog_about(hwnd);
160 return DefWindowProcW(hwnd, msg, wparam, lparam);
165 static LRESULT CALLBACK
166 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
168 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
173 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
175 return iewnd_OnDestroy(This);
177 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
179 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
181 return process_dochost_task(&This->doc_host, lparam);
183 return DefWindowProcW(hwnd, msg, wparam, lparam);
186 void register_iewindow_class(void)
190 memset(&wc, 0, sizeof wc);
191 wc.cbSize = sizeof(wc);
193 wc.lpfnWndProc = ie_window_proc;
195 wc.cbWndExtra = sizeof(InternetExplorer*);
196 wc.hInstance = shdocvw_hinstance;
197 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
198 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
199 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
200 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
201 wc.hbrBackground = 0;
202 wc.lpszClassName = szIEWinFrame;
203 wc.lpszMenuName = NULL;
205 RegisterClassExW(&wc);
208 void unregister_iewindow_class(void)
210 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
213 static void create_frame_hwnd(InternetExplorer *This)
215 This->frame_hwnd = CreateWindowExW(
217 szIEWinFrame, wszWineInternetExplorer,
218 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
219 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
220 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
221 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
224 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
226 IWebBrowser2 *wb = NULL;
228 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
232 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
233 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE);
236 IWebBrowser2_GoHome(wb);
242 if(!strncasecmp(cmdline, "-nohome", 7))
244 while(*cmdline == ' ' || *cmdline == '\t')
246 cmdlen = lstrlenA(cmdline);
247 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
252 V_VT(&var_url) = VT_BSTR;
254 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
255 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
256 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
258 /* navigate to the first page */
259 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
261 SysFreeString(V_BSTR(&var_url));
267 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
269 InternetExplorer *ret;
272 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
274 ret = heap_alloc_zero(sizeof(InternetExplorer));
277 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
278 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
280 InternetExplorer_WebBrowser_Init(ret);
282 create_frame_hwnd(ret);
283 ret->doc_host.frame_hwnd = ret->frame_hwnd;
285 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
294 /******************************************************************
295 * IEWinMain (SHDOCVW.101)
297 * Only returns on error.
299 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
301 IWebBrowser2 *wb = NULL;
305 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
307 if(*szCommandLine == '-' || *szCommandLine == '/') {
308 if(!strcasecmp(szCommandLine+1, "regserver"))
309 return register_iexplore(TRUE);
310 if(!strcasecmp(szCommandLine+1, "unregserver"))
311 return register_iexplore(FALSE);
316 hres = register_class_object(TRUE);
322 if(strcasecmp(szCommandLine, "-embedding"))
323 wb = create_ie_window(szCommandLine);
325 /* run the message loop for this thread */
326 while (GetMessageW(&msg, 0, 0, 0))
328 TranslateMessage(&msg);
329 DispatchMessageW(&msg);
333 IWebBrowser2_Release(wb);
335 register_class_object(FALSE);