Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

set foreground window

how do you know the focus sequence in multiple non MDIChild forms?

for example, form1, form2 and form3 is created using the main form. when form3 closes, the focus will be on form2. when form2 closes, the focus will be on form1.

Hope you can help me out on this. thank you in advance
0
allio
Asked:
allio
  • 3
1 Solution
 
intheCommented:
hi,
see the mdichildren property of the mainform.

ie
if you have two mdichildren this would continually switch the focused one:

MDIChildren[1].SetFocus;

from delphi help (there is quick example in help file also) :

property MDIChildren[I: Integer]: TForm;

Description

Use MDIChildren to access a child form.

I is the index of the child form to access. The order of MDI children changes as different MDI forms are activated. Initially, forms are listed in creation order, with new forms being added to the end of the array. Whenever an MDI child is activated, however, it moves to the front of the list. Thus, use I to index over all forms in the array, but not to refer to a specific form.

MDIChildren is meaningful only if the form is an MDI frame (that is, if the form?s FormStyle property is set to fsMDIForm).
0
 
allioAuthor Commented:
The Formstyle of the forms are not MDIChild. It is fsStayOnTop only. Thank you anyway =)
0
 
intheCommented:
sorry bad reading on my part ..,
note.
the following may be a bit messey i was writing it while thinking and testing some ideas..but it might work ;)

i dont think enumwindows will help ,maybe you could use

getwindow or getnextwindow with GW_HWNDPREV flag..
it will get the previous window from whatever handle you pass to it.
var
h : Thandle;
begin
h := GetNextWindow(form1.handle,GW_HWNDPREV);
h := GetNextWindow(h,GW_HWNDPREV);
etc...
you could make a loop that cycled this and call GetWindowText() to check the captions of each form and add to a list & when it doesnt contain some text of your desired captions you have finished.
so put your forms captions like:
myform - settings
myform - database
myform - someotherthing
then the loop can be using something like
if
Pos(AnsiUpperCase('myform'),AnsiUpperCase(StrPas(@capt[0])))<> 0 then begin
//this is one of my forms
//some add form handle to list procedure
//add form caption as well to list
end //if
else //no more forms
end; //loop

then if you wish  to focus any of teh forms ninparticular find where it is in the order and call its handle

SetForeGroundWindow(forms_handle_from_list_procedure);

so if you have your forms with fsstayontop style and the above code on main form which is normal style and show a couple of the child forms then click button on main form this would this would get the second from top window,ie if you had two child forms it would switch focus ..

heavens i hope theres a easier way that all that ;-)
0
 
intheCommented:
note
GW_HWNDPREV flag ,it will get the previous window from the z-order so if you open notepad while messing with several of your forms open then notepad would appear in the middle somewhere..
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now