advapi32: Explicitly initialize nested array element.
[wine] / dlls / shdocvw / iexplore.c
1 /*
2  * SHDOCVW - Internet Explorer main frame window
3  *
4  * Copyright 2006 Mike McCormack (for CodeWeavers)
5  * Copyright 2006 Jacek Caban (for CodeWeavers)
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define COBJMACROS
23
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"
33
34 #include "shdocvw.h"
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
39
40 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
41
42 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
43 {
44     SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
45     return 0;
46 }
47
48 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
49 {
50     if(This->doc_host.hwnd)
51         SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
52                      SWP_NOZORDER | SWP_NOACTIVATE);
53
54     return 0;
55 }
56
57 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
58 {
59     TRACE("%p\n", This);
60
61     This->frame_hwnd = NULL;
62     PostQuitMessage(0); /* FIXME */
63
64     return 0;
65 }
66
67 static LRESULT CALLBACK
68 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
69 {
70     InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
71
72     switch (msg)
73     {
74     case WM_CREATE:
75         return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
76     case WM_DESTROY:
77         return iewnd_OnDestroy(This);
78     case WM_SIZE:
79         return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
80     }
81     return DefWindowProcW(hwnd, msg, wparam, lparam);
82 }
83
84 void register_iewindow_class(void)
85 {
86     WNDCLASSW wc;
87
88     memset(&wc, 0, sizeof wc);
89     wc.style = 0;
90     wc.lpfnWndProc = ie_window_proc;
91     wc.cbClsExtra = 0;
92     wc.cbWndExtra = sizeof(InternetExplorer*);
93     wc.hInstance = shdocvw_hinstance;
94     wc.hIcon = 0;
95     wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDI_APPLICATION));
96     wc.hbrBackground = 0;
97     wc.lpszClassName = szIEWinFrame;
98     wc.lpszMenuName = NULL;
99
100     RegisterClassW(&wc);
101 }
102
103 void unregister_iewindow_class(void)
104 {
105     UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
106 }
107
108 static void create_frame_hwnd(InternetExplorer *This)
109 {
110     /* Windows uses "Microsoft Internet Explorer" */
111     static const WCHAR wszWineInternetExplorer[] =
112         {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
113
114     This->frame_hwnd = CreateWindowExW(
115             WS_EX_WINDOWEDGE,
116             szIEWinFrame, wszWineInternetExplorer,
117             WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
118                 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
119             CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
120             NULL, NULL /* FIXME */, shdocvw_hinstance, This);
121 }
122
123 static IWebBrowser2 *create_ie_window(LPCWSTR url)
124 {
125     IWebBrowser2 *wb = NULL;
126     VARIANT var_url;
127
128     InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
129     if(!wb)
130         return NULL;
131
132     IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
133
134     V_VT(&var_url) = VT_BSTR;
135     V_BSTR(&var_url) = SysAllocString(url);
136
137     /* navigate to the first page */
138     IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
139
140     SysFreeString(V_BSTR(&var_url));
141
142     return wb;
143 }
144
145 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
146 {
147     InternetExplorer *ret;
148     HRESULT hres;
149
150     TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
151
152     ret = shdocvw_alloc(sizeof(InternetExplorer));
153     ret->ref = 0;
154
155     ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
156     DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
157
158     InternetExplorer_WebBrowser_Init(ret);
159
160     create_frame_hwnd(ret);
161     ret->doc_host.frame_hwnd = ret->frame_hwnd;
162
163     hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
164     if(FAILED(hres)) {
165         shdocvw_free(ret);
166         return hres;
167     }
168
169     return hres;
170 }
171
172 /******************************************************************
173  *              IEWinMain            (SHDOCVW.101)
174  *
175  * Only returns on error.
176  */
177 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
178 {
179     IWebBrowser2 *wb = NULL;
180     MSG msg;
181     HRESULT hres;
182
183     FIXME("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
184
185     CoInitialize(NULL);
186
187     hres = register_class_object(TRUE);
188     if(FAILED(hres)) {
189         CoUninitialize();
190         ExitProcess(1);
191     }
192
193     if(strcmp(szCommandLine, "-Embedding")) {
194         LPWSTR url;
195         DWORD len;
196
197         len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
198         url = shdocvw_alloc(len*sizeof(WCHAR));
199         MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, url, len);
200
201         wb = create_ie_window(url);
202
203         shdocvw_free(url);
204     }
205
206     /* run the message loop for this thread */
207     while (GetMessageW(&msg, 0, 0, 0))
208     {
209         TranslateMessage(&msg);
210         DispatchMessageW(&msg);
211     }
212
213     if(wb)
214         IWebBrowser2_Release(wb);
215
216     register_class_object(FALSE);
217
218     CoUninitialize();
219
220     ExitProcess(0);
221     return 0;
222 }