-
Oct 23rd, 2013, 09:24 AM
#1
Thread Starter
New Member
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.
-
Oct 23rd, 2013, 10:06 AM
#2
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
-
Oct 24th, 2013, 01:31 AM
#3
Thread Starter
New Member
Re: Need help with AppActivate to be able to use SendKeys
Originally Posted by Hack
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.
-
Oct 24th, 2013, 02:31 AM
#4
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
-
Oct 24th, 2013, 04:48 AM
#5
Thread Starter
New Member
Re: Need help with AppActivate to be able to use SendKeys
Originally Posted by stum
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|