[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

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.
0
nyt
Asked:
nyt
  • 3
1 Solution
 
kretzschmarCommented:
getactivewindow i guess is limited to your own process windows,
try to use getforegroundwindow (or similar)
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello
change ur code to use  GetForegroundWindow API

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

Mohammed
0
 
Mohammed NasmanSoftware DeveloperCommented:
Ohh
  meikl you are faster :)

0
 
nytAuthor Commented:
why doesn't EE allow two people to share the points...
0
 
Mohammed NasmanSoftware DeveloperCommented:
nyt,

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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now