Solved

Reading Windows States

Posted on 1998-07-29
9
137 Views
Last Modified: 2010-04-04
Hey all,

I'm currently writing a delphi program (it's a toolbar of sorts) that needs to be visible if internet explorer (ie3/4) is running and visible, and not visible when ie3/4 is either not running or more importantly, not visible.... i.e. it's practically part of the ie3/4 window for all intents and purposes. If someone could give me a few pointers on how to find out whether a window is minimised or not, and if it's an ie3/4 window, that would be much appreciated.

Also, is it possible find what colour is at a particular point on a window in delphi 2?

Much thanks,
Matt
0
Comment
Question by:mattg072998
  • 3
  • 3
  • 3
9 Comments
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358982
function GetWindowPlacement(Wnd: HWnd; Placement: PWindowPlacement): Bool;

TWindowPlacement = record
  length: Word;
  flags: Word;
  showCmd: Word;
  ptMinPosition: TPoint;
  ptMaxPosition: TPoint;
  rcNormalPosition: TRect;
end;

c help 4 API.

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358983
mattg!

sorry, i didn't mean 2 answer, i just wanted 2 comment.
please reject, even if accepted.

Black Death.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1358984
I just figured out an answer to your question ... here it is...
Put this procedure in OnTimer()
{**********************************************}
procedure TForm1.Timer1Timer(Sender: TObject);
var hNotepad: HWND;
begin
  hNotepad := FindWindow('Notepad',nil);
  if IsWindowVisible(hWin) = true then
    ShowWindow(handle,SW_SHOW) else
      ShowWindow(handle,SW_HIDE);
end;
{**********************************************}
Since I've deleted InternetExplorer I tried it with Notepad and it works....

Regards,
Viktor Ivanov

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1358985
OOOpppppssss....A little mistake..This would be like this....
     {**********************************************}
     procedure TForm1.Timer1Timer(Sender: TObject);
     var hNotepad: HWND;
     begin
       hNotepad := FindWindow('Notepad',nil);
       if IsWindowVisible(hNotepad) = true then {  <<<- After I tried the if this works I've changed            the code so you know what's going on...but I forgot to change all names...well here it is...}
         ShowWindow(handle,SW_SHOW) else
           ShowWindow(handle,SW_HIDE);
     end;
     {**********************************************}
0
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.

 

Author Comment

by:mattg072998
ID: 1358986
Thanks viktornet and blackdeath for solutions and comments.

I'll reopen the question so viktornet can get the points, which is what i assume you were asking for, blackdeath.

Anyone have any quick tips for the second small question?
0
 
LVL 10

Accepted Solution

by:
viktornet earned 150 total points
ID: 1358987
Ok, then....the answer is up there....Ok let me put it again..

procedure TForm1.Timer1Timer(Sender: TObject);
          var hNotepad: HWND;
          begin
            hNotepad := FindWindow('Notepad',nil);
            if IsWindowVisible(hNotepad) = true then
              ShowWindow(handle,SW_SHOW) else
                ShowWindow(handle,SW_HIDE);
          end;
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358988
hi, mattg.

which 1 do u put in2 action?
i'm just asking cos i'd like 2 know if mine is handy in case i should need something like that, 2. otherwise i'd use vik's.

Black Death.
0
 

Author Comment

by:mattg072998
ID: 1358989
I'm using an adapted version of viktor's, because I wasn't sure how to properly implement your suggestions.

I've adapted viktor's because IsWindowVisible was not quite what i wanted. Instead, i'm using:

hWindow := WindowFromPoint(point);

to determine which window is on top at a particular point. Unfortunately, i'm finding that different points on the same application return different hWnd values. I'm not sure why, although i have a suspicion that it is something to do with child windows or similar. But then again i may be totally wrong, because i'm not exactly familiar with the winapi :)

I was thinking another solution may be to change the Z order of windows, so that the toolbar always stays on top of any Internet Explorer windows.
0
 

Author Comment

by:mattg072998
ID: 1358990
here is the code i've decided on using for anyone still interested. It is adapted from viktor's idea, thanks for the pointers everyone. Try it on notepad, it works well, even with multiple instances. All I have to do is convert it to internet explorer for it to fulfil its original purpose.

procedure TformMain.Timer1Timer(Sender: TObject);
var
   hNotepad: HWND;
   hWindow: HWND;

begin
   hWindow := GetForegroundWindow();
   hNotepad := FindWindow('Notepad',nil);

   if ((hWindow = hNotepad) AND (NOT(IsIconic(hNotepad)))) then
       ShowWindow(handle, SW_SHOWNOACTIVATE);
   else
       ShowWindow(handle,SW_HIDE);
end;


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

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

929 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

19 Experts available now in Live!

Get 1:1 Help Now