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
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw
);
48 static const WCHAR szIEWinFrame
[] = { 'I','E','F','r','a','m','e',0 };
50 /* Windows uses "Microsoft Internet Explorer" */
51 static const WCHAR wszWineInternetExplorer
[] =
52 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
55 static DWORD dde_inst
;
56 static HSZ ddestr_iexplore
, ddestr_openurl
;
57 static struct list ie_list
;
59 HRESULT
update_ie_statustext(InternetExplorer
* This
, LPCWSTR text
)
61 if(!SendMessageW(This
->status_hwnd
, SB_SETTEXTW
, MAKEWORD(SB_SIMPLEID
, 0), (LPARAM
)text
))
67 static void adjust_ie_docobj_rect(HWND frame
, RECT
* rc
)
69 HWND hwndRebar
= GetDlgItem(frame
, IDC_BROWSE_REBAR
);
70 HWND hwndStatus
= GetDlgItem(frame
, IDC_BROWSE_STATUSBAR
);
71 INT barHeight
= SendMessageW(hwndRebar
, RB_GETBARHEIGHT
, 0, 0);
74 rc
->bottom
-= barHeight
;
76 if(IsWindowVisible(hwndStatus
))
80 GetClientRect(hwndStatus
, &statusrc
);
81 rc
->bottom
-= statusrc
.bottom
- statusrc
.top
;
85 static HMENU
get_tb_menu(HMENU menu
)
87 HMENU menu_view
= GetSubMenu(menu
, 1);
89 return GetSubMenu(menu_view
, 0);
92 static HMENU
get_fav_menu(HMENU menu
)
94 return GetSubMenu(menu
, 2);
97 static LPWSTR
get_fav_url_from_id(HMENU menu
, UINT id
)
101 item
.cbSize
= sizeof(item
);
102 item
.fMask
= MIIM_DATA
;
104 if(!GetMenuItemInfoW(menu
, id
, FALSE
, &item
))
107 return (LPWSTR
)item
.dwItemData
;
110 static void free_fav_menu_data(HMENU menu
)
115 for(i
= 0; (url
= get_fav_url_from_id(menu
, ID_BROWSE_GOTOFAV_FIRST
+ i
)); i
++)
119 static int get_menu_item_count(HMENU menu
)
125 item
.cbSize
= sizeof(item
);
126 item
.fMask
= MIIM_DATA
| MIIM_SUBMENU
;
128 for(i
= 0; GetMenuItemInfoW(menu
, i
, TRUE
, &item
); i
++)
131 count
+= get_menu_item_count(item
.hSubMenu
);
139 static void add_fav_to_menu(HMENU favmenu
, HMENU menu
, LPWSTR title
, LPCWSTR url
)
142 /* Subtract the number of standard elements in the Favorites menu */
143 int favcount
= get_menu_item_count(favmenu
) - 2;
146 if(favcount
> (ID_BROWSE_GOTOFAV_MAX
- ID_BROWSE_GOTOFAV_FIRST
))
148 FIXME("Add support for more than %d Favorites\n", favcount
);
152 urlbuf
= heap_alloc((lstrlenW(url
) + 1) * sizeof(WCHAR
));
157 lstrcpyW(urlbuf
, url
);
159 item
.cbSize
= sizeof(item
);
160 item
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_DATA
| MIIM_ID
;
161 item
.fType
= MFT_STRING
;
162 item
.dwTypeData
= title
;
163 item
.wID
= ID_BROWSE_GOTOFAV_FIRST
+ favcount
;
164 item
.dwItemData
= (ULONG_PTR
)urlbuf
;
165 InsertMenuItemW(menu
, -1, TRUE
, &item
);
168 static void add_favs_to_menu(HMENU favmenu
, HMENU menu
, LPCWSTR dir
)
170 WCHAR path
[MAX_PATH
*2];
171 const WCHAR search
[] = {'*',0};
174 WIN32_FIND_DATAW finddata
;
175 IUniformResourceLocatorW
* urlobj
;
176 IPersistFile
* urlfile
= NULL
;
180 PathAppendW(path
, search
);
182 findhandle
= FindFirstFileW(path
, &finddata
);
184 if(findhandle
== INVALID_HANDLE_VALUE
)
187 res
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUniformResourceLocatorW
, (PVOID
*)&urlobj
);
190 res
= IUnknown_QueryInterface(urlobj
, &IID_IPersistFile
, (PVOID
*)&urlfile
);
194 filename
= path
+ lstrlenW(path
) - lstrlenW(search
);
198 lstrcpyW(filename
, finddata
.cFileName
);
200 if(finddata
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
203 const WCHAR ignore1
[] = {'.','.',0};
204 const WCHAR ignore2
[] = {'.',0};
206 if(!lstrcmpW(filename
, ignore1
) || !lstrcmpW(filename
, ignore2
))
209 item
.cbSize
= sizeof(item
);
210 item
.fMask
= MIIM_STRING
| MIIM_SUBMENU
;
211 item
.dwTypeData
= filename
;
212 item
.hSubMenu
= CreatePopupMenu();
213 InsertMenuItemW(menu
, -1, TRUE
, &item
);
214 add_favs_to_menu(favmenu
, item
.hSubMenu
, path
);
219 const WCHAR urlext
[] = {'.','u','r','l',0};
221 if(lstrcmpiW(PathFindExtensionW(filename
), urlext
))
224 if(FAILED(IPersistFile_Load(urlfile
, path
, 0)))
227 urlobj
->lpVtbl
->GetURL(urlobj
, &url
);
232 fileext
= filename
+ lstrlenW(filename
) - lstrlenW(urlext
);
234 add_fav_to_menu(favmenu
, menu
, filename
, url
);
236 } while(FindNextFileW(findhandle
, &finddata
));
240 IPersistFile_Release(urlfile
);
243 IUnknown_Release(urlobj
);
245 FindClose(findhandle
);
248 static void add_tbs_to_menu(HMENU menu
)
250 HUSKEY toolbar_handle
;
251 WCHAR toolbar_key
[] = {'S','o','f','t','w','a','r','e','\\',
252 'M','i','c','r','o','s','o','f','t','\\',
253 'I','n','t','e','r','n','e','t',' ',
254 'E','x','p','l','o','r','e','r','\\',
255 'T','o','o','l','b','a','r',0};
257 if(SHRegOpenUSKeyW(toolbar_key
, KEY_READ
, NULL
, &toolbar_handle
, TRUE
) == ERROR_SUCCESS
)
259 HUSKEY classes_handle
;
260 WCHAR classes_key
[] = {'S','o','f','t','w','a','r','e','\\',
261 'C','l','a','s','s','e','s','\\','C','L','S','I','D',0};
263 DWORD value_len
= sizeof(guid
)/sizeof(guid
[0]);
266 if(SHRegOpenUSKeyW(classes_key
, KEY_READ
, NULL
, &classes_handle
, TRUE
) != ERROR_SUCCESS
)
268 SHRegCloseUSKey(toolbar_handle
);
269 ERR("Failed to open key %s\n", debugstr_w(classes_key
));
273 for(i
= 0; SHRegEnumUSValueW(toolbar_handle
, i
, guid
, &value_len
, NULL
, NULL
, NULL
, SHREGENUM_HKLM
) == ERROR_SUCCESS
; i
++)
276 DWORD tb_name_len
= sizeof(tb_name
)/sizeof(tb_name
[0]);
277 HUSKEY tb_class_handle
;
280 value_len
= sizeof(guid
)/sizeof(guid
[0]);
282 if(lstrlenW(guid
) != 38)
284 TRACE("Found invalid IE toolbar entry: %s\n", debugstr_w(guid
));
288 if(SHRegOpenUSKeyW(guid
, KEY_READ
, classes_handle
, &tb_class_handle
, TRUE
) != ERROR_SUCCESS
)
290 ERR("Failed to get class info for %s\n", debugstr_w(guid
));
294 ret
= SHRegQueryUSValueW(tb_class_handle
, NULL
, NULL
, tb_name
, &tb_name_len
, TRUE
, NULL
, 0);
296 SHRegCloseUSKey(tb_class_handle
);
298 if(ret
!= ERROR_SUCCESS
)
300 ERR("Failed to get toolbar name for %s\n", debugstr_w(guid
));
304 item
.cbSize
= sizeof(item
);
305 item
.fMask
= MIIM_STRING
;
306 item
.dwTypeData
= tb_name
;
307 InsertMenuItemW(menu
, GetMenuItemCount(menu
), TRUE
, &item
);
310 SHRegCloseUSKey(classes_handle
);
311 SHRegCloseUSKey(toolbar_handle
);
315 static HMENU
create_ie_menu(void)
317 HMENU menu
= LoadMenuW(shdocvw_hinstance
, MAKEINTRESOURCEW(IDR_BROWSE_MAIN_MENU
));
318 HMENU favmenu
= get_fav_menu(menu
);
319 WCHAR path
[MAX_PATH
];
321 add_tbs_to_menu(get_tb_menu(menu
));
323 if(SHGetFolderPathW(NULL
, CSIDL_COMMON_FAVORITES
, NULL
, SHGFP_TYPE_CURRENT
, path
) == S_OK
)
324 add_favs_to_menu(favmenu
, favmenu
, path
);
326 if(SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, SHGFP_TYPE_CURRENT
, path
) == S_OK
)
327 add_favs_to_menu(favmenu
, favmenu
, path
);
332 static void ie_navigate(InternetExplorer
* This
, LPCWSTR url
)
336 V_VT(&variant
) = VT_BSTR
;
337 V_BSTR(&variant
) = SysAllocString(url
);
339 IWebBrowser2_Navigate2(&This
->IWebBrowser2_iface
, &variant
, NULL
, NULL
, NULL
, NULL
);
341 SysFreeString(V_BSTR(&variant
));
344 static INT_PTR CALLBACK
ie_dialog_open_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
346 static InternetExplorer
* This
;
351 This
= (InternetExplorer
*)lparam
;
352 EnableWindow(GetDlgItem(hwnd
, IDOK
), FALSE
);
356 switch(LOWORD(wparam
))
358 case IDC_BROWSE_OPEN_URL
:
360 HWND hwndurl
= GetDlgItem(hwnd
, IDC_BROWSE_OPEN_URL
);
361 int len
= GetWindowTextLengthW(hwndurl
);
363 EnableWindow(GetDlgItem(hwnd
, IDOK
), len
? TRUE
: FALSE
);
368 HWND hwndurl
= GetDlgItem(hwnd
, IDC_BROWSE_OPEN_URL
);
369 int len
= GetWindowTextLengthW(hwndurl
);
375 V_VT(&url
) = VT_BSTR
;
376 V_BSTR(&url
) = SysAllocStringLen(NULL
, len
);
378 GetWindowTextW(hwndurl
, V_BSTR(&url
), len
+ 1);
379 IWebBrowser2_Navigate2(&This
->IWebBrowser2_iface
, &url
, NULL
, NULL
, NULL
, NULL
);
381 SysFreeString(V_BSTR(&url
));
386 EndDialog(hwnd
, wparam
);
393 static void ie_dialog_about(HWND hwnd
)
395 HICON icon
= LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON
), IMAGE_ICON
, 48, 48, LR_SHARED
);
397 ShellAboutW(hwnd
, wszWineInternetExplorer
, NULL
, icon
);
402 static void add_tb_separator(HWND hwnd
)
406 ZeroMemory(&btn
, sizeof(btn
));
409 btn
.fsStyle
= BTNS_SEP
;
410 SendMessageW(hwnd
, TB_ADDBUTTONSW
, 1, (LPARAM
)&btn
);
413 static void add_tb_button(HWND hwnd
, int bmp
, int cmd
, int strId
)
418 LoadStringW(shdocvw_hinstance
, strId
, buf
, sizeof(buf
)/sizeof(buf
[0]));
422 btn
.fsState
= TBSTATE_ENABLED
;
423 btn
.fsStyle
= BTNS_SHOWTEXT
;
425 btn
.iString
= (INT_PTR
)buf
;
427 SendMessageW(hwnd
, TB_ADDBUTTONSW
, 1, (LPARAM
)&btn
);
430 static void create_rebar(HWND hwnd
)
436 REBARBANDINFOW bandinf
;
438 HIMAGELIST imagelist
;
439 WCHAR idb_ietoolbar
[] = {'I','D','B','_','I','E','T','O','O','L','B','A','R',0};
441 LoadStringW(shdocvw_hinstance
, IDS_ADDRESS
, addr
, sizeof(addr
)/sizeof(addr
[0]));
443 hwndRebar
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
, WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
|CCS_NODIVIDER
, 0, 0, 0, 0, hwnd
, (HMENU
)IDC_BROWSE_REBAR
, shdocvw_hinstance
, NULL
);
445 rebarinf
.cbSize
= sizeof(rebarinf
);
447 rebarinf
.himl
= NULL
;
448 rebarinf
.cbSize
= sizeof(rebarinf
);
450 SendMessageW(hwndRebar
, RB_SETBARINFO
, 0, (LPARAM
)&rebarinf
);
452 hwndToolbar
= CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS
, TOOLBARCLASSNAMEW
, NULL
, TBSTYLE_FLAT
| WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hwndRebar
, (HMENU
)IDC_BROWSE_TOOLBAR
, shdocvw_hinstance
, NULL
);
454 imagelist
= ImageList_LoadImageW(shdocvw_hinstance
, idb_ietoolbar
, 32, 0, CLR_NONE
, IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
456 SendMessageW(hwndToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)imagelist
);
457 SendMessageW(hwndToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
458 add_tb_button(hwndToolbar
, 0, 0, IDS_TB_BACK
);
459 add_tb_button(hwndToolbar
, 1, 0, IDS_TB_FORWARD
);
460 add_tb_button(hwndToolbar
, 2, 0, IDS_TB_STOP
);
461 add_tb_button(hwndToolbar
, 3, 0, IDS_TB_REFRESH
);
462 add_tb_button(hwndToolbar
, 4, ID_BROWSE_HOME
, IDS_TB_HOME
);
463 add_tb_separator(hwndToolbar
);
464 add_tb_button(hwndToolbar
, 5, ID_BROWSE_PRINT
, IDS_TB_PRINT
);
465 SendMessageW(hwndToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(55,50));
466 SendMessageW(hwndToolbar
, TB_AUTOSIZE
, 0, 0);
468 bandinf
.cbSize
= sizeof(bandinf
);
469 bandinf
.fMask
= RBBIM_STYLE
| RBBIM_CHILD
| RBBIM_CHILDSIZE
| RBBIM_SIZE
;
470 bandinf
.fStyle
= RBBS_CHILDEDGE
;
472 bandinf
.cyMinChild
= 52;
473 bandinf
.hwndChild
= hwndToolbar
;
475 SendMessageW(hwndRebar
, RB_INSERTBANDW
, -1, (LPARAM
)&bandinf
);
477 hwndAddress
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
, WS_BORDER
|WS_CHILD
|WS_VISIBLE
|CBS_DROPDOWN
, 0, 0, 100,20,hwndRebar
, (HMENU
)IDC_BROWSE_ADDRESSBAR
, shdocvw_hinstance
, NULL
);
479 bandinf
.fMask
|= RBBIM_TEXT
;
480 bandinf
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
;
481 bandinf
.lpText
= addr
;
482 bandinf
.cyMinChild
= 20;
483 bandinf
.hwndChild
= hwndAddress
;
485 SendMessageW(hwndRebar
, RB_INSERTBANDW
, -1, (LPARAM
)&bandinf
);
488 static LRESULT
iewnd_OnCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
490 InternetExplorer
* This
= (InternetExplorer
*)lpcs
->lpCreateParams
;
491 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
) lpcs
->lpCreateParams
);
493 This
->menu
= create_ie_menu();
495 This
->status_hwnd
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|SBT_NOBORDERS
|CCS_NODIVIDER
,
496 NULL
, hwnd
, IDC_BROWSE_STATUSBAR
);
497 SendMessageW(This
->status_hwnd
, SB_SIMPLE
, TRUE
, 0);
504 static LRESULT
iewnd_OnSize(InternetExplorer
*This
, INT width
, INT height
)
506 HWND hwndRebar
= GetDlgItem(This
->frame_hwnd
, IDC_BROWSE_REBAR
);
507 INT barHeight
= SendMessageW(hwndRebar
, RB_GETBARHEIGHT
, 0, 0);
508 RECT docarea
= {0, 0, width
, height
};
510 SendMessageW(This
->status_hwnd
, WM_SIZE
, 0, 0);
512 adjust_ie_docobj_rect(This
->frame_hwnd
, &docarea
);
514 if(This
->doc_host
->doc_host
.hwnd
)
515 SetWindowPos(This
->doc_host
->doc_host
.hwnd
, NULL
, docarea
.left
, docarea
.top
, docarea
.right
, docarea
.bottom
,
516 SWP_NOZORDER
| SWP_NOACTIVATE
);
518 SetWindowPos(hwndRebar
, NULL
, 0, 0, width
, barHeight
, SWP_NOZORDER
| SWP_NOACTIVATE
);
523 static LRESULT
iewnd_OnNotify(InternetExplorer
*This
, WPARAM wparam
, LPARAM lparam
)
525 NMHDR
* hdr
= (NMHDR
*)lparam
;
527 if(hdr
->idFrom
== IDC_BROWSE_ADDRESSBAR
&& hdr
->code
== CBEN_ENDEDITW
)
529 NMCBEENDEDITW
* info
= (NMCBEENDEDITW
*)lparam
;
531 if(info
->fChanged
&& info
->iWhy
== CBENF_RETURN
)
536 V_BSTR(&vt
) = SysAllocString(info
->szText
);
538 IWebBrowser2_Navigate2(&This
->IWebBrowser2_iface
, &vt
, NULL
, NULL
, NULL
, NULL
);
540 SysFreeString(V_BSTR(&vt
));
549 static LRESULT
iewnd_OnDestroy(InternetExplorer
*This
)
551 HWND hwndRebar
= GetDlgItem(This
->frame_hwnd
, IDC_BROWSE_REBAR
);
552 HWND hwndToolbar
= GetDlgItem(hwndRebar
, IDC_BROWSE_TOOLBAR
);
553 HIMAGELIST list
= (HIMAGELIST
)SendMessageW(hwndToolbar
, TB_GETIMAGELIST
, 0, 0);
557 free_fav_menu_data(get_fav_menu(This
->menu
));
558 ImageList_Destroy(list
);
559 This
->frame_hwnd
= NULL
;
564 static LRESULT
iewnd_OnCommand(InternetExplorer
*This
, HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
566 switch(LOWORD(wparam
))
569 DialogBoxParamW(shdocvw_hinstance
, MAKEINTRESOURCEW(IDD_BROWSE_OPEN
), hwnd
, ie_dialog_open_proc
, (LPARAM
)This
);
572 case ID_BROWSE_PRINT
:
573 if(This
->doc_host
->doc_host
.document
)
575 IOleCommandTarget
* target
;
577 if(FAILED(IUnknown_QueryInterface(This
->doc_host
->doc_host
.document
, &IID_IOleCommandTarget
, (LPVOID
*)&target
)))
580 IOleCommandTarget_Exec(target
, &CGID_MSHTML
, IDM_PRINT
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
582 IOleCommandTarget_Release(target
);
587 IWebBrowser2_GoHome(&This
->IWebBrowser2_iface
);
590 case ID_BROWSE_ABOUT
:
591 ie_dialog_about(hwnd
);
595 ShowWindow(hwnd
, SW_HIDE
);
599 if(LOWORD(wparam
) >= ID_BROWSE_GOTOFAV_FIRST
&& LOWORD(wparam
) <= ID_BROWSE_GOTOFAV_MAX
)
601 LPCWSTR url
= get_fav_url_from_id(get_fav_menu(This
->menu
), LOWORD(wparam
));
604 ie_navigate(This
, url
);
606 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
611 static LRESULT
update_addrbar(InternetExplorer
*This
, LPARAM lparam
)
613 HWND hwndRebar
= GetDlgItem(This
->frame_hwnd
, IDC_BROWSE_REBAR
);
614 HWND hwndAddress
= GetDlgItem(hwndRebar
, IDC_BROWSE_ADDRESSBAR
);
615 HWND hwndEdit
= (HWND
)SendMessageW(hwndAddress
, CBEM_GETEDITCONTROL
, 0, 0);
616 LPCWSTR url
= (LPCWSTR
)lparam
;
618 SendMessageW(hwndEdit
, WM_SETTEXT
, 0, (LPARAM
)url
);
623 static LRESULT CALLBACK
624 ie_window_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
626 InternetExplorer
*This
= (InternetExplorer
*) GetWindowLongPtrW(hwnd
, 0);
631 return iewnd_OnCreate(hwnd
, (LPCREATESTRUCTW
)lparam
);
634 ShowWindow(hwnd
, SW_HIDE
);
637 TRACE("WM_SHOWWINDOW %lx\n", wparam
);
639 IWebBrowser2_AddRef(&This
->IWebBrowser2_iface
);
641 IWebBrowser2_Release(&This
->IWebBrowser2_iface
);
644 return iewnd_OnDestroy(This
);
646 return iewnd_OnSize(This
, LOWORD(lparam
), HIWORD(lparam
));
648 return iewnd_OnCommand(This
, hwnd
, msg
, wparam
, lparam
);
650 return iewnd_OnNotify(This
, wparam
, lparam
);
652 return process_dochost_tasks(&This
->doc_host
->doc_host
);
653 case WM_UPDATEADDRBAR
:
654 return update_addrbar(This
, lparam
);
656 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
659 void register_iewindow_class(void)
663 memset(&wc
, 0, sizeof wc
);
664 wc
.cbSize
= sizeof(wc
);
666 wc
.lpfnWndProc
= ie_window_proc
;
668 wc
.cbWndExtra
= sizeof(InternetExplorer
*);
669 wc
.hInstance
= shdocvw_hinstance
;
670 wc
.hIcon
= LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON
));
671 wc
.hIconSm
= LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON
), IMAGE_ICON
,
672 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
673 wc
.hCursor
= LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW
));
674 wc
.hbrBackground
= 0;
675 wc
.lpszClassName
= szIEWinFrame
;
676 wc
.lpszMenuName
= NULL
;
678 RegisterClassExW(&wc
);
681 void unregister_iewindow_class(void)
683 UnregisterClassW(szIEWinFrame
, shdocvw_hinstance
);
686 static void create_frame_hwnd(InternetExplorer
*This
)
688 This
->frame_hwnd
= CreateWindowExW(
690 szIEWinFrame
, wszWineInternetExplorer
,
691 WS_CLIPCHILDREN
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
692 | WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
,
693 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
694 NULL
, NULL
/* FIXME */, shdocvw_hinstance
, This
);
697 static inline IEDocHost
*impl_from_DocHost(DocHost
*iface
)
699 return CONTAINING_RECORD(iface
, IEDocHost
, doc_host
);
702 static ULONG
IEDocHost_addref(DocHost
*iface
)
704 IEDocHost
*This
= impl_from_DocHost(iface
);
705 LONG ref
= InterlockedIncrement(&This
->ref
);
707 TRACE("(%p) ref=%d\n", This
, ref
);
712 static ULONG
IEDocHost_release(DocHost
*iface
)
714 IEDocHost
*This
= impl_from_DocHost(iface
);
715 LONG ref
= InterlockedDecrement(&This
->ref
);
717 TRACE("(%p) ref=%d\n", This
, ref
);
721 ERR("This->ie is not NULL\n");
728 static void WINAPI
DocHostContainer_GetDocObjRect(DocHost
* This
, RECT
* rc
)
730 GetClientRect(This
->frame_hwnd
, rc
);
731 adjust_ie_docobj_rect(This
->frame_hwnd
, rc
);
734 static HRESULT WINAPI
DocHostContainer_SetStatusText(DocHost
*iface
, LPCWSTR text
)
736 IEDocHost
*This
= impl_from_DocHost(iface
);
737 return update_ie_statustext(This
->ie
, text
);
740 static void WINAPI
DocHostContainer_SetURL(DocHost
* iface
, LPCWSTR url
)
742 IEDocHost
*This
= impl_from_DocHost(iface
);
747 This
->ie
->nohome
= FALSE
;
748 SendMessageW(This
->ie
->frame_hwnd
, WM_UPDATEADDRBAR
, 0, (LPARAM
)url
);
751 static HRESULT
DocHostContainer_exec(DocHost
* This
, const GUID
*cmd_group
, DWORD cmdid
, DWORD execopt
, VARIANT
*in
,
756 static const IDocHostContainerVtbl DocHostContainerVtbl
= {
759 DocHostContainer_GetDocObjRect
,
760 DocHostContainer_SetStatusText
,
761 DocHostContainer_SetURL
,
762 DocHostContainer_exec
765 static HRESULT
create_ie(InternetExplorer
**ret_obj
)
767 InternetExplorer
*ret
;
769 ret
= heap_alloc_zero(sizeof(InternetExplorer
));
771 return E_OUTOFMEMORY
;
773 ret
->doc_host
= heap_alloc_zero(sizeof(IEDocHost
));
776 return E_OUTOFMEMORY
;
780 ret
->doc_host
->ref
= 1;
781 ret
->doc_host
->ie
= ret
;
783 DocHost_Init(&ret
->doc_host
->doc_host
, (IDispatch
*)&ret
->IWebBrowser2_iface
, &DocHostContainerVtbl
);
785 InternetExplorer_WebBrowser_Init(ret
);
787 HlinkFrame_Init(&ret
->hlink_frame
, (IUnknown
*)&ret
->IWebBrowser2_iface
, &ret
->doc_host
->doc_host
);
789 create_frame_hwnd(ret
);
790 ret
->doc_host
->doc_host
.frame_hwnd
= ret
->frame_hwnd
;
792 InterlockedIncrement(&obj_cnt
);
793 list_add_tail(&ie_list
, &ret
->entry
);
798 HRESULT
InternetExplorer_Create(IUnknown
*pOuter
, REFIID riid
, void **ppv
)
800 InternetExplorer
*ret
;
803 TRACE("(%p %s %p)\n", pOuter
, debugstr_guid(riid
), ppv
);
805 hres
= create_ie(&ret
);
809 hres
= IWebBrowser2_QueryInterface(&ret
->IWebBrowser2_iface
, riid
, ppv
);
810 IWebBrowser2_Release(&ret
->IWebBrowser2_iface
);
817 void released_obj(void)
819 if(!InterlockedDecrement(&obj_cnt
))
823 static BOOL
create_ie_window(LPCSTR cmdline
)
825 InternetExplorer
*ie
;
828 hres
= create_ie(&ie
);
832 IWebBrowser2_put_Visible(&ie
->IWebBrowser2_iface
, VARIANT_TRUE
);
833 IWebBrowser2_put_MenuBar(&ie
->IWebBrowser2_iface
, VARIANT_TRUE
);
836 IWebBrowser2_GoHome(&ie
->IWebBrowser2_iface
);
842 while(*cmdline
== ' ' || *cmdline
== '\t')
844 cmdlen
= lstrlenA(cmdline
);
845 if(cmdlen
> 2 && cmdline
[0] == '"' && cmdline
[cmdlen
-1] == '"') {
850 if(cmdlen
== 7 && !memcmp(cmdline
, "-nohome", 7)) {
853 V_VT(&var_url
) = VT_BSTR
;
855 len
= MultiByteToWideChar(CP_ACP
, 0, cmdline
, cmdlen
, NULL
, 0);
856 V_BSTR(&var_url
) = SysAllocStringLen(NULL
, len
);
857 MultiByteToWideChar(CP_ACP
, 0, cmdline
, cmdlen
, V_BSTR(&var_url
), len
);
859 /* navigate to the first page */
860 IWebBrowser2_Navigate2(&ie
->IWebBrowser2_iface
, &var_url
, NULL
, NULL
, NULL
, NULL
);
862 SysFreeString(V_BSTR(&var_url
));
866 IWebBrowser2_Release(&ie
->IWebBrowser2_iface
);
870 static ULONG
open_dde_url(WCHAR
*dde_url
)
872 InternetExplorer
*ie
= NULL
, *iter
;
873 WCHAR
*url
, *url_end
;
877 TRACE("%s\n", debugstr_w(dde_url
));
882 url_end
= strchrW(url
, '"');
884 FIXME("missing string terminator\n");
889 url_end
= strchrW(url
, ',');
893 url_end
= url
+ strlenW(url
);
896 LIST_FOR_EACH_ENTRY(iter
, &ie_list
, InternetExplorer
, entry
) {
898 IWebBrowser2_AddRef(&iter
->IWebBrowser2_iface
);
905 hres
= create_ie(&ie
);
910 IWebBrowser2_put_Visible(&ie
->IWebBrowser2_iface
, VARIANT_TRUE
);
911 IWebBrowser2_put_MenuBar(&ie
->IWebBrowser2_iface
, VARIANT_TRUE
);
913 V_VT(&urlv
) = VT_BSTR
;
914 V_BSTR(&urlv
) = SysAllocStringLen(url
, url_end
-url
);
916 IWebBrowser2_Release(&ie
->IWebBrowser2_iface
);
920 hres
= IWebBrowser2_Navigate2(&ie
->IWebBrowser2_iface
, &urlv
, NULL
, NULL
, NULL
, NULL
);
924 IWebBrowser2_Release(&ie
->IWebBrowser2_iface
);
928 static HDDEDATA WINAPI
dde_proc(UINT type
, UINT uFmt
, HCONV hConv
, HSZ hsz1
, HSZ hsz2
, HDDEDATA data
,
929 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
933 TRACE("XTYP_CONNECT %p\n", hsz1
);
934 return (HDDEDATA
)!DdeCmpStringHandles(hsz1
, ddestr_openurl
);
941 TRACE("XTYP_EXECUTE %p\n", data
);
943 size
= DdeGetData(data
, NULL
, 0, 0);
949 url
= heap_alloc(size
);
953 if(DdeGetData(data
, (BYTE
*)url
, size
, 0) != size
) {
954 ERR("error during read\n");
958 ret
= (HDDEDATA
)open_dde_url(url
);
965 FIXME("XTYP_REQUEST\n");
969 TRACE("type %d\n", type
);
975 static void init_dde(void)
979 static const WCHAR iexploreW
[] = {'I','E','x','p','l','o','r','e',0};
980 static const WCHAR openurlW
[] = {'W','W','W','_','O','p','e','n','U','R','L',0};
982 res
= DdeInitializeW(&dde_inst
, dde_proc
, CBF_SKIP_ALLNOTIFICATIONS
| CBF_FAIL_ADVISES
| CBF_FAIL_POKES
, 0);
983 if(res
!= DMLERR_NO_ERROR
) {
984 WARN("DdeInitialize failed: %u\n", res
);
988 ddestr_iexplore
= DdeCreateStringHandleW(dde_inst
, iexploreW
, CP_WINUNICODE
);
990 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst
));
992 ddestr_openurl
= DdeCreateStringHandleW(dde_inst
, openurlW
, CP_WINUNICODE
);
994 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst
));
996 res
= (ULONG
)DdeNameService(dde_inst
, ddestr_iexplore
, 0, DNS_REGISTER
);
997 if(res
!= DMLERR_NO_ERROR
)
998 WARN("DdeNameService failed: %u\n", res
);
1001 static void release_dde(void)
1004 DdeNameService(dde_inst
, ddestr_iexplore
, 0, DNS_UNREGISTER
);
1006 DdeFreeStringHandle(dde_inst
, ddestr_openurl
);
1008 DdeFreeStringHandle(dde_inst
, ddestr_iexplore
);
1009 DdeUninitialize(dde_inst
);
1012 /******************************************************************
1013 * IEWinMain (SHDOCVW.101)
1015 * Only returns on error.
1017 DWORD WINAPI
IEWinMain(LPSTR szCommandLine
, int nShowWindow
)
1022 TRACE("%s %d\n", debugstr_a(szCommandLine
), nShowWindow
);
1024 list_init(&ie_list
);
1026 if(*szCommandLine
== '-' || *szCommandLine
== '/') {
1027 if(!strcasecmp(szCommandLine
+1, "regserver"))
1028 return register_iexplore(TRUE
);
1029 if(!strcasecmp(szCommandLine
+1, "unregserver"))
1030 return register_iexplore(FALSE
);
1035 hres
= register_class_object(TRUE
);
1043 if(strcasecmp(szCommandLine
, "-embedding")) {
1044 if(!create_ie_window(szCommandLine
)) {
1050 /* run the message loop for this thread */
1051 while (GetMessageW(&msg
, 0, 0, 0))
1053 TranslateMessage(&msg
);
1054 DispatchMessageW(&msg
);
1057 register_class_object(FALSE
);