Setting Windows Explorer size and position

Posted by Jerry D on December 22, 2005

In Reply to: Setting Explorer Size and position? posted by creeek on December 13, 2005

: The following code works great.

: ShellExecute(Application.Handle, 'open', pchar('explorer.exe'), pchar('C:\'), pchar('C:\'), SW_NORMAL);

: But, what I would like to do is open the explorer window to a specific size and position.
: does anybody know how?
: The registry sounds a logical course, because when you close 'explorer' it tends to remember the size!

There is no Delphi routine for opening an application and at the same time setting its size and position. But you can set size and position of an application's main window *after* it has been started.

The MoveWindow function sets the size and position of a single application window. For this, you have to know the window's handle (HWND).

function MoveWindow(HWND: THandle; X, Y, nWidth, nHeight: DWORD; bRepaint: BOOLEAN): BOOLEAN

The function FindWindow lpClassName, lpWindowName: PChar): THandle
returns the window handle for the window that matches the ClassName and/or WindowName. If you do not wish to specify one of the parameters, pass NIL for it.


H := FindWindow(PChar('IEFrame'), nil); // Internet Explorer
H := FindWindow(nil, PChar('Calculator')); // Calculator

Related Articles and Replies