Jump to content

VB ActiveX Controls


livewire
 Share

Recommended Posts

This post will have some examples of how to use ActiveX controls in AutoIt3 (use latest beta).

To use, you will need to register the ActiveX control (**using other people's ActiveX control is risky because of malware/virus issues...hence...use other people's controls at your own risk...I will post my source).

You can use this to register/unregister ActiveX controls.

#include <GUIConstants.au3>

Dim $dll_file = ""

$Form1 = GUICreate("RegsvrGUI", 400, 110, (@DesktopWidth - 400) / 2, (@DesktopHeight - 110) / 2)
$Label1 = GUICtrlCreateLabel("File: No File Selected", 16, 10, 400, 15)
$Group1 = GUICtrlCreateGroup("", 16, 30, 105, 73)
$Radio1 = GUICtrlCreateRadio("Register", 32, 40, 80, 25)
$Radio2 = GUICtrlCreateRadio("Unregister", 32, 70, 80, 25)
$Button1 = GUICtrlCreateButton("Browse", 136, 40, 57, 25)
$Button2 = GUICtrlCreateButton("OK", 136, 70, 59, 25)

GUICtrlSetState($Radio1,$GUI_CHECKED)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $Button1
        $dll_file = FileOpenDialog("Select dll/ocx to register/unregister",@ScriptDir,"Dynamic Linked Library (*.dll;*.ocx)",1)
        If Not @error Then GUICtrlSetData($Label1,"File: " & $dll_file)
    Case $msg = $Button2
        If $dll_file = "" Then
            MsgBox(0,"RegsvrGUI","Please select a file to register/unregister!")
        Else
            ExitLoop
        EndIf   
    Case Else
     ;;;;;;;
    EndSelect
WEnd


If GUICtrlRead($Radio1) = $GUI_CHECKED Then
    RunWait('regsvr32.exe /s "' & $dll_file & '"')
Else
    RunWait('regsvr32.exe /s /u "' & $dll_file & '"')
EndIf
MsgBox(0,"Testing","Registration complete")

I created some ActiveX controls in Visual Basic 6 (VB6) with the following properties (I will add/correct as necessary). Try 'em out...you get more events than using AutoIt3 native controls.

[VBControls.CommandButton]
    Events:
        Click()
        GotFocus()
        KeyDown(KeyCode As Integer, Shift As Integer)
        KeyPress(KeyAscii As Integer)
        KeyUp(KeyCode As Integer, Shift As Integer)
        LostFocus()
        MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Functions:
        SetBkColor(color As Long)
        SetCaption(caption As String)

[VBControls.Timer]
    Events:
        Fired()
    Functions:
        Enable()
        Disable()
        SetInterval(interval As long)

[VBControls.TextBox]
    Events:
        Change()
        Click()
        DblClick()
        GotFocus()
        KeyDown(KeyCode As Integer, Shift As Integer)
        KeyPress(KeyAscii As Integer)
        KeyUp(KeyCode As Integer, Shift As Integer)
        LostFocus()
        MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Functions:
        SetText(txt As String)
        GetText() As String

[VBControls.PictureBox]
    Events:
        Change()
        Click()
        DblClick()
        GotFocus()
        KeyDown(KeyCode As Integer, Shift As Integer)
        KeyPress(KeyAscii As Integer)
        KeyUp(KeyCode As Integer, Shift As Integer)
        LostFocus()
        MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Paint()
    Functions:
        SetBkColor(color As Long)
        Line(StartX As Single, StartY As Single, EndX As Single, EndY As Single, color As Long)
        SetPixel(X As Single, Y As Single, color As Long)

VBControls.zip

Edited by livewire
Link to comment
Share on other sites

*Fixed initial post so that TextBox initializes text to ""

*Fixed initial post so that Button initializes text to ""

Try this example:

#include <GuiConstants.au3>

Global $num = 0

GuiCreate("MyGUI", 300, 300 ,(@DesktopWidth - 300)/2, (@DesktopHeight - 300)/2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button = ObjCreate("VBControls.CommandButton")
$Input = ObjCreate("VBControls.TextBox")

GUICtrlCreateObj($Button, 10, 10, 100, 30)
GUICtrlCreateObj($Input, 10, 50, 100, 20)

ObjEvent($Button,"Button_")
ObjEvent($Input,"Input_")

$Button.SetBkColor(0xFF0000)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
          ;;;
    EndSelect
WEnd

Func Button_Click()
    MsgBox(0,"Testing","Button clicked" & @CRLF & _
                        "$Input.GetText = " & $Input.GetText)
EndFunc

Func Input_Change()
    $Button.SetCaption($Input.GetText)
EndFunc
Edited by livewire
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...