Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
4.3 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include <exdisp.h>
  4. #include <htiframe.h>
  5. #define INITGUID
  6. #include <initguid.h>
  7. #include <shlguid.h>
  8. #include <mshtml.h>
  9. #include <comdef.h>
  10. const VARIANT c_vaEmpty = {0};
  11. #define PVAREMPTY ((VARIANT*)&c_vaEmpty)
  12. extern "C"
  13. BOOL
  14. IsIE3Installed(
  15. VOID
  16. )
  17. {
  18. HRESULT hr;
  19. IWebBrowserApp *pwb;
  20. hr = CoCreateInstance( CLSID_InternetExplorer,
  21. NULL,
  22. CLSCTX_LOCAL_SERVER,
  23. IID_IWebBrowserApp,
  24. (void **)&pwb );
  25. if (SUCCEEDED(hr)) {
  26. return TRUE;
  27. } else {
  28. return FALSE;
  29. }
  30. }
  31. extern "C"
  32. BOOL
  33. IsIE4Installed(
  34. VOID
  35. )
  36. {
  37. HRESULT hr;
  38. IWebBrowserApp *pwb;
  39. hr = CoCreateInstance( CLSID_InternetExplorer,
  40. NULL,
  41. CLSCTX_LOCAL_SERVER,
  42. IID_IWebBrowser2,
  43. (void **)&pwb );
  44. if (SUCCEEDED(hr)) {
  45. return TRUE;
  46. } else {
  47. return FALSE;
  48. }
  49. }
  50. extern "C"
  51. BOOL
  52. LaunchIE3Instance(
  53. LPWSTR szResourceURL
  54. )
  55. {
  56. HRESULT hr;
  57. int dx, dy;
  58. IWebBrowserApp *pwb;
  59. hr = CoCreateInstance(
  60. CLSID_InternetExplorer,
  61. NULL,
  62. CLSCTX_LOCAL_SERVER,
  63. IID_IWebBrowserApp,
  64. (void **)&pwb
  65. );
  66. if (SUCCEEDED(hr)) {
  67. // turn off chrome
  68. hr = pwb->put_MenuBar(FALSE);
  69. hr = pwb->put_StatusBar(FALSE);
  70. // hr = pwb->put_ToolBar(FALSE);
  71. // set client area size
  72. int iWidth = 466L;
  73. int iHeight = 286L;
  74. pwb->ClientToWindow(&iWidth, &iHeight);
  75. if (iWidth > 0)
  76. pwb->put_Width(iWidth);
  77. if (iHeight > 0)
  78. pwb->put_Height(iHeight);
  79. if ((dx = ((GetSystemMetrics(SM_CXSCREEN) - iWidth) / 2)) > 0) // center the on screen window
  80. pwb->put_Left(dx);
  81. if ((dy = ((GetSystemMetrics(SM_CYSCREEN) - iHeight) / 2)) > 0)
  82. pwb->put_Top(dy);
  83. pwb->put_Visible(TRUE);
  84. hr = pwb->Navigate(szResourceURL, PVAREMPTY, PVAREMPTY, PVAREMPTY, PVAREMPTY);
  85. pwb->Release();
  86. return(TRUE);
  87. }
  88. return(FALSE);
  89. }
  90. extern "C"
  91. BOOL
  92. LaunchIE4Instance(
  93. LPWSTR szResourceURL
  94. )
  95. {
  96. HRESULT hr;
  97. HWND hwndIE;
  98. int dx, dy;
  99. IWebBrowser2 *pwb;
  100. hr = CoCreateInstance(
  101. CLSID_InternetExplorer,
  102. NULL,
  103. CLSCTX_LOCAL_SERVER,
  104. IID_IWebBrowser2,
  105. (void **)&pwb
  106. );
  107. if (SUCCEEDED(hr)) {
  108. DWORD dwFlags;
  109. ITargetFrame2* ptgf;
  110. //
  111. // this marks this window as a third party window,
  112. // so that the window is not reused.
  113. //
  114. pwb->put_RegisterAsBrowser(VARIANT_TRUE);
  115. IHTMLWindow2 *phw;
  116. IServiceProvider *psp;
  117. if (SUCCEEDED(pwb->QueryInterface(IID_IServiceProvider, (void**) &psp)) && psp) {
  118. if (SUCCEEDED(psp->QueryService(IID_IHTMLWindow2, IID_IHTMLWindow2, (void**)&phw))) {
  119. VARIANT var;
  120. var.vt = VT_BOOL;
  121. var.boolVal = 666;
  122. phw->put_opener(var);
  123. phw->Release();
  124. } else
  125. MessageBox(NULL, TEXT("QueryInterface of IID_IHTMLWindow2 FAILED!!!!!"), NULL, MB_ICONERROR);
  126. psp->Release();
  127. }
  128. // turn off chrome
  129. pwb->put_MenuBar(FALSE);
  130. pwb->put_StatusBar(FALSE);
  131. // pwb->put_ToolBar(FALSE);
  132. pwb->put_AddressBar(FALSE);
  133. // pwb->put_Resizable(FALSE);
  134. // set client area size
  135. int iWidth = 466L;
  136. int iHeight = 286L;
  137. pwb->ClientToWindow(&iWidth, &iHeight);
  138. if (iWidth > 0)
  139. pwb->put_Width(iWidth);
  140. if (iHeight > 0)
  141. pwb->put_Height(iHeight);
  142. if ((dx = ((GetSystemMetrics(SM_CXSCREEN) - iWidth) / 2)) > 0) // center the on screen window
  143. pwb->put_Left(dx);
  144. if ((dy = ((GetSystemMetrics(SM_CYSCREEN) - iHeight) / 2)) > 0)
  145. pwb->put_Top(dy);
  146. pwb->put_Visible(TRUE);
  147. pwb->get_HWND((LONG_PTR*)&hwndIE);
  148. SetForegroundWindow(hwndIE);
  149. hr = pwb->Navigate(szResourceURL, PVAREMPTY, PVAREMPTY, PVAREMPTY, PVAREMPTY);
  150. pwb->Release();
  151. return(TRUE);
  152. }
  153. return(FALSE);
  154. }