Solved

set foreground window

Posted on 2001-09-05
4
410 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
Delphi application Soap connection 5 96
Delphi: Connect to running MS Outlook 4 49
Delphi...Split view - idea? 1 42
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

861 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now