Solved

Program manipulation from a dialog

Posted on 1999-01-27
13
176 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
[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
  • 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
Industry Leaders: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ getting the first 10 characters of a char* string 11 111
Printing the elements of a set declared inside a map in C++. 3 69
Finding Divisors 5 61
visual C++ 1 43
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 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.
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.

752 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