Solved

set foreground window

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

18 Experts available now in Live!

Get 1:1 Help Now