Board index » delphi » Window Handle of Active Window

Window Handle of Active Window

I need the capture the window handle of the active window in order to send
it keystrokes using:

SendMessage(Handle, WM_CHAR, Word('y'), 0);

Any ideas?

MTIA

Tim

 

Re:Window Handle of Active Window


Use GetActiveWindow:

MyHandle := GetActiveWindow;
SendMessage(MyHandle, WM_CHAR, Word('y'), 0);

Quote
Timothy Creswick wrote:

> I need the capture the window handle of the active window in order to send
> it keystrokes using:

> SendMessage(Handle, WM_CHAR, Word('y'), 0);

> Any ideas?

> MTIA

> Tim

--

1 + 1 = 2  but  '1' + '1' = '11'

Re:Window Handle of Active Window


Quote
> Use GetActiveWindow:

> MyHandle := GetActiveWindow;
> SendMessage(MyHandle, WM_CHAR, Word('y'), 0);

thanks for the quick response, but this isn't working for me!

could it be that I am using windows XP?

If i have my application run this procedure with another window active
nothing happens...

Tim

Re:Window Handle of Active Window


Quote
> If i have my application run this procedure with another window active
> nothing happens...

Just worked out why: this is only sending the keystroke to the window, not
the active control in that window (eg the text area in notepad).

Anyone know how I can capture handle containing the cursor?

Tim

Re:Window Handle of Active Window


Get SndKeys32.pas; it has the routines you want.

The file is on the Delphi installer or companion CD and can be found all
over the net.

Quote
"Timothy Creswick" <timothy.cresw...@NOSPAM{*word*269}.net> wrote in message

news:3d5e9708$0$233$cc9e4d1f@news.dial.pipex.com...
Quote
> > If i have my application run this procedure with another window active
> > nothing happens...

> Just worked out why: this is only sending the keystroke to the window, not
> the active control in that window (eg the text area in notepad).

> Anyone know how I can capture handle containing the cursor?

> Tim

Re:Window Handle of Active Window


Quote
> Get SndKeys32.pas; it has the routines you want.

Actually sndkey32.pas - thanks for this tip - works a treat!

Tim

Other Threads