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 void ie_dialog_about(HWND hwnd)
52 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
54 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
59 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
61 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
65 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
67 if(This->doc_host.hwnd)
68 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
69 SWP_NOZORDER | SWP_NOACTIVATE);
74 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
78 This->frame_hwnd = NULL;
79 PostQuitMessage(0); /* FIXME */
84 static LRESULT CALLBACK iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
86 switch(LOWORD(wparam))
89 if(This->doc_host.document)
91 IOleCommandTarget* target;
93 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
96 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
98 IOleCommandTarget_Release(target);
102 case ID_BROWSE_ABOUT:
103 ie_dialog_about(hwnd);
107 return DefWindowProcW(hwnd, msg, wparam, lparam);
112 static LRESULT CALLBACK
113 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
115 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
120 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
122 return iewnd_OnDestroy(This);
124 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
126 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
128 return process_dochost_task(&This->doc_host, lparam);
130 return DefWindowProcW(hwnd, msg, wparam, lparam);
133 void register_iewindow_class(void)
137 memset(&wc, 0, sizeof wc);
138 wc.cbSize = sizeof(wc);
140 wc.lpfnWndProc = ie_window_proc;
142 wc.cbWndExtra = sizeof(InternetExplorer*);
143 wc.hInstance = shdocvw_hinstance;
144 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
145 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
146 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
147 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
148 wc.hbrBackground = 0;
149 wc.lpszClassName = szIEWinFrame;
150 wc.lpszMenuName = NULL;
152 RegisterClassExW(&wc);
155 void unregister_iewindow_class(void)
157 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
160 static void create_frame_hwnd(InternetExplorer *This)
162 This->frame_hwnd = CreateWindowExW(
164 szIEWinFrame, wszWineInternetExplorer,
165 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
166 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
167 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
168 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
171 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
173 IWebBrowser2 *wb = NULL;
175 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
179 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
180 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE);
183 IWebBrowser2_GoHome(wb);
189 if(!strncasecmp(cmdline, "-nohome", 7))
191 while(*cmdline == ' ' || *cmdline == '\t')
193 cmdlen = lstrlenA(cmdline);
194 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
199 V_VT(&var_url) = VT_BSTR;
201 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
202 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
203 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
205 /* navigate to the first page */
206 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
208 SysFreeString(V_BSTR(&var_url));
214 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
216 InternetExplorer *ret;
219 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
221 ret = heap_alloc_zero(sizeof(InternetExplorer));
224 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
225 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
227 InternetExplorer_WebBrowser_Init(ret);
229 create_frame_hwnd(ret);
230 ret->doc_host.frame_hwnd = ret->frame_hwnd;
232 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
241 /******************************************************************
242 * IEWinMain (SHDOCVW.101)
244 * Only returns on error.
246 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
248 IWebBrowser2 *wb = NULL;
252 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
254 if(*szCommandLine == '-' || *szCommandLine == '/') {
255 if(!strcasecmp(szCommandLine+1, "regserver"))
256 return register_iexplore(TRUE);
257 if(!strcasecmp(szCommandLine+1, "unregserver"))
258 return register_iexplore(FALSE);
263 hres = register_class_object(TRUE);
269 if(strcasecmp(szCommandLine, "-embedding"))
270 wb = create_ie_window(szCommandLine);
272 /* run the message loop for this thread */
273 while (GetMessageW(&msg, 0, 0, 0))
275 TranslateMessage(&msg);
276 DispatchMessageW(&msg);
280 IWebBrowser2_Release(wb);
282 register_class_object(FALSE);