Har ikke lige afprøvet det, men det ligner da noget der må kunne bruges ;)
Question/Problem/Abstract:
Have you ever wanted, that your form gets an event when it was minimized? Answer:
Try this extension to the normal form. You can assign a handler to the OnMnimize property and choose from three "automatic" actions built in in the form:
tmNone = Dont minimize the Window tmWindow = minimize the Window as usual tmAll = Minimze all windows of the application
Installation: Put the Unit in the library folder of your delphi compiler and import it to your form sourcecode.
Usage: Replace the
type TMyForm = class (TForm)
of your form with
type TMyForm = class (TMiniForm)
Thats all. Assign the OnMinimze property at runtime. Example:
procedure TMyForm.MyMinimize (Sender: TObject; var state: TMiniState); begin state:= tmAll; // minimize all windows end;
procedure TMyForm.FormCreate; begin OnMinimize:= MyMinimize; end;
//--------------------------------------------------------- unit MiniForm;
// state flags for automatic handling of minimize events type TMiniState = (tmNone, // dont react to the message tmWindow, // minimize the window tmAll); // minimze all windows of the app
// the minimize event himself type TMinimizeEvent = procedure (Sender: TObject; var state: TMiniState) of object;
type TMiniForm = class (TForm) // derived from TForm private FOnMinimize: TMinimizeEvent; FOnRestore: TNotifyEvent; procedure WMSIZE(Var Msg: TWMSIZE); Message WM_SIZE; procedure WinRestore (Sender: TObject); public constructor Create (AOwner: TComponent); override; destructor Destroy; override; published property OnMinimize: TMinimizeEvent read FOnMinimize write FOnminimize; end;
implementation
destructor TMiniForm.Destroy; begin inherited end;
constructor TMiniForm.Create (AOwner: TComponent); begin FOnMinimize:= NIL; inherited; end;
procedure TMiniForm.WMSIZE (VAR msg: TWMSIZE); // catch the WM_SIZE message to know what happend var status: TMiniState; begin if msg.SizeType = integer (wsMinimized) THEN BEGIN IF Assigned (FOnMinimize) then begin status:= tmWindow; // Default action FOnMinimize (self, status); case status OF tmNone: // Tell windows to restore the window immedately PostMessage(Handle, WM_SYSCOMMAND, SC_RESTORE, 0); tmWindow: ; // All is done by windows and Delphi tmAll: // Minimize all windows of the app begin // Store the OnRestore event FOnRestore:= Application.OnRestore; // Replace it with own handler Application.OnRestore:= WinRestore; // Minimize all Application.Minimize; end; end; end; end; inherited; // Call other hanlder of WMSIZE event end;
procedure TMiniForm.WinRestore (Sender: TObject); // handles restoring of the windows begin // made Window normal WindowState:= wsNormal; // Restore other Windows of the app Application.Restore; // Restore the old Restore handler Application.OnRestore:= FOnRestore; // Call the restore handler IF Assigned (FOnRestore) then FOnRestore (sender); end;
Måske en lidt lettere måde, men så er spørgsmålet bare hvad man skal skrive for at den ikke fortsætter med at minimere formen !? ;)
Question/Problem/Abstract:
Does anybody know how to capture the minimize button press and act on it before it actually minimizes the form? Answer:
You should intercept WM_SYSCOMMAND messages like this:
type TForm1 = class(TForm) public procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; end;
procedure TForm1.WMSysCommand; begin if (Msg.CmdType = SC_MINIMIZE) or (Msg.CmdType = SC_MAXIMIZE) then begin // your code... end; DefaultHandler(Msg); end;
geek1011 >> læs alle komentarer, prøv evt selv !!!!!!!!
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.