Advertisement

08.02.2008 at 01:13PM PDT, ID: 23616554
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

How to send a keystoke to an app in VB6

Asked by bpl5000 in Visual Basic Programming

Tags:

In a VB6 program, I want to open an application (maybe using shell) and send a keystroke (enter) to the app whether it is in focus or minimized or whatever.  I found the following code here on EE and it works great for sending text to an app, but I just want to send a single key (the enter key).  I tried to substitute SendMessageSTR with SendMessage, but I must be doing something wrong.  Can someone help me to modify the code or suggest a better way.

--------------------------------------------------
' PUT THE FOLLOWING IN A MODULE:
'--------------------------------------------------

Option Explicit

Private Const WM_SETTEXT = &HC

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageSTR Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Public Function SendString(ByVal hWnd As Long, ByVal TheString As String) As Boolean
 
  ' Check for a valid handle
  If hWnd = 0 Then
    Exit Function
  End If
 
  ' Send the string via the SendMessage API (altered for sending strings)
  If SendMessageSTR(hWnd, WM_SETTEXT, 0, TheString) = 0 Then
    MsgBox "Error sending the string"
    Exit Function
  End If
 
  SendString = True
 
End Function

Public Sub Main()
 
  Dim HandleWin As Long
  Dim HandleEdit As Long
 
  ' Find the handle to the NOTEPAD window
  HandleWin = FindWindow("Notepad", "Untitled - Notepad")
  If HandleWin = 0 Then
    MsgBox "Couldn't find the window handle"
    Exit Sub
  End If
 
  ' Find the handle to the text area of the NOTEPAD window found
  HandleEdit = FindWindowEx(HandleWin, 0, "Edit", vbNullString)
  If HandleEdit = 0 Then
    MsgBox "Couldn't find the text area of the window"
    Exit Sub
  End If
 
  SendString HandleEdit, "Check it out... it works!!"
 
End SubStart Free Trial
[+][-]08.02.2008 at 01:19PM PDT, ID: 22145502

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.02.2008 at 01:55PM PDT, ID: 22145602

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.02.2008 at 02:12PM PDT, ID: 22145680

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.02.2008 at 02:15PM PDT, ID: 22145692

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: VB6
Sign Up Now!
Solution Provided By: LordOfPorts
Participating Experts: 4
Solution Grade: A
 
 
[+][-]08.02.2008 at 05:57PM PDT, ID: 22146162

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.02.2008 at 06:23PM PDT, ID: 22146191

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.02.2008 at 06:49PM PDT, ID: 22146226

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.02.2008 at 07:24PM PDT, ID: 22146262

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.02.2008 at 08:25PM PDT, ID: 22146358

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 06:44AM PDT, ID: 22147559

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 09:21AM PDT, ID: 22147983

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 05:34PM PDT, ID: 22149338

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628