Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Minimize/restore any window from my app

Posted on 2004-09-16
3
Medium Priority
?
1,642 Views
Last Modified: 2008-01-09
Hello!
I want to make a single button which would minimize/restore some window (it's not in my application) (first click - minimizing, second click - restoring etc).
I found 2 ways how to do it if I maximize window, but I can't find how to do it with minimizing...
How can I:
1) minimize a window properly like MS Windows does it?
2) check if window is minimized?
3) restore the window to its normal position and size if it is minimized?

Thanks..
0
Comment
Question by:ZhaawZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
MrJul earned 195 total points
ID: 12078443
This little function should do the trick :


// Takes window handle as a parameter
procedure MinRestoreWindow(hWnd: Cardinal);
var
    WP: WINDOWPLACEMENT;
begin

    // Check if window is minimized
    WP.length := SizeOf(WP);
    GetWindowPlacement(hWnd, @WP);
    if (WP.showCmd = SW_SHOWMINIMIZED) or (WP.showCmd = SW_SHOWMINNOACTIVE) then
        WP.showCmd := SW_RESTORE // Yes, then restore it
    else
        WP.showCmd := SW_MINIMIZE; // No, then minimize it
    WP.flags := 0;

    // Go
    SetWindowPlacement(hWnd, @WP);

end;
0
 
LVL 7

Assisted Solution

by:LRHGuy
LRHGuy earned 180 total points
ID: 12078575
Here's how I did it...replace "NameOfWindow" with the window of interest...

procedure TForm2.Button3Click(Sender: TObject);
var
  H:HWnd;
  Placement: TWindowPlacement;
begin
  H:=FindWindow(0,'NameOfWindow');
  if H<>0 then begin
    Placement.length := SizeOf(TWindowPlacement);
    GetWindowPlacement(H, @Placement);
    case Placement.showCmd of
      SW_SHOWMINIMIZED: Placement.ShowCmd:=SW_ShowNormal;
      SW_SHOWMAXIMIZED: Placement.ShowCmd:=SW_ShowMinimized;
      else  Placement.ShowCmd:=SW_ShowMaximized;
    end;
    SetWindowPlacement(H,@Placement);
  end;
end;

GetWindowPlacement will tell you the current state of the window.
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 12078748
Thanks!
Booth examples work almost fine. There was only one problem in booth of them - when restoring window it doesn't stay maximized if it was maximized before minimizing. I solved it by replacing SetWindowPlacement to sending WM_SYSCOMMAND message.

var
  wnd : hwnd;
  info : WINDOWPLACEMENT;
begin
wnd := FindWindow('mirc', nil);
info.length := SizeOf(TWindowPlacement);
GetWindowPlacement(wnd, @info);
if (info.showCmd = SW_SHOWMINIMIZED) or (info.showCmd = SW_SHOWMINNOACTIVE) then begin
  SendMessage(wnd, WM_SYSCOMMAND, SC_RESTORE, 0)
end else begin
  SendMessage(wnd, WM_SYSCOMMAND, SC_MINIMIZE, 0)
end;
end;
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

610 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