Link to home
Start Free TrialLog in
Avatar of wengwah
wengwah

asked on

Controlling other opened windows.

How do I set focus on  another opened window, e.g. notepad and start sending tabs and keystrokes ? I'm trying to get around the Delphi/400 client installation when keying the QSECOFR's password. I have a few hundred installations ...
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Matvey
Matvey

You have  Windows.SetFocus( HWND ), and you can find the handle of a window, by it's title for example, using FindWindow and GetWindow (look in win32.hlp).

Sending keystrokes is either sending WM_KEYDOWN, WM_CHAR messages using SendMessage, or you have the Keybd_event function, which is the best thing to use here (set the focus first).

BWT what's QSECOFR, or whatever you mean?
Zif! You did it again! ;-)
You have  Windows.SetFocus( HWND ), and you can find the handle of a window, by it's title for example, using FindWindow and GetWindow (look in win32.hlp).

Sending keystrokes is either sending WM_KEYDOWN, WM_CHAR messages using SendMessage, or you have the Keybd_event function, which is the best thing to use here (set the focus first).

BWT what's QSECOFR, or whatever you mean?
Have a look in the Extras\SendKeys directory on the Delphi CD. SendKeys.pas has an AppActivate routine where you supply a window name.
Also, there is SendKeys which takes a string, and a boolean wait value.
Might be just what you're looking for.

Cheers,
Phil.
I would prefer just sending WM_CHAR/WM_KEYDOWN/WM_KEYUP messages to the window without activating or focussing the it, because win98 sometimes makes problems with activating windows. Sometimes the program that you activated is in reality NOT activated, but only blinking in the taskbar.

Regards, Madshi.
Avatar of wengwah

ASKER

Forgot to mention that I'm really  new to Delphi 3/Win32 API programming.   I would appreciate some kind of roadmap on this.

Much appeciated the help and Merry Christmas!
API is something that we aren't suppose to like much, but we have to learn to live with it.
API is based on handles and messages, which are simple constant numbers. Every object has it's handle (index), and you can access it with this handle, using API functions. These functions are simple DLL extracts, that are commonally used by all windows programming tools.
The best thing to do is register (free) in the MSDN, or use the SDK, which is mostly just Win32.HLP. You can find almost all documentation in there, though on MS site it's more organized and updated. (http://premium.microsoft.com/msdn/library/).

--Matvey
Marry Christmass!
In Windows 98, if your program that you activated is in reality NOT activated, but only blinking in  the taskbar try :

SetWindowPos(Handle, HWND_TOPMOST,
                         0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
SetWindowPos(Handle, HWND_NOTOPMOST,
                         0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);

it works for me.