#
Dim All
#Include "win32api.inc"
%ID_OCX = 1001
%IDC_URL = 1010
%IDC_BTNAVG = 1011
%IDC_BTBACK = 1012
%IDC_BTFRWD = 1013
%IDC_LABEL1 = 1014
Global hDlg
As Dword
Global hOcx
As Dword
Global oOcx
As Dispatch
Declare Function AtlAxWinInit
Lib "ATL.DLL"
Alias "AtlAxWinInit" ()
As Long
' *********************************************************************************************
Declare Function AtlAxWinTerm ()
As Long
' *********************************************************************************************
Function AtlAxWinTerm ()
As Long
UnregisterClass ("AtlAxWin", GetModuleHandle(
ByVal %NULL))
End Function
' *********************************************************************************************
' **********************************************************************************************
Declare Function AtlAxGetControl
Lib "ATL.DLL"
Alias "AtlAxGetControl" _
 
_
ByVal hWnd
As Dword, _
' [in] A handle to the window that is hosting the control.
ByRef pp
As Dword _
' [out] The IUnknown of the control being hosted.
 
As Dword
' *********************************************************************************************
' *********************************************************************************************
' Puts the address of an object in a variant and marks it as containing a dispatch variable
' *********************************************************************************************
Sub AtlMakeDispatch ( _
ByVal lpObj
As Dword, _
' Address of the object instance
ByRef vObj
As Variant _
' Variant to contain this address
 
Export
Local lpvObj
As VARIANTAPI Ptr
' Pointer to a VARIANTAPI structure
Let vObj = Empty
' Make sure is empty to avoid memory leaks
lpvObj = VarPtr(vObj)
' Get the VARIANT address
@lpvObj.vt = %VT_Dispatch
' Mark it as containing a dispatch variable
@lpvObj.vd.pdispVal = lpObj
' Set the dispatch pointer address
End Sub
' *********************************************************************************************
' *********************************************************************************************
' Main dialog callback
' *********************************************************************************************
CallBack
Function MainDlgProc()
Local rc
As RECT
Local r
As Long
Local x
As Long
Local y
As Long
Local xx
As Long
Local yy
As Long
Select Case CbMsg
Case %WM_SIZE
GetClientRect CbHndl, rc
x = rc.nLeft
y = rc.nTop
xx = rc.nRight - rc.nLeft
yy = rc.nBottom - rc.nTop - 32
MoveWindow hOcx, x, y, xx, yy, %TRUE
Case %WM_DESTROY
PostQuitMessage 0
Case %WM_COMMAND
Select Case CbCtl
Case %IDCANCEL
If CbCtlMsg = %BN_CLICKED
Or CbCtlMsg = 1
Then
 
ialog
End CbHndl, 0
End If
Case %IDC_BTNAVG
If CbCtlMsg = %BN_CLICKED
Or CbCtlMsg = 1
Then
Local strUrl
As String, vVar
As Variant
Control
Get Text CbHndl, %IDC_URL
To strUrl
vVar = strUrl
Object Call oOcx.Navigate(vVar)
End If
Case %IDC_BTBACK
If CbCtlMsg = %BN_CLICKED
Or CbCtlMsg = 1
Then
Object Call oOcx.GoBack
End If
Case %IDC_BTFRWD
If CbCtlMsg = %BN_CLICKED
Or CbCtlMsg = 1
Then
Object Call oOcx.GoForward
End If
End Select
End Select
End Function
' *********************************************************************************************
' *********************************************************************************************
' Main
' *********************************************************************************************
Function PBMain
Local hInst
As Dword
Local hr
As Dword
Local OcxName
As Asciiz * 255
Local pUnk
As Dword
Local vVar
As Variant
Local uMsg
As tagMsg
OcxName = "Shell.Explorer"
AtlAxWinInit
' // Initializes ATL
 
ialog
New 0, "A Web Browser in a DDT dialog",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0
To hDlg
Control Add "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE
Or %WS_CHILD
Control Handle hDlg, %ID_OCX
To hOcx
Control Add Label, hDlg, %IDC_LABEL1, "URL", 226, 322, 16, 12
Control Add TextBox, hDlg, %IDC_URL, "", 250, 320, 210, 14
Control Add Button, hDlg, %IDC_BTNAVG, "&Navigate", 470, 320, 46, 14, %WS_TABSTOP
Or %BS_DEFAULT
Control Add Button, hDlg, %IDC_BTBACK, "&Back", 5, 320, 46, 14, %WS_TABSTOP
Control Add Button, hDlg, %IDC_BTFRWD, "&Forward", 58, 320, 46, 14, %WS_TABSTOP
Control
Set Text hDlg, %IDC_URL, "http://www.powerbasic.com"
AtlAxGetControl(hOcx, pUnk)
AtlMakeDispatch(pUnk, vVar)
Set oOcx = vVar
SetFocus(hOcx)
 
ialog Show Modal hDlg,
Call MainDlgProc
To hr
AtlAxWinTerm
' // Uninitializes ATL
Set oOcx =
Nothing
End Function