Solved

Program manipulation from a dialog

Posted on 1999-01-27
13
170 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

776 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