• How to auto start an AVI in Visual Basic Classic

    Maxim6m0cj Member

    How to auto start an AVI in Visual Basic Classic

  • Abhey Member

    I can’t help with the avi control but here’s how to position the mouse and force a double-click. (from MSDN)
    First Abstract
    This article explains how to position the mouse pointer over a specific control in a Microsoft® Visual Basic® application.
    Positioning the Mouse Pointer
    Sometimes you may need to position the mouse pointer over a specific control in a Microsoft® Visual Basic® application, even though that control does not have the current focus.
    To position the mouse pointer over a specific control, you need to use the Microsoft Windows® application programming interface (API) GetWindowRect and SetCursorPos functions. The GetWindowRect function is used to retrieve the coordinates of a control. The Declare statement for the GetWindowRect function is:

    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect
    As RECT) As Long

    The GetWindowRect function requires two arguments. The first argument is the handle of the control. The second argument is the address of a RECT structure.
    After calling the GetWindowRect function, the control's coordinates are stored in the RECT structure. The RECT structure is defined as:

    Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
      

    Note that the left, top, right, and bottom positions of the control are stored in the RECT structure. After you know the exact position of the control, you need to use the SetCursorPos function to position the mouse pointer directly over the control. The Declare statement for the SetCursorPos function is:

     
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long,
       ByVal y As Long) As Long
      

    Then, to position the mouse pointer over the control, you retrieve the coordinates of the control's upper-left corner by using the values stored in the Left field and Top field of the RECT structure. Next, you call the SetCursorPos function with these two values to actually position the mouse pointer over the control.
    Example Program
    This program shows how to move the mouse pointer over a specific control.
    1.Create a new project in Visual Basic. Form1 is created by default.
    2.Add the following Declare statements to the General Declarations section of Form1 (note that each Declare statement must be typed as a single line of code):

    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect
       As RECT) As Long
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As
       Long) As Long
      

    3.Add the following code to the Form_Load event for Form1:

    Private Sub Form_Load()
        Dim MousePos As RECT
    
        Call GetWindowRect(Command2.hwnd, MousePos)
        Call SetCursorPos(MousePos.Left, MousePos.Top)
    End Sub
      

    4.Add a Command Button control to Form1. Command1 is created by default. Set its Default property to False.
    5.Add a second Command Button control to Form1. Command2 is created by default. Set its Default property to True.
    6.From the Visual Basic Insert menu, select Module to create a new module. Module1.Bas is created by default.
    7.Add the following Type structure to Module1.Bas:

    Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
      
    Run the example program by pressing F5. Notice that the focus is set to the first Command Button control, but the mouse pointer is positioned over the second Command Button control. In short, the mouse pointer is placed over the control whose Default property is set to True.
    
    Second Abstract
    This article explains how to allow the user of your Microsoft® Visual Basic® application use the ENTER key, instead of double-clicking with the mouse, to select a directory.
    Using the ENTER Key to Select Directories
    
    The Microsoft® Visual Basic® Directory List Box control displays a list of all directories stored on the specified disk drive. You can select a specific directory to work with by double-clicking its entry in the control. The selected directory can then be manipulated by your Visual Basic application.
    
    You may, however, want to select a directory from the Directory List Box control by pressing the ENTER key instead of double-clicking with the mouse. This functionality can be accomplished by monitoring the KeyPress event of the Directory List Box control.
    
    Whenever a key is pressed on the keyboard, a KeyPress event is triggered in the control that has the focus. A special number representing that particular key is stored in the KeyPress event's KeyAscii variable. You can then test the KeyAscii variable to determine whether a specific key, such as ENTER, was pressed on the keyboard.
    
    In the example program below, each time a KeyPress event is triggered, the focus is set to the Directory List Box control. The KeyAscii variable is then tested to determine whether ENTER (represented by the number 13) was pressed. Next, a WM_LBUTTONDBLCLK (double-click) message is sent to the Directory List Box control by using the Microsoft Windows® application programming interface (API) SendMessage function. 
    
    The KeyAscii variable is then set to a value of zero, which prevents the beep from being played on the computer's speaker. Finally, the default directory is changed to the newly selected directory.
    
    Example Program
    This program shows how to emulate a double-click event in a Directory List Box control with the ENTER key.
     1.Create a new project in Visual Basic. Form1 is created by default.
     2.Add the following Constant and Declare statements to the General Declarations section of Form1 (note that each statement must be typed as a single line of code):
    
    Private Declare Function GetFocus Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
       (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer,
       ByVal lParam As Long) As Long
    Const WM_LBUTTONDBLCLK = &H203
     

    3.Add the following code to the Form_Load event for Form1:

    Private Sub Form_Load()
        Text1.Text = ""
        Text1.Text = CurDir$
    End Sub
     

    4. Add a Text Box control to Form1. Text1 is created by default.
    5. Add a Directory List Box control to Form1. Dir1 is created by default.
    6. Add the following code to the Dir1_KeyPress event for Dir1:

    Private Sub Dir1_KeyPress(KeyAscii As Integer)
        Dim R As Long
        Dim DirHwnd As Integer
        Dim X As String
        If KeyAscii = 13 Then
            Dir1.SetFocus
            DirHwnd = GetFocus()
            R = SendMessage(DirHwnd, WM_LBUTTONDBLCLK, 0, 0)
            KeyAscii = 0
        End If
        X = Dir1.Path
        ChDir X
        Text1.Text = CurDir$
    End Sub
     

    Run the example program by pressing F5. The Directory List Box control displays a list of directories found on your hard drive. The name of the default directory appears in the Text Box control.

    Select a directory from the Directory List Box control by pressing the first letter of the directory name or by clicking the directory name. Press ENTER. The currently selected directory is now the default directory.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish