Solved

GetActiveWindow

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 139
Run video youtube webbrowse 10 57
how to send memory stream from ics Client To ics server ? 11 80
Graphics32 under Delphi 10.1 Berlin 2 36
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

20 Experts available now in Live!

Get 1:1 Help Now