Solved

set foreground window

Posted on 2001-09-05
4
415 Views
Last Modified: 2010-04-06
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
Comment
Question by:allio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6456577
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
 

Author Comment

by:allio
ID: 6456964
The Formstyle of the forms are not MDIChild. It is fsStayOnTop only. Thank you anyway =)
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 6459714
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
 
LVL 17

Expert Comment

by:inthe
ID: 6459716
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question