Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make my parent form minimise on click a of button 1

Status
Not open for further replies.

Jayz

ISP
Feb 17, 2002
59
Hello all,

I've just started learning delphi 6.0 and now my head is full of ideas.

I apologies if this sounds like a simple question.

I've created a form with a button, when on the click action it will open notepad. But I'd also like to have this form minimise when notepad opens.

And then when I close notepad, I'd like the form to maximise (reappear back on desktop).

Thanks for you help in advance.

Regards,
Jayz
 
To MINIMIZE a form:
Code:
Application.Minimize;
or for a specific form i.e. form1:
Code:
form1.WindowState :=wsMinimized;

To MAXIMIZE a form:
Code:
Application.Maximize;
or for a specific form i.e. form1:
Code:
form1.WindowState :=wsMaximized;

Hope this helps
Clive [infinity]
 
Thankyou stretch for the reply, I'm able to minimize the form when notepad opens. I used your code on the onclick button property.

But when I close notepad I want the form to maximise.

What code do I need to detect that notepad has closed inorder to use the code form1.WindowState :=wsMaximized;

I'm thinking there needs to be a booleen expression in there somewhere.

Sorry as my knowledge of delphi is very limited.

 
You'll have to use CreateProcess and WaitForSingeObject function to achieve that. Something like this:
Code:
var
  SI             : STARTUPINFO;
  SA             : SECURITY_ATTRIBUTES;
  SD             : SECURITY_DESCRIPTOR;
  ProcInfo       : PROCESS_INFORMATION;
  LastError      : DWORD;
  ProcState      : DWord;
  ProcExitCode   : Cardinal;
begin
  FillChar(SI,SizeOf(SI),0);
  with SI do                               
  begin
    cb:=SizeOf(STARTUPINFO);
    cbReserved2 :=0;
    lpReserved  :=nil;
    lpDesktop   :=nil;
    lpReserved2 :=nil;
  end;
  InitializeSecurityDescriptor(@SD,SECURITY_DESCRIPTOR_REVISION);
  with SA do                              
  begin
    nLength:=SizeOf(SECURITY_ATTRIBUTES);
    bInheritHandle:=False;
    lpSecurityDescriptor:=@SD;
  end;
  if (not CreateProcess(nil, pChar('notepad.exe test.txt'), @SA, @SA, False, 0, nil, nil, SI, ProcInfo)) then   
  begin
    LastError := GetLastError();
    MessageDlg('Error: can not create process. Last error = ' + IntToStr(LastError), mtError, [mbOk], 0);                               
    Exit;
  end;
  Application.Minimize;
repeat                                                      
    ProcState := WaitForSingleObject(ProcInfo.hProcess, INFINITE);            
    GetExitCodeProcess(ProcInfo.hProcess, ProcExitCode);
  until (ProcState=WAIT_OBJECT_0);
  Application.Restore;
  ProcExitCode :=1 ;
  TerminateProcess(ProcInfo.hProcess, 0);
  CloseHandle(ProcInfo.hProcess);
end;
HTH

--- markus
 
Markus, your code is perfect for what I need but the problem is that it loads notepad test.txt file on startup of the app.

I need it to be on an event onclick of a button which is on the form (App).

So when I click this button 2 things should happen:
Notepad will open
My app will minimse

When I close notepad:
The app will maximise

Thanks in advance,
Jayz

 
Hmmm... Thought it was simple enough. Ok, Place this code to any OnClick procedure or any other proc which you'd call when you need. Command line param 'notepad.exe test.txt' was given as an example and you're are free to replace it with whatever you like.

Cheers.

--- markus
 
My apologies Markus, I finally got it to work. You're a scholar and a gentleman. Thankyou very much for your persistance.

Greatly appreciated.

Regards,
Jayz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top