Solved

Reading Windows States

Posted on 1998-07-29
9
134 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now