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 Inside Dialogs Written by Guido

Keywords: 	 WebBrowser inside dialogs 

After reading the post in the ole area regarding to access an active instance of IE, I think I figured out how to access the browser object with the WIL OLE functions.

If this is confirmed to work, it can be very interesting because i think you can use more objects an even ActiveX controls. So far, we know it works on on Win98SE and Win2k.

There are some limitations, like there no way to make this work so that TAB (or some other key) will move the cursor around the dialog buttons and the links on the web page. And the webbrowser control is usable, but the method to get the handle only works with shell windows. For example, you can put the AMOVIE.ActiveMovieControl inside the dialog, but you can't use it.

To run this, you have to type an url and click go.


;WebBrowser control
;11/02 Guido

;-------------------------------------------------------------------------------;
;BrowserInit : Initializes the browser functions,it must be called              ;
;              at the beginning                                                 ;
;-------------------------------------------------------------------------------;
;Returns : a handle to be used with BrowserFree or 0 if it fails                ;
;-------------------------------------------------------------------------------;
#definefunction BrowserInit()
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

;--------------------------------------------------------------------------------;
;BrowserFree : Finishes the browser functions, it must be called always after    ;
;              the dialog has vanished.                                          ;
;--------------------------------------------------------------------------------;
;hinit    : handle returned by BrowserInit                                       ;
;hbrowser : handle returned by BrowserGetObject                                  ;
;Returns  : always 0                                                             ;
;--------------------------------------------------------------------------------;
#definefunction BrowserFree(hinit,hbrowser)
objectclose(hbrowser)
return dllfree(hinit)
#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                                                         ;
;url    : initial url if any                                                     ;
;Returns: browser handle                                                         ;
;--------------------------------------------------------------------------------;
;API EXStyle : WS_EX_CLIENTEDGE                                                  ;
;    Style   : WS_CHILD|WS_VISIBLE                                               ;
;--------------------------------------------------------------------------------;
#definefunction browsercreate(handle,x,y,w,h)
user32=strcat(dirwindows(1),"user32.dll")
hinst=dllhinst("")
return dllcall(user32,long:"CreateWindowExA",long:512,lpstr:"AtlAxWin",lpstr:"Shell.Explorer.1",long:1073741824|268435456,long:x,long:y,long:w,long:h,long:handle,long:0,long:hinst,long:0)
#endfunction

;--------------------------------------------------------------------------------;
;BrowserGetObject : Gets the object handle of the previously created webbrowser  ;
;                   control.                                                     ;
;--------------------------------------------------------------------------------;
;Returns : A object handle to be used when referring to the object               ;
;--------------------------------------------------------------------------------;
#definefunction BrowserGetObject()
oShellApp=Objectaccess("Shell.Application",1)
oWindows=oShellApp.Windows()
count=oWindows.Count    
obrowser=oWindows.Item(count-1)
objectclose(oShellApp)
return obrowser
#endfunction

;TEST
hinit=browserinit()
if hinit==0
  message("Error","Unable to initialize atl lib")
  exit
endif

;dialog procedure
#definesubroutine dlgproc(handle,msg,id,p4,p5)
select msg
  case 0 ;Init
    DialogProcOptions(handle,2,1) ;Push buttons
    
    ;create browser control
    browsercreate(handle,20,60,660,350)

    ;get object handle
    obrowser=BrowserGetObject()

    return -1

  case 2 ;Button pushed
    select id
      case 1 ;go
        url=DialogControlGet(handle,3,3) 
        if url<>""
          obrowser.navigate(url,0,"","","")
        endif
        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,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

browserfree(hinit,obrowser)
;endscript


Sizing Custom Browser Controls

Question:

In the example above, the script with API Calls places a Web Browser control within a WB Dialog. The key function
;--------------------------------------------------------------------------------;
;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 ;
;url : initial url if any ;
;Returns: browser handle ;
;--------------------------------------------------------------------------------;
;API EXStyle : WS_EX_CLIENTEDGE ;
; Style : WS_CHILD|WS_VISIBLE|WS_VSCROLL ;
;--------------------------------------------------------------------------------;
#definefunction browsercreate(handle,x,y,w,h,url)
user32=strcat(dirwindows(1),"user32.dll")
hinst=dllhinst("")
return dllcall(user32,long:"CreateWindowExA",long:512,lpstr:"AtlAxWin",lpstr:url,long:1073741824|268435456|2097152,long:x,long:y,long:w,long:h,long:handle,long:0,long:hinst,long:0)
#endfunction
sizes the browse control within the dialog. His example drew a huge WB dialog, prompted for a URL. I want to create smaller dialogs and post coordinates to the control relative to the coordinates of the Dialog. For example, I attached a .wdl with a listbox that is pretty much the size of the dialog except for the cancel button below. What I would like to know is how to calculate the x,y values for Guido's control so it appears in the dialog exactly like he listbox does now.

Answer:

I think this works, but only if the dialog uses the system font:
;------------------------------------------------------------------------------;
;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                          ;
;------------------------------------------------------------------------------;
#definefunction DlgUnitsToPixels(dx,dy,dw,dh)
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
px=dllcall(kernel32,long:"MulDiv",long:dx,long:hu,long:4)
py=dllcall(kernel32,long:"MulDiv",long:dy,long:vu,long:8)
pw=dllcall(kernel32,long:"MulDiv",long:dw,long:hu,long:4)
ph=dllcall(kernel32,long:"MulDiv",long:dh,long:vu,long:8)

return strcat(px,",",py,",",pw,",",ph)
#endfunction

;so the coordinates for the browsercreate function 
;should be:

message("",DlgUnitsToPixels(004,002,184,091))

Article ID:   W15484
File Created: 2003:05:13:11:28:06
Last Updated: 2003:05:13:11:28:06