Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

set foreground window

Posted on 2001-09-05
4
Medium Priority
?
417 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

721 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