Sybase, Inc. Navigational Bar

Powersoft Tools

Tip #14 - Order! Order! Setting Tab Order at Runtime

Medical students spend a lot of time studying the anatomy of the human body in order to understand the connections between various organs. By mastering the circulatory system, Cardiologists are able to perform bypass surgery and other vein grafting operations to save lives. Windows programmers also, spend many days and nights studying the anatomy of the Windows API in order to be able to debug their ex-colleague's applications.

This issue of Dr. Power++ focuses on the issues of setting tab stops for ActiveX controls.

 Dr. Power++

Windows and Controls

In Microsoft Windows virtually every visual component is a form of a window, each of which is created with the CreateWindow() function. In Power++ the Component Library class, WWindow, is responsible for creating windows. Consider the following window:


Figure 1, Sample Window

Figure 1 illustrates the following windows:

The form window is created as the parent form for the application. The command button and the textbox are created as children of the form window. The command button and textbox are commonly referred to as "controls". Controls are windows that contain a common display format and common logic that interacts with users at runtime. The display format of windows and controls includes many properties, some of which are:


Figure 2, Rectangle properties for each window

In the example assume that the textbox was created first and then the command button was created second. If both controls have enabled the TabStop property then pressing the tab key will result in the textbox getting focus, the command button getting focus and then the textbox getting focus and so on.

Because the textbox was created first it gets assigned a Z position of 1 and the next control to be created, command button, gets assigned a Z position of 2. Windows uses the Z position or Z order to determine which control should get focus if a user presses tab. All controls, except for OLE controls, in Power++ have the functions SetTabStop() and SetZOrder().

The function SetTabStop() will either enabled or disable the TabStop property and the function SetZOrder() will rearrange the ordering for each control on the Z axis. The code below enables the TabStop property and sets the Z position for various controls found on a form.

 

 The example above assumes that a form contains the following controls:

Since the three command buttons are native Power++ controls we use the functions SetTabStop() and SetZOrder() to control their ordering. OLE controls and ActiveX controls are not the same as native controls thus require an extra step to control their ordering.

Before we can change the TabStop or Z position property of an OLE control we first must obtain the handle to the window that manages the control. This is done by calling the GetInplaceWindowHandle() function that is provided by Power++. Since the WControl class already has functions to manage the TabStop and Z position property we are going to create a WControl class based on the window handle of the OLE control. The function below, OLETabStop(), gets the InplaceWindowHandle of an OLE control and then sets the TabStop property to true and then sets the Z position accordingly.

OLE Controls: 

When you press tab on the command button, Windows sends a tab message to the OLE control's InplaceWindowHandle. Due to the design of some OLE controls, they may not be able to process the tab message as expected. Thus, you will need to find another way to send focus to an OLE control.

This case can be demonstrated by the DataWindow control provided with Power++. The DataWindow control is parented to the ActiveX InplaceWindow called AfxWnd40. Since we know the desired flow of focus on our form, we need to code the lostfocus event handler for the control that has focus before the DataWindow.

In our case, tab flow should go from command button, cb_2, to the DataWindow control, dw_1. In the lostfocus event handler for command button, cb_2, we check to see where Window sent the tab message. If the message went to the dw_1's InplaceWindowHandle, then we call SetFocus on the window that represents the DataWindow, PSDWX050. For more information about this window please refer to Tip13.

 



Click here to return to Dr Power++

Return to Power++ Home Page.


to top of page

Copyright © 1999 Sybase, Inc. All Rights Reserved.
Privacy Policy
Legal