We help IT Professionals succeed at work.

How do I get the text window handle in another application while the mouse clicking this text window item.

YangXG
YangXG asked
on
Now, I want to build one application to get the handle of any item window of one another application after my mouse clidked the this item. this item may be text item, or static text time, or something else. I know one windows API can do it. But I forget the name of this function. Also do I have another ways to get this handle not via the mouse clicking.
Comment
Watch Question

CERTIFIED EXPERT
Author of the Year 2009
Commented:
First, you can use FindWindow to opbtain the handle of top-level windows.

Alas, you are going to run into some problems in reading the Window Text for windows that are not created by your program.  There is an ugly workaround for win95 and a less-ugly-but-far-from-pretty workaround for Win98, and WinNT/2K.

>>Also do I have another ways to get this handle not via the mouse clicking.

Of course for mouse-clicking, you can use WindowFromPoint() but you can obviously use that same fn without having the mosue click -- as long as you know the screen location of the window.  But you can get a handle to each top-level window (such as an application program's MainFrame) via EnumWindows() and given a top-level window, you can use EnumChildWindows() to get a look at each child and grandchild window of that window.

What exactly are you trying to accomplish?  Spell it out -- in detail -- and I'll take a crack at writing up some code for you.

-- Dan
CERTIFIED EXPERT
Author of the Year 2009

Commented:
See
http://www.microsoft.com/MSJ/0997/win320997.htm
for some info on the difficulties in obtaining string data from a window owned by another process.

-- Dan

Author

Commented:
thanks for your comment, it is great! but if I want to get the input control from a web page? They input item may be wroten by CGI or Java Scripts. So what should I do?

thanks a lot!

Commented:
Use WindowFromPoint function. It is a API fuction that returns a HWND but has an equivalent in MFC witch returns an CWnd*.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
Just a note:  I think I know what you want to do and... All you're going to get is asterisks.

-- Dan
ekc

Commented:
If you want to do this by mouse click, the SetWindowsHookEx() API could be interesting. This way you can intercept many OS...

Author

Commented:
Dan: No, I don't want to get the asterisks in one web page, I just want to input date from my application to the one web page edit item. I used the SPY++ to track the handle of this edit item, but this item has no handle at all. Another control, just like list cortrol in web page, has the handle.

EKC: yes, if I want to get the point from mouse clicking. I have to set mouse hook.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
>>I just want to input date from my application to the one web page edit item.

If this is the case, I may have an out-of-the-box-thinking solution for you.

It sounds like you want to fill an input box on a web page FORM and then submit that input to a site.  You want to automate this procedure so that you can do it many times rapidly or so that you can feed diverse data into the form without needing manually type it.

If that is the case, then all you need to do is simulate what normally happens when you click the [Submit] button.  It usually boils down to "navigating to" a page with a URL like:

http://xxx.com/cgi/dosomething.asp?name=jones&age=17

I have done this many times and it is actually pretty easy, but it is more than 100 pts worth of effort because the details vary widely -- depending upon the web page.

An alternative is to place the desired data into the clipboard (you can do this programmatically, say from a database) then simply select the input box on the web page (using mouse or a series of TAB keys) and then press Ctrl+V to paste the data into the input form.  Tab to the submit button and press Enter.  It is easy to automate sending keystrokes to a webpage for this type of operation.

-- Dan

Author

Commented:
Ok, I see there are two ways to parse the string into web server, get and post. But one home page is one frame and composed by another pages, also I can't see the source code of every page, since I can't open the every page seperately.

I think you second way is not so good, but the first way is still unclear to me. So how many pts do you want to get about your first way.

Also I have another way to get the IE application handle via shellWindowInterface. do you think it can do it?

CERTIFIED EXPERT
Author of the Year 2009

Commented:
>>Also I have another way to get the IE application handle
>> via shellWindowInterface. do you think it can do it?

Your best bet may be to host a webbrowser control and then spelunk through the DOM to locate the desired page element.  Then programatically submit the result.

>>But one home page is one frame and composed by another pages,...

This does complicate it somewhat.  I have answered a question about asccessing the separate pages of a frameset.  See

http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20180039

Bu I have found that you can often just subimt the one frame (it is typically a standalone page).

Alternative idea:
Just hijack the page(s) by using View SOurce and copying to a local hard disk.  Make your own changes to the scripts to fill-in the desired inputs.  Some hosts will reject your submit attempt, becasue they know the "referrer is not themselves... but other hosts don't check or don't care.

-- Dan




Author

Commented:
Your comment is very good, I should close this question in last week, but it is really nice talk with you and your comment is valueable. Thanks a lot.

Also I meet another problem, for the first page is one frame, I can't open the one of the page seperately, I can't see the souce code. I will try another way to access it.

Thanks again for your wonderful comments.

Author

Commented:
thanks for your excellent comment! I hope we have another change to talk about C++ programming. Thanks a lot.

Jacky

Explore More ContentExplore courses, solutions, and other research materials related to this topic.