Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created February 12, 2017 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kumatti1/784839cef2114394b67a77455a4d06ee to your computer and use it in GitHub Desktop.
Save kumatti1/784839cef2114394b67a77455a4d06ee to your computer and use it in GitHub Desktop.
Option Explicit
Private Declare Function WindowFromAccessibleObject Lib "oleacc.dll" ( _
ByVal IAcessible As Object, _
ByRef hwnd As LongPtr _
) As Long
Private Declare _
Function SetWindowLongW Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr _
) As LongPtr
Private Declare _
Function SetParent Lib "user32.dll" ( _
ByVal hWndChild As LongPtr, _
ByVal hWndNewParent As LongPtr _
) As LongPtr
Private Type Rect
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Declare _
Function GetClientRect Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
lpRect As Rect _
) As Long
Private Declare _
Function SetWindowPos Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal hWndInsertAfter As LongPtr, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal uFlags As Long _
) As Long
Private Declare _
Function AtlAxWinInit Lib "atl.dll" () As Long
Private Declare _
Function AtlAxAttachControl Lib "atl.dll" ( _
ByVal pControl As stdole.IUnknown, _
ByVal hwnd As LongPtr, _
ppUnkContainer As LongPtr _
) As LongPtr
Private Declare PtrSafe Function GetTopWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const GWL_STYLE = (-16)
Private WithEvents ie As SHDocVw.InternetExplorer
Private m_pContainer As LongPtr
Private Sub UserForm_Initialize()
Set ie = New InternetExplorer
Dim h As LongPtr
WindowFromAccessibleObject Me, h
h = GetTopWindow(h)
Dim hwndie As LongPtr
hwndie = ie.hwnd
Dim ws As Long
ws = WS_CHILD Or WS_VISIBLE
SetWindowLongW hwndie, GWL_STYLE, ws
SetParent hwndie, h
Dim rc As Rect
GetClientRect h, rc
SetWindowPos hwndie, 0, _
0, 0, rc.right - rc.left, rc.bottom - rc.top + 20, 0
Debug.Print Hex(AtlAxWinInit), "a"
Debug.Print AtlAxAttachControl(ie, h, m_pContainer), "b"
ie.Navigate "https://www.google.co.jp/"
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment