Solved

communicating with other apps. in VC++

Posted on 1997-12-09
6
245 Views
Last Modified: 2012-06-22
In VBA there is a way to communicate with other
applications via the SendKeys command, is it possible to
implement a similar function in Visual C++?
How about "Shell" and "AppActivate"?
0
Comment
Question by:quiller
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1175591
C can do anything VB or VBA can do.

I don't know the SendKeys command, but I guess it simply send some WM_KEYDOWN/WM_KEYUP messages.  In c, you can call SendMessage(), which can not only send key messages but also a lot of others.

You can also use OLE, DDE, socket etc to communicate with other processes.
0
 

Author Comment

by:quiller
ID: 1175592
I should be a little more specific.  Say, I want to communicate
with an App. that has no OLE,DDE, or any other support that
I know of.  Under Unix, I used "expect".  Under VBA, there is
the "SendKeys" command.  I want to be able to send keys to
another app.  I'm basically trying to set up a batch procedure
which at one step involves calling an App. that has no msg.
support.  So, for example, I can do the following in VBA:

Sub Send_Msg()
 Dim i, Msg, x                             ' Declare variables.
 x = Shell("C:\WINNT\system32\calc.exe", 1)  ' open Calculator.
 For i = 1 To 10                        ' Set up counting loop.
  SendKeys i, True         ' Send keystrokes to the calculator.
  SendKeys "{+}", True
 Next i                               ' to add each value of I.
 AppActivate "Microsoft Access"          ' Return focus to VBA.
 Msg = "Choose OK to close Calculator."  ' Stop to see results.
 MsgBox Msg
 AppActivate "calculator"         ' Return focus to Calculator.
 SendKeys "%{F4}", True      ' Send Alt+F4 to close Calculator.
 AppActivate "Microsoft Access" ' Return focus to VBA
End Sub

So, how can I do the equivalent from Visual C++?

0
 

Expert Comment

by:od0
ID: 1175593
Use the system() command to execute programs from within vc++. Like this: system("executable.exe")
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:quiller
ID: 1175594
The system command I am aware of.  But how do I target a
specific window, as in the above example (I can target the
window by its name, "calculator"), and how do I send key strokes
to it.


0
 
LVL 7

Accepted Solution

by:
faster earned 150 total points
ID: 1175595
First, use FindWindow() to get the window handle of calc.  Then use SendMessage() to send key strokes.

hwnd=FindWindow(NULL, "Calculator");
SendMessage(hwnd, WM_CHAR, wparam, lparam);

Refer to SDK help for wparam and lparam.
0
 

Author Comment

by:quiller
ID: 1175596
Thanks.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question