[fpc-pascal]Re: How to resize window under win32? (Jeff Pohlmeyer)

Matt D. Emson matt at Diplomat.co.uk
Fri Feb 28 13:49:41 CET 2003


I sent more or less this info yesterday, but it bounced (my ISP doesn't
like redirecting email from my work IP address!!!).... I think the
CreateProcess idea is better than this one, but just in case...

Assuming you have a window with the caption 'Untitled - Notepad'
(running notepad.exe will get you this)

Function  ResizeWindow(const Caption: pchar; const AWidth, Aheight:
integer): boolean; var
  h: Thandle;
  r: Trect;
  Width, Height, Left, Top: integer;

begin
  Result := False;
  
  h := FindWindow( nil, Caption );

  if (h <> 0) and GetWindowRect(h, r) then begin
    Width := (r.right - r.left);
    Height := (r.Bottom - r.top);
    Left := r.Left;
    Top := r.Top;
    
    if (Awidth = Width) and (Aheight = height) then exit; //don't bother
if the size is same

    Windows.MoveWindow(h, Top, Left, Width, Height, true); //DOH!! Silly
api name M$ 2 API's would have been
	
//easier... If you want to move the window you
	
//must track it's size too!!!!		
    
    Result := True; //<--- only return true is we do a resize.... You
could put this above the line
			  //		"if (Awidth..." if you want to
know that you 'found the window' but
			  //        didn't necessarily move it.
  end;
end;

Therefore:

  Resizewindow('Untitled - Notepad', 10, 10);

> -----Original Message-----
> From: fpc-pascal-admin at deadlock.et.tudelft.nl 
> [mailto:fpc-pascal-admin at deadlock.et.tudelft.nl] On Behalf Of 
> Bernhard Steffen
> Sent: 28 February 2003 12:07
> To: fpc-pascal at deadlock.et.tudelft.nl
> Subject: [fpc-pascal]Re: How to resize window under win32? 
> (Jeff Pohlmeyer)
> 
> 
> > > I'm launching another program from Freepascal program 
> through "exec" 
> > > I need code that can set the position and size of the started 
> > > program.
> > 
> > I haven't used Windows in a while, but I think you need
> > CreateProcess() instead of WinExec()
> > [...]
> 
> If you have access to the source code of the launched 
> program, you can use the SetWindowPos function to set the 
> window position and size from within that program.
> 
> Bernhard
> 
> -- 
> bernhard.steffen at gmx.net
> http://www.bernhard-steffen.de/
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> http://lists.freepascal.org/mailman/listinfo/f> pc-pascal
> 




More information about the fpc-pascal mailing list