• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

maximise or minimise other aplication

how i can create programm who maximise and minimise otther programm's window ???
0
andrezzzz
Asked:
andrezzzz
3 Solutions
 
mikelittlewoodCommented:
2 buttons on a form, 1 to maximise, 1 to minimise.
This example uses notepad, but you can change the application name to anything you want.

procedure TForm1.Button1Click(Sender: TObject);
var
  myapp: Thandle;
begin
  MyApp := FindWindow(nil,'Untitled - Notepad');
  ShowWindow(MyApp,SW_MAXIMIZE);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  myapp: Thandle;
begin
  MyApp := FindWindow(nil,'Untitled - Notepad');
  ShowWindow(MyApp,SW_MINIMIZE);
end;
0
 
andrezzzzAuthor Commented:
but if i want minimaize or maximise all aplication.

for example i have in form timer and after every 5 seconds i want maximize one aplication ?
0
 
ZhaawZSoftware DeveloperCommented:
You can't minimize/maximize application, you can minimize/maximize only a window.

Here's another way to minimize/maximize/restore a window:
SendMessage(handle, wm_syscommand, sc_minimize, 0);
(write sc_maximize instead of sc_minimize to maximize window, sc_restore - to restore it)
0
 
OctabunCommented:
The Shell.Application ActiveX object has the minimizeAll() method. Maybe it is what you need.
0
 
mikelittlewoodCommented:
You could get all the windows currently on screen from the code below.
Then using the handle provided for each window, maximise or minimise using the code I gave near the beginning.

Drop a button and a memo onto a form and use this code

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    btnEnumWindows: TButton;
    procedure btnEnumWindowsClick(Sender: TObject);
  private

  public

  end;

    function EnumWindowsProc(hwnd: HWND;
      lParam: LPARAM): Boolean; stdcall;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function EnumWindowsProc(
   hwnd: HWND;          // handle to parent window
   lParam: LPARAM       // application-defined value
  ): Boolean; stdcall;
var
 p: pchar;
 winname: array[0..144] of char;
begin
  // reserve a string space
  GetMem(p, 300);
  if iswindowvisible(hwnd) then
  begin
    // convert the hwnd into a classname
    GetClassName(hwnd, p, 300);
    // add the information to the list box
    Form1.Memo1.Lines.Add(IntToStr(hwnd)+' '+p);
  end;
  // free the string space
  FreeMem(p);
  // return true to signal windows should continue
  Result := True;
end;

procedure TForm1.btnEnumWindowsClick(Sender: TObject);
begin
// call EnumWindows passing our callback function as a parameter
  EnumWindows(@EnumWindowsProc, 0);
end;

end.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now