Thursday, January 27, 2011

How To Set and Change Tab Order in MFC.



Dialog boxes Controls get the focus in a specific order when the user hits the TAB key.


In VC++6 this order is decided through the interface (Dialog resource editor / Layout / Tab order - or Control-D).

In VC++.NET there are two new methods to access, set and change Tab order: Control .TapStop(boolean) and TabIndex(int).


- TabStop (there_is_a_tab_stop)
- TabIndex (index_of_tab_stop_the_lower_the_nearer)

Query:
How to adjust tab order in dialogs so that if it reaches the highest tab index then focus jumps to another dialog. Considering dialogs are placed in the same view.

Which function retrieve tab order number of current focused control?

Solution :  Please be aware that Tab order is a fiction. The order numbers just control the way in which
the control declarations are sorted in the resource (.rc) file, but have no other discernable property. When you invoke the set-tab-order. it is reflecting the Z-axis  order.
For example,  the first control on the dialog is 1, the second is 2, and so on.

Considering an example,  if you have the dialog,
Write,
               CWnd * child= GetWindow(GW_CHILD);

which gives you the first window in the sequence (tab # 1)

Note that the function GetNextDlgTabItem is what is normally used, so if you did
                           CWnd * last = child->GetNextDlgTabItem(TRUE);

then it will give you the last control (note that there is a difference betrween asking for the next window and the the next dialog item, or the previous window or the previous dialog item, because the next dialog item or previous dialog item return you the CWnd * of the window which is visible, enabled, and has WS_TABSTOP set (and if it is a static control such as a label, it deals with this situation by returning the associated active window), whereas iterating with
GetWindow(GW_HWND[NEXT|PREV]) merely gives you a window.

If you want to find the window which is the first window in the sequence, so actually try this,

CWnd * first = last->GetNextDlgTabItem();
(the default is FALSE, to move forward), which would give me the first active window.
But one need to be very careful to in implementation part.  It gets even more complex if, during the time you are running, you could disable that first tabbable window, or hide it, or the last window is disabled, along the way.
Easy method: 
Use UI. Open dialog and Press Ctrl+D and then you can set tab order for your control by click on numbers.

Please provide your comments...


Also Visit:
http://journeyallover.blogspot.com/2010/04/way-to-south-korea.html

http://journeyallover.blogspot.com/2010/04/frequently-asked-interview-question-in.html

http://journeyallover.blogspot.com/2010/04/biometrics.html



No comments:

Post a Comment

Health Benefits of Cashews

  Benefits of Cashews. Healthy food is an integral part of healthy body. Regular exercises such as Yoga and healthy diet is important to...