Solved

GetActiveWindow

Posted on 2001-07-11
5
446 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 101
Delphi: ForceDirectory plain function 7 29
Convert MS Word document to a PDF file 9 78
Delphi: making a BW image transparent 10 35
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now