Solved

communicating with other apps. in VC++

Posted on 1997-12-09
6
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
Use the system() command to execute programs from within vc++. Like this: system("executable.exe")
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:quiller
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now