shdocvw: Support setting an icon on the main iexplore window.
[wine/wine-gecko.git] / dlls / shdocvw / iexplore.c
blob9c14cfc1631adf4daa98fb37a3d9f47d0a03a3d0
1 /*
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
22 #define COBJMACROS
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "exdisp.h"
32 #include "oleidl.h"
34 #include "shdocvw.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
40 #define IDI_APPICON 101
42 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
44 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
46 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
47 return 0;
50 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
52 if(This->doc_host.hwnd)
53 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
54 SWP_NOZORDER | SWP_NOACTIVATE);
56 return 0;
59 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
61 TRACE("%p\n", This);
63 This->frame_hwnd = NULL;
64 PostQuitMessage(0); /* FIXME */
66 return 0;
69 static LRESULT CALLBACK
70 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
72 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
74 switch (msg)
76 case WM_CREATE:
77 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
78 case WM_DESTROY:
79 return iewnd_OnDestroy(This);
80 case WM_SIZE:
81 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
82 case WM_DOCHOSTTASK:
83 return process_dochost_task(&This->doc_host, lparam);
85 return DefWindowProcW(hwnd, msg, wparam, lparam);
88 void register_iewindow_class(void)
90 WNDCLASSEXW wc;
92 memset(&wc, 0, sizeof wc);
93 wc.style = 0;
94 wc.lpfnWndProc = ie_window_proc;
95 wc.cbClsExtra = 0;
96 wc.cbWndExtra = sizeof(InternetExplorer*);
97 wc.hInstance = shdocvw_hinstance;
98 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
99 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
100 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
101 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
102 wc.hbrBackground = 0;
103 wc.lpszClassName = szIEWinFrame;
104 wc.lpszMenuName = NULL;
106 RegisterClassExW(&wc);
109 void unregister_iewindow_class(void)
111 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
114 static void create_frame_hwnd(InternetExplorer *This)
116 /* Windows uses "Microsoft Internet Explorer" */
117 static const WCHAR wszWineInternetExplorer[] =
118 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
120 This->frame_hwnd = CreateWindowExW(
121 WS_EX_WINDOWEDGE,
122 szIEWinFrame, wszWineInternetExplorer,
123 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
124 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
125 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
126 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
129 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
131 IWebBrowser2 *wb = NULL;
133 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
134 if(!wb)
135 return NULL;
137 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
139 if(!*cmdline) {
140 IWebBrowser2_GoHome(wb);
141 }else {
142 VARIANT var_url;
143 DWORD len;
145 if(!strncasecmp(cmdline, "-nohome", 7))
146 cmdline += 7;
148 V_VT(&var_url) = VT_BSTR;
150 len = MultiByteToWideChar(CP_ACP, 0, cmdline, -1, NULL, 0);
151 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
152 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, V_BSTR(&var_url), len);
154 /* navigate to the first page */
155 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
157 SysFreeString(V_BSTR(&var_url));
160 return wb;
163 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
165 InternetExplorer *ret;
166 HRESULT hres;
168 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
170 ret = heap_alloc_zero(sizeof(InternetExplorer));
171 ret->ref = 0;
173 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
174 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
176 InternetExplorer_WebBrowser_Init(ret);
178 create_frame_hwnd(ret);
179 ret->doc_host.frame_hwnd = ret->frame_hwnd;
181 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
182 if(FAILED(hres)) {
183 heap_free(ret);
184 return hres;
187 return hres;
190 /******************************************************************
191 * IEWinMain (SHDOCVW.101)
193 * Only returns on error.
195 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
197 IWebBrowser2 *wb = NULL;
198 MSG msg;
199 HRESULT hres;
201 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
203 if(*szCommandLine == '-' || *szCommandLine == '/') {
204 if(!strcasecmp(szCommandLine+1, "regserver"))
205 return register_iexplore(TRUE);
206 if(!strcasecmp(szCommandLine+1, "unregserver"))
207 return register_iexplore(FALSE);
210 CoInitialize(NULL);
212 hres = register_class_object(TRUE);
213 if(FAILED(hres)) {
214 CoUninitialize();
215 ExitProcess(1);
218 if(strcasecmp(szCommandLine, "-embedding"))
219 wb = create_ie_window(szCommandLine);
221 /* run the message loop for this thread */
222 while (GetMessageW(&msg, 0, 0, 0))
224 TranslateMessage(&msg);
225 DispatchMessageW(&msg);
228 if(wb)
229 IWebBrowser2_Release(wb);
231 register_class_object(FALSE);
233 CoUninitialize();
235 ExitProcess(0);
236 return 0;