Solved

Program manipulation from a dialog

Posted on 1999-01-27
13
168 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
Comment Utility
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
Comment Utility
Hmm - i'd have sent a WM_SETTEXT to the edit window...
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
I prefer using functions to messages where possible.  Provides type safety etc.
0
 
LVL 3

Author Comment

by:SuperMario
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

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