Solved

GetActiveWindow

Posted on 2001-07-11
5
451 Views
Last Modified: 2010-04-06
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
Comment
Question by:nyt
  • 3
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 40 total points
ID: 6272661
getactivewindow i guess is limited to your own process windows,
try to use getforegroundwindow (or similar)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6272686
Hello
change ur code to use  GetForegroundWindow API

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

Mohammed
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6272699
Ohh
  meikl you are faster :)

0
 

Author Comment

by:nyt
ID: 6272735
why doesn't EE allow two people to share the points...
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6272742
nyt,

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

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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