Solved

Program manipulation from a dialog

Posted on 1999-01-27
13
175 Views
Last Modified: 2010-04-02
I am curious to know how to set edit box text to a string in another program's window. For example, the program I am working with only has one edit box. How would I go about putting text in that from another program? Please help.

Thanks
D
0
Comment
Question by:SuperMario
  • 6
  • 6
13 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1185343
Once you get the text from the other program's window you use SetWindowText() to change it.

The question is how to get the text from the other program.  That depends on where that text is.  If the text is in an edit box in another program, then get the edit-box;'s window handle and use the GetWindowText() procedure to get the window text.  If it is elsewhere, let me know.  

Let me know if you have any questions.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185344
Hmm - i'd have sent a WM_SETTEXT to the edit window...
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185345
I prefer using functions to messages where possible.  Provides type safety etc.
0
Independent Software Vendors: 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!

 
LVL 3

Author Comment

by:SuperMario
ID: 1185346
I know to use SetWindowText(), but the problem is I don't know how to get the other program's edit box ID. If I knew how to do that, I would be on my way. That's why I said there is only one edit box... because maybe that would make it easier?

D
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185347
What do you have to work with?  What do you know about this window?  Like do you have its parent window's handle?  its process ID?  do you have the parent window's title? etc?
0
 
LVL 3

Author Comment

by:SuperMario
ID: 1185348
Yes. The parent window is composed of no more than a CView window and an edit box. The parent window's title is The Palace. (The objective of this program is to give users a script library usable on some Palace servers).

D
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185349
Get the handle to the parent window using EnumWindows() or FindWindow()  (To use FindWindow, you need the window class name, you can obtain that with Spy++).  Then use EnumChildWindows() to go through all the child windows until you find one with the right class.  (Use GetClassName().)
0
 
LVL 3

Author Comment

by:SuperMario
ID: 1185350
Okay... Now I have this:
Handle: 00000D0C
I had the process ID but I just closed it on accident..

If this helps any..
More points go to you later on when I gain them.
D
0
 
LVL 3

Author Comment

by:SuperMario
ID: 1185351
I also got the class... Palace. Now I have the process ID, the handle, the class and just about everything.

What now?
0
 
LVL 3

Author Comment

by:SuperMario
ID: 1185352
Hey, my brain is slowly growing!

I used Spy++ to find the window stuff. I then added this into my code:

{
   CString input;
   GetDlgItem(IDC_EDIT1)->GetWindowText(input);
   FindWindow("Palace","The Palace")->SetWindowText(input);
   // I need to add a wildcard to "The Palace" somehow, because
   // it changes when you switch servers.
}

As I expected, it changed the caption of the Palace window to whatever the user typed in the edit box in my program.

Now I want to be able to change the caption of the Palace edit box to whatever the user typed in MY edit box.

That's the whole point behind this.
Thanks!
D

0
 
LVL 22

Expert Comment

by:nietod
ID: 1185353
obtaining the process ID or handle at a particular time (like by using spy) is of no value--they change each time the program is run.  You must have code that can obtain them at any time.

Wildcards are not avaialble to FindWindow().  You must know the title exactly.  It sounds like you don't, so use EnumWindows() instead.  In this case you can check each window enumerated to make sure the title is "reasonable?" and that the window has the right class.  From there, you can start searching the child windows.
0
 
LVL 3

Author Comment

by:SuperMario
ID: 1185354
Okay...

but how do I set that window's edit box text?
Is it like,
EnumWindows("Palace")->GetDlgItem(IDC_EDITBOX)->SetWindowText("blah");
?
D
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185355
I see, I missunderstood. I read

"how to set edit box text to a string in another program's window."
as how to set your edit box to [a string in another program's window].

Yes, that code will work if you now the ID to pass to GetDlgItem.  Otherwise, you need to enumerate the child windows and look for the edit box.  use EnumChildWindows() for that.  (I assume by -> you mean program logic, not the C++ operator, right?)

However, it is somewhat rude, if not risky to alter information in another program.  You will probably be okay in this case, but there is no rule that says that a program has to run propperly when you start tinkering with its windows.

Al less risky possiblity might be to send a past command to the program.  (if paste works in this case.)  This is less "hack" like.  but only works if the program responds to paste and if the edit box is empty or if the text there is selected.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

749 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