Results 1 to 5 of 5

Thread: Need help with AppActivate to be able to use SendKeys

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    3

    Need help with AppActivate to be able to use SendKeys

    I am using VB6 on Windows XP.

    I have earlier used SendKeys after Shell without using AppActivate on Windows NT with VB3, but that does not work any more.

    I can get Paint to start with Shell on MSPAINT.EXE with its path. But AppActivate "PAINT" or "MSPAINT" does not work. AppActivate Xn, True with Xn = Shell... also did not work. Can someone help me with this?

    Apparently, I cannot get the focus on Paint window without this command. Is that true?

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help with AppActivate to be able to use SendKeys

    Welcome to the forums

    Try using the API approach
    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
    ShellExecute Me.hwnd, vbNullString, "mspaint", vbNullString, "C:\", SW_SHOWNORMAL
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    3

    Re: Need help with AppActivate to be able to use SendKeys

    Quote Originally Posted by Hack View Post
    Welcome to the forums

    Try using the API approach
    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
    ShellExecute Me.hwnd, vbNullString, "mspaint", vbNullString, "C:\", SW_SHOWNORMAL
    End Sub
    Thanks for your reply. It results in a compile error: Invalid use of Me keyword.

    What was wrong with using Shell? It does start MS Paint quite well but does not shift the focus to that window. Will this shift the focus to the Paint window?

    Do I need AppActivate? And if yes, why does it not work? Thanks.

  4. #4
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Need help with AppActivate to be able to use SendKeys

    Try to change "Me" to "Form1", or you may use this code:

    Code:
    Private Sub Form_Load()
         Call Shell("mspaint", vbNormalFocus)
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    3

    Re: Need help with AppActivate to be able to use SendKeys

    Quote Originally Posted by stum View Post
    Try to change "Me" to "Form1", or you may use this code:

    Code:
    Private Sub Form_Load()
         Call Shell("mspaint", vbNormalFocus)
    End Sub
    It still wrote the keys on the form from which I sent the keys.

    Here is the code:

    Sub bmp_in_16(Filnamn As String)

    Dim PaintCommand As String, PaintPath As String

    Call PaintDir(PaintPath)
    PaintCommand = PaintPath & "MSPAINT.EXE " & Filnamn
    If FileExists(PaintPath & "MSPAINT.EXE") < 1 Then Exit Sub

    If InStr(PaintPath, "WINNT") Then ' This used to work perfectly for over 10 years
    Xnothing = Shell(PaintCommand, 1)
    SendKeys "%FA{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{UP}{UP}{UP}{TAB}{ENTER}Y%FX", True
    End If
    If InStr(PaintPath, "WINDOWS") Then
    If IsVista() = 1 Then ' SendKeys does not work
    SendKeys "%FA{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{UP}{UP}{UP}{UP}{UP}{UP}{TAB}{TAB}{ENTER}Y%FX", True
    Exit Sub
    Else ' it is Windows XP, and this does not work either
    Xnothing = Shell(PaintCommand, 1)
    SendKeys "%FA{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{UP}{UP}{UP}{UP}{UP}{UP}{TAB}{ENTER}YY%FX", True
    End If
    End If

    End Sub

    Can someone tell me what I am doing wrong? Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width