[fpc-pascal]How to set focus to graph window?
Matt D. Emson
matt at Diplomat.co.uk
Thu Mar 13 15:04:00 CET 2003
> > Is there a way to set the focus to the freshly opened graph window
> > from within my program? (eg: open a graph window and define this as
> > the foremost window, in front even of the opening program)
> > Any help appreciated, thanks in advance
> Hmmm, I wrote the graph unit for win32 and I don't know an "official"
> way, so I guess you've to modify the graph unit sources.
I have no idea if this will help or not, but if the original poster can
either get the windows handle or find the handle from the class/title of
the window, they can use Win API calls to gain focus. [I'm assuming this
is a regular WinAPI window.]
h := FindWindow( nil, 'Graph Window Title' ); //replace with your
if ( h <> 0 ) then begin
//bring the window to the front
if not(SetForegroundWindow( h )) then
writeln( 'Failed to bring window to front.' );
//give the window focus (i.e. remove focus from any controls)
if not( SendMessage( h, WM_SETFOCUS, 0, 0 ) = 0 ) then
writeln( 'Failed to set focus to window.' );
writeln('Window was not found.');
You can substitute the 'WM_SETFOCUS' part to use the handle of the
actual control you wish to have focus, or leave it out and the default
windows functionality will happen.
More information about the fpc-pascal