WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.X
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WebBrowser Control HTML Dialog


Question:

Anyway to embed an HTML Document rendered by IE within a WinBatch Dialog anytime? Sorta like HTML Dlg, but regular controls on the Dialog could manipulate the HTML through OLE.

Answer:

;WebBrowser control
;11/02 Guido

;ATLInit : Initializes ATL's control hosting code, necessary for the
;          browser functions.
;Returns : ATL dll handle. You can free this handle on program exit using dllfree()
#definefunction ATLInit()
	errormode(@off)
	atl=dllload(strcat(dirwindows(1),'atl.dll'))
	errormode(@on)
	if atl<>0
		if dllcall(atl,long:'AtlAxWinInit') then return atl
		else return 0
	else
		return 0
	endif
#endfunction

;BrowserCreate : Creates a webbrowser control.
;handle : dialog handle
;x      : browser x position inside dialog
;y      : browser y position inside dialog
;w      : browser width
;h      : browser height
;Returns: 2 elemnt array
;         0 : browser window handle
;         1 : browser OLE handle                                                
#definefunction BrowserCreate(handle,x,y,w,h)
	WS_EX_CLIENTEDGE=512
	WS_CHILD=1073741824
	WS_VISIBLE=268435456
	user32=strcat(dirwindows(1),'user32.dll')
	hinst=dllhinst('')
	aret=arrdimension(2)
	aret[0]=dllcall(user32,long:'CreateWindowExA',long:WS_EX_CLIENTEDGE,lpstr:'AtlAxWin',lpstr:'Shell.Explorer.1',long:WS_CHILD|WS_VISIBLE,long:x,long:y,long:w,long:h,long:handle,long:1,long:hinst,long:0)
	
	;get ole handle
	oShellApp=Objectopen('Shell.Application')
	oWindows=oShellApp.Windows()
	count=oWindows.Count    
	aret[1]=oWindows.Item(count-1) ;ole handle
	objectclose(oWindows)
	objectclose(oShellApp)
	return aret
#endfunction

;+---------------------
;dialog procedure
#definesubroutine dlgproc(handle,msg,id,p4,p5)
	select msg
		case 0 ;Init
			DialogProcOptions(handle,2,1) ;BUT
	
			hatl=ATLInit()
			if hatl==0
				message('Error','Unable to initialize atl lib')
				exit
			endif
	
			;create browser control
			awb=browsercreate(handle,20,60,660,350)
			hbrowser=awb[0] ;window handle
			obrowser=awb[1] ;object handle
			drop(awb)
	
		case 2 ;Button pushed
			select id
				case 1 ;go
					url=DialogControlGet(handle,3,3) 
					if url<>'' then obrowser.navigate(url,0,'','','')
					return -2
		
				case 4 ;exit
					return -1
			endselect
	endselect
	return -1
#endsubroutine


MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`WinBatch Web Browser`
MyDialogX=-1
MyDialogY=-1
MyDialogWidth=352
MyDialogHeight=218
MyDialogNumControls=004
MyDialogProcedure=`dlgproc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`

MyDialog001=`265,007,036,012,PUSHBUTTON,DEFAULT,"Go",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`009,007,020,010,STATICTEXT,DEFAULT,"URL:",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`033,007,226,012,EDITBOX,MyVariable1,"",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`305,007,036,012,PUSHBUTTON,DEFAULT,"Exit",2,2,32,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

;free
objectclose(obrowser)
dllfree(hatl)
EXIT


Here is UDF to map Windows x,y to Winbatch's....


;// UDF's for the HTML control courtesy of Guido

;------------------------------------------------------------------------------;
;DlgUnitsToPixels : Converts from dialog units to pixel units. Asumes that the ;
; dialog uses the system font. ;
;------------------------------------------------------------------------------;
;dx,dy,dw,dh : dialog units ;
;------------------------------------------------------------------------------;
;Returns : A string with the converted units: x,y,w,h ;
;changed to return an array, Stan Littlefield 12/13/2002 ;
;------------------------------------------------------------------------------;
#DefineFunction DlgUnitsToPixels(dx,dy,dw,dh)
aPixels = ArrDimension( 4,0,0,0,0 )
arrInitialize( aPixels, 0 )
user32=strcat(dirwindows(1),"user32.dll")
kernel32=strcat(dirwindows(1),"kernel32.dll")
bubuf=binaryalloc(4)

;Get Dialog BaseUnits
bu=dllcall(user32,long:"GetDialogBaseUnits")
binarypoke4(bubuf,0,bu)
hu=binarypeek2(bubuf,0) ;horizontal dlg base unit
vu=bu >> 16 ;vertical dlg base unit
binaryfree(bubuf)

;convert to pixels
aPixels[0]=dllcall(kernel32,long:"MulDiv",long:dx,long:hu,long:4)
aPixels[1]=dllcall(kernel32,long:"MulDiv",long:dy,long:vu,long:8)
aPixels[2]=dllcall(kernel32,long:"MulDiv",long:dw,long:hu,long:4)
aPixels[3]=dllcall(kernel32,long:"MulDiv",long:dh,long:vu,long:8)

return ( aPixels )
#EndFunction 

Article ID:   W16416
File Created: 2005:02:18:12:20:28
Last Updated: 2005:02:18:12:20:28