Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-03

How to set focus to graph window?

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bernhard Steffen

I'm using the graph unit to provide graphing capabilities for my program (Win 32 platform). The graph window opens as a separate window, which is ok for me - except one point: The graph window gets opened with the least important position in Z-order (ie: all other windows are in front of this window).

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

Bernhard

Reply by email

Florian Klaempfl
to Bernhard Steffen
Bernhard Steffen wrote 11 lines
I'm using the graph unit to provide graphing capabilities for my program (Win 32 platform). The graph window opens as a separate window, which is ok for me - except one point: The graph window gets opened with the least important position in Z-order (ie: all other windows are in front of this window). 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.

Reply by email

Matt D. Emson
Show quoted text 8 lines
> 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.]

Something like:

var
  h: Thandle;
begin
  h := FindWindow( nil, 'Graph Window Title' ); //replace with your
window title
  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.' );
  end
  else
    writeln('Window was not found.');
end;

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.

Matt

Reply by email

Bernhard Steffen
to Matt D. Emson

Thanks, Florian and Matt, for your help.

I used Matt's approach to bring the window to the top (works), thus avoiding the need to change the original sources. And, I can print some additional information for the user before opening the graph window (I have a wrapper function for InitGraph, anyway).

Bernhard

Show quoted text 16 lines
> > 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.]

[...]

Reply by email

Marco van de Voort
to Matt D. Emson: I have no idea if this will help or not, but if the original poster can either get the…
Show quoted text 16 lines
> > 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.] Something like:
Or is he searching for a way to do

http://www.freepascal.org/faq.html#win-graph

?

Reply by email

Thomas Schatzl
to Bernhard Steffen: I'm using the graph unit to provide graphing capabilities for my program (Win 32…

Hi,

although others have already pointed out a few solutions, here're my two cents...

Show quoted text 9 lines
I'm using the graph unit to provide graphing capabilities for my program (Win 32 platform). The graph window opens as a separate window, which is ok for me - except one point: The graph window gets opened with the least important position in Z-order (ie: all other windows are in front of this window). 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)

Graph (Win32 version) publishes the variable "mainwindow" in its interface section. So why not use it?

E.g.

uses
  windows;
SetForegroundWindow(mainwindow); // bring window into foreground
SetFocus(mainwindow); // set focus

Probably worth trying... after a quick look at the sources I think that this variable holds the handle to the graph window, doesn't it? Florian?

[Not tested]

Regards,
Thomas

Reply by email

Bernhard Steffen
to Marco van de Voort: Or is he searching for a way to do http://www.freepascal.org/faq.html#win-graph ?

Thanks for the link, but that's not the case for me. My program is partly text-based and partly graph-based, so it's no "dummy" dos window for me... But I found a solution that works for me, thanks anyone for your input.

Bernhard

Show quoted text 5 lines
Or is he searching for a way to do http://www.freepascal.org/faq.html#win-graph ?

Reply by email