Print Friendly and PDF

InteractX - How does one create a browser control that looks like the message display?

I have source data that will be getting formatting in HTML and may contain links to images (Safety placards)

Previously we've been using a messagedisplay (Object/element on the right) as it has been plain text data - plain text displays well and the control looks like it belongs in Interact. 

Due to safety considerations, we need to improve the data displayed and need to use HTML - the browser object on left can do that, but to call it ugly would be charitable.

There's no apparent way to:

  • turn off the scroll bars.
  • attach buttons on the side like on the message display.
  • use buttons with VBA pass scroll up/down instruction to the browser control.

What I'd like to do is create another object that looks like the messagedisplay, but renders HTML   

Is there a template/guide anywhere on how to do so?

  • Broadly speaking I am calling Windows API methods for manipulating the mouse cursor location and click events

    When the browser control is clicked, I use the VB "Sendkeys" function to send page up / down or the arrow up / down keys.

    Here is what I've ended up doing: 

    On this panel, there is:

    • an "Action button" for exiting the runtime
    • 2x "Discrete button" 
      • "Scroll up" (called btnPageUp in VBA)
      • "Scroll down" (called btnPageDown in VBA)
    • a browser control (called BrowserDisplay001) 
      • "Type and Action" in the object properties (Machine shop window - not VBA)
        • "Expression" radio button set
        • URL_Tag is "URL_for_display"  (This tag will hold a file path and name)
    • a message display (Just to show the frame around the browser and buttons)

    In the project, I have created a module that exposes the Windows API via public functions.

    VBA module: VirtualMouse

    Option Explicit

    Public Const MOUSEEVENTF_LEFTDOWN As Long = &H2
    Public Const MOUSEEVENTF_LEFTUP As Long = &H4

    Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    Public Const MOUSEEVENTF_RIGHTUP As Long = &H10

    ' Access the GetSystemMetrics32 function in user32.dll to get the screen size (Pixels)
    Public Declare Function GetSystemMetrics32 Lib "User32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

    ' Access the GetCursorPos function in user32.dll - "Where did they click on the screen?"
    Public Declare Function GetCursorPos Lib "User32" _
    (lpPoint As POINTAPI) As Long

    ' Access the SetCursorPos function in user32.dll - "Where do you want to place the mouse pointer?)
    Public Declare Function SetCursorPos Lib "User32" _
    (ByVal x As Long, ByVal y As Long) As Long

    ' Access the mouse_event function in user32.dll - "Make the OS think a mouse did something"
    Public Declare Sub mouse_event Lib "User32" _
    (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    ' Access a sleep function that can use milliseconds in kernel32
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    ' Usage: Sleep t

    ' GetCursorPos/SetCursorPos requires a variable declared as a custom data type that will hold two integers, one for x value and one for y value
    Public Type POINTAPI
    X_Pos As Long
    Y_Pos As Long
    End Type

    Panel VBA

    Dim SavedCursor As POINTAPI

    Private Sub Panel_Activate()

    Tags.URL_for_Display.Value = "[Some local folder on the PC]\instructions.htm"

    End Sub

    Private Sub btnPageDown_ButtonPressed()

    GetCursorPos SavedCursor

    ' Get browser middle coordinates and click once on it (To set focus for sending the navigation keys)

    SendKeys "{DOWN}"

    SetCursorPos SavedCursor.X_Pos, SavedCursor.Y_Pos

    End Sub

    Private Sub btnPageUp_ButtonPressed()

    GetCursorPos SavedCursor


    SendKeys "{UP}"

    SetCursorPos SavedCursor.X_Pos, SavedCursor.Y_Pos

    End Sub

    Private Sub GetBrowserMidPos()

    ' Positions and dimensions reurned to VBA are NOT always the same as the cursor cordinates.
    ' * Cursor cordinates are in 'pixels'
    ' * VBA cordinates are in pixels when configured - BUT ...
    ' Panel resolution set at 800x600 with "scale to runtime resolution" enabled (This is the basis for the VBA co-ord)
    ' Screen maybe running 1920 x 1080 - the cursor postion uses this
    ' SCALING VBA SIZE to SCREEN SIZE is needed for the mouse click!

    Dim BrowserMid As POINTAPI
    Dim PanelSize As POINTAPI
    Dim ScreenSize As POINTAPI

    ' Insert VBA position
    BrowserMid.X_Pos = BrowserDisplay001.Left + (BrowserDisplay001.Width / 2)
    BrowserMid.Y_Pos = BrowserDisplay001.Top + (BrowserDisplay001.Height / 2)

    ' Find screen x and y sizes (Numbers returned match the display resolution in windows OS "Display properties")
    ScreenSize.X_Pos = GetSystemMetrics32(0) ' width in points
    ScreenSize.Y_Pos = GetSystemMetrics32(1) ' height in points

    PanelSize.X_Pos = Me.Width
    PanelSize.Y_Pos = Me.Height

    ' Scale the browser mid position
    BrowserMid.X_Pos = BrowserMid.X_Pos * ScreenSize.X_Pos / PanelSize.X_Pos
    BrowserMid.Y_Pos = BrowserMid.Y_Pos * ScreenSize.Y_Pos / PanelSize.Y_Pos

    ' Place the mouse cursor over the midpoint of the browser
    SetCursorPos BrowserMid.X_Pos, BrowserMid.Y_Pos

    ' Left click once
    Sleep 200 ' A delay of 100ms was not long enough for the mouse click to set focus
    mouse_event MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&
    mouse_event MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&

    End Sub

Reply Children
No Data