Solved

GetActiveWindow

Posted on 2001-07-11
5
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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