Solved

function that retrieves the state(maximise,minimise,restore) of an open window depending on its class

Posted on 2006-06-29
5
211 Views
Last Modified: 2010-04-05
hi there

i need a function in delphi where i can pass as a parameter the name of a class e.g

"Notepad", and get a result back as a string or integer that tells me whether this window that belongs to this class

is mininimised,maximised or restored

for example

i open the art.txt notepad file and i minimise it

i want the fuction to return me the following:

minimise=0
restore=1
maximise=2


urgent help needed

thanks



function Get_windowminimised(const thestring: WideString): long;
var
  foldercaption:cardinal;
  foldercaptiontext,foldercaptiontext1:array[0..255] of char;

begin
     
     
      foldercaption := FindWindow('myClass', nil);
     
      GetWindowText (foldercaption, foldercaptiontext, 256);
        isminimised     (blah)
Result := ismin or is max or is restored
     
End;
0
Comment
Question by:nikolaosk
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Hamidreza Vakilian
ID: 17014755
Hi!

You can use GetWindowPlacement Win32 API function:
I wrote a function that returns the status by a string using GetWindowPlacement =>


function GetWindowState(Wnd:HWnd):string;
var WPlacement : PWINDOWPLACEMENT;
begin
  GetMem(WPlacement,SizeOf(TWINDOWPLACEMENT));
  WPlacement^.Length:=SizeOf(TWINDOWPLACEMENT);
  if GetWindowPlacement(Wnd,WPlacement) then
    begin
    case WPlacement^.showCmd of
    SW_SHOWMAXIMIZED:  Result := 'Maximized';
    SW_SHOWMINIMIZED:  Result := 'Minimized';
    SW_SHOWNORMAL:     Result := 'Normal';{or restored}
    end
    end
  else
    Result:='ERR';
  FreeMem(WPlacement);
end;


Programmer-x
0
 
LVL 14

Accepted Solution

by:
Hamidreza Vakilian earned 250 total points
ID: 17014773
Integer Result =>

{Maximized=2,Minimized=0,Normal or Restored=1}

function GetWindowState(Wnd:HWnd):Integer;
var WPlacement : PWINDOWPLACEMENT;
begin
  GetMem(WPlacement,SizeOf(TWINDOWPLACEMENT));
  WPlacement^.Length:=SizeOf(TWINDOWPLACEMENT);
  if GetWindowPlacement(Wnd,WPlacement) then
    begin
    case WPlacement^.showCmd of
    SW_SHOWMAXIMIZED:  Result := 2;
    SW_SHOWMINIMIZED:  Result := 0;
    SW_SHOWNORMAL:     Result := 1;
    end
    end
  else
    Result:=-1;
  FreeMem(WPlacement);
end;

Programmer-x
0
 

Author Comment

by:nikolaosk
ID: 17016096
hi,

your code works....

but in this function of yours

function GetWindowState(Wnd:HWnd):Integer;

i need to pass the classname of the window that i want to see if it is minimised or not, as a parameter.can you change the function a bit?

 
0
 
LVL 14

Expert Comment

by:Hamidreza Vakilian
ID: 17016730
... Can you explain more?
0
 

Author Comment

by:nikolaosk
ID: 17017823
hi i will try to explain as soon possible.

using the code below i can pass in the following function


GetStateOfWindow(param1,param2)

param1="CabinetWclass"
param2="My Computer"


and get the state of the window.
what i need is a similar function that i will be able to pass the same arguments and force(and not check) the window state. for example i open "my computer" window and SET the STATEof the window to restore or minimised.

some minor alterations to the code below i think

thanks



*******************************************

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function GetStateOfWindow(const thestr,thestr2: WideString): Integer;
var
  h2,h1:string;
  wnd:thandle;
  WPlacement:PWINDOWPLACEMENT;
  begin

  try
    h2:=string(thestr);
    h1:=string(thestr2);
    wnd := FindWindow(pansichar(h1),pansichar(h2));
    GetMem(WPlacement,SizeOf(TWINDOWPLACEMENT));
    WPlacement^.Length:=SizeOf(TWINDOWPLACEMENT);
    if GetWindowPlacement(Wnd,WPlacement) then
      begin
      case WPlacement^.showCmd of
        SW_SHOWMAXIMIZED:  Result := 2;
        SW_SHOWMINIMIZED:  Result := 0;
        SW_SHOWNORMAL:     Result := 1;
        end
        end
        else
        result:=-2;

  finally
    FreeMem(WPlacement);
  end;
  //end;
  end;



procedure TForm1.Button1Click(Sender: TObject);
var
a:integer;
x1,x2:string;
begin
x1:='My Computer';
x2:='CabinetWClass';

      a:=GetStateOfWindow(x1,x2);
         showmessage(inttostr(a));
      end;

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
SUM 2 INTEGER ARRAYS INTO 1 10 93
how to update exe applicatio from internet ? 6 68
tvirtualstringtree freeze when load too manny images 10 53
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 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

23 Experts available now in Live!

Get 1:1 Help Now