?
Solved

Delphi TSendKeys FindWindowEx

Posted on 2007-10-04
4
Medium Priority
?
4,970 Views
Last Modified: 2010-05-18
I am using a TSendKeys object to send create a virtual user to do data entry.  For most windows this works fine - we set the handle to the main window and then run our functions.  

However, I have a case where I need to touch a child window in another application.  I can get the handle and set the focus on the main window - but it has a separate meaning for Alt-V than the child window within the app.  I tried using FindWindowEx but I don't think I am passing the right parameters.  

Here is my code so far - but it keeps returning chandle = o

      handle := SendKeysMacro.HandleFromTitle(FindWindowTitle(FMacro.ValueFromIndex[nLine -1]));
      chandle := FindWindowEx(handle, 0, PChar('WINDOW'), nil);//PChar(FMacro.ValueFromIndex[nLine]));
      SendKeysMacro.MakeWindowActive(chandle);

I think the third parameter is my issue - but I don't know - I'm not sure what lpszClass this is supposed to be and I can't seem to find a listing of options for this field either.  Most of the other questions I have seen related to this want to press a button in another app or something, not set the focus on a child window.

Any help is appreciated!

Thanks,
C
0
Comment
Question by:Chipmunk77
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 20018088
if you know the relative location of te child window, you could try using
childhandle := Childwindowfrompoint(mainhandle,point(50,50));
0
 
LVL 16

Assisted Solution

by:CodedK
CodedK earned 500 total points
ID: 20020280
Or use the application and see what keys need to be pressed to set the focus to the child window.
For example if tab key sends the focus to the desired child window then send a tab key to the main window !
This will enable the child window.
Sending mouse keys could be risky if the form remembers the last position.

To send keys to another application do this..

Example :
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
procedure TForm1.Button1Click(Sender: TObject);
var
hnp:HWND;
begin
 hnp:= FindWindow('notepad',nil);
 if hnp>0 then begin
  hnp:=FindWindowEx(hnp,0,'Edit',nil);
  SendMessage(hnp, WM_CHAR, Ord('H'),0); // Send 'H' letter.
  SendMessage(hnp, WM_CHAR, Ord('i'),0); // Send 'i' letter.
  SendMessage(hnp, WM_CHAR, Ord('!'),0); // Send '!' letter.
  PostMessage(hnp, WM_KEYDOWN, VK_RETURN,0); // Send ENTER key.
 end;
end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Or since the desired window is focused (in our case the main window not the child)
You can send keys with keybd_Event
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
keybd_Event(ord('X'), 0, 0, 0);  {X key down}
keybd_Event(ord('X'), 0, KEYEVENTF_KEYUP, 0);   {X  key up}
keybd_event(VK_F7,0,0,0);
keybd_event(VK_F7,0,KEYEVENTF_KEYUP,0);
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
To see a list of all the virtual keys codes (use with keybd_event), take a look at this :
http://delphi.about.com/od/objectpascalide/l/blvkc.htm

Hope this helps :)
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21216635
Forced accept.

Computer101
EE Admin
0

Featured Post

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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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