Link to home
Start Free TrialLog in
Avatar of nyt
nyt

asked on

GetActiveWindow

Hi,
I tried to use GetActiveWindow to get the handle of the active window, but failed.  Can anyone tell me what's wrong with my code?

var
   h:hwnd;
begin
     h:=GetActiveWindow;
     PostMessage(h,WM_CLOSE,0,0);
end;

The above code can only close the program itself, but if the active window is, say, Notepad, it failed to do what I want.

Can anyone help me?
Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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
Hello
change ur code to use  GetForegroundWindow API

  var
  h:hwnd;
begin
    h:=GetForegroundWindow;
    PostMessage(h,WM_CLOSE,0,0);
end;

Mohammed
Ohh
  meikl you are faster :)

Avatar of nyt
nyt

ASKER

why doesn't EE allow two people to share the points...
nyt,

  Meikl gave you the first correct answer, and he's deserve the points