?
Solved

communicating with other apps. in VC++

Posted on 1997-12-09
6
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 450 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

801 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