Sybase, Inc. Navigational Bar

Powersoft Tools

Tip #13 - Jazz Up Your DataWindow!

After researching various medical journals, I found a couple of treatments to relieve some DataWindow control ailments. All users complaining of the following symptoms should read on.

I have also heard rumors of end-users and developers complaining of headaches from seeing borders around the outside of their DataWindows. Two aspirins, unfortunately, will not cure your headache. Read on for the bonus cure at the end.

 Dr. Power++

Power++ DataWindow Advanced Medicines

I should mention that the treatments stated below are potent and require the use of the Microsoft Win 32 API. Before you attempt any of the following workarounds you must include WINDOWS.H in the precompiled header WPCH.HPP. If you are not sure how to include WINDOWS.H, please see the section entitled "Windows API Functions" in the on-line manuals.

Obtaining the DataWindow Handle

When you place a DataWindow control on a form, Power++ loads and activates the DataWindow OCX control. The visual component that is drawn on the form is called an OLE container. This OLE container is the parent of the DataWindow control and is represented in Microsoft Windows as a window with the class name AFXWND40. The actual DataWindow that is displayed on the form is a child window of AFXWND40 and is represented as a Window with the class name PBDWX050. You never see the AFXWND40 window because the PBDWX050 window is the same size.

In order to use the workarounds listed below you must retrieve the handles to the windows AFXWND40 and PBDWX050. The latter is easiest to obtain and will be done first. The DataWindow control contains a function that will return the handle of the PSDWX050 window at runtime. The function prototype is:

long WDataWindow::GetDataWindowHandle();

The following example stores the handle to the DataWindow in a variable called _dwHandle ( declared as HWND _dwHandle ):

Now that you have the handle to the DataWindow control, you can call the Windows API GetParent() to obtain the handle to the AFXWND40 window. The GetParent() function is prototyped as follows:

HWND dwParentHandle=::GetParent((HWND)dwHandle);

The dwParentHandle will primarily be used in the treatments.

Setting the focus to the DataWindow

The SetFocus function of the DataWindow control, currently, is an ill function. After calling the SetFocus(TRUE) function for a DataWindow, the observed results are that the focus is lost from the current control that has it but no other control gets focus. This happens because the focus is set on the parent of the DataWindow control, the AFXWND40 window.

Without the treatment, users are left manually clicking in the DataWindow to edit their data. This treatment involves the use of the Windows API SetFocus, which is prototyped as follows:

::SetFocus((HWND)dwHandle );

Imagine you have a DataWindow control and a command button, which is labeled 'Add', on the form. The command button is the first tab stop and the DataWindow is the second tab stop. If a user presses the command button, a new row is added to the DataWindow and the application should set focus on the DataWindow enabling the user to immediately enter data. The command button's click event handler contains the application of the treatment.

Alternatively, the user could press tab while the command button has focus. In this case the datawindow should receive focus while the command button loses focus. This situation is handled by the command button's lost focus event handler.

 


 TAB-ing out from a DataWindow

Currently, there is no way to exit a DataWindow by the means of a keyboard key. If, in your program, you would like to set the focus on the next control that has the TabStop style you can use the following call:

::PostMessage(dwParentHandle,WM_KEYDOWN,VK_TAB,0x000F0001);

PostMessage() is a Windows API function which is used to send a message to a window or control in your application. This treatment sends a message to the AFXWND40 window that simulates a TAB key press. This technique can be used to change the focus from our DataWindow object to the next tab stop control when we press the TAB key and we are positioned on the last editable column of the last row in the DataWindow. It can also be used to change the focus to the previous control by simulating a press of SHIFT-TAB when the first editable cell of our DataWindow is active.

The tab out function sends the TAB message to the AFXWND40 window.

The back tab out function sends the SHIFT-TAB message to the AFXWND40 window:

Observant readers will have noticed that the TabOut event and the BackTabOut event post the same message but their behaviors are different. Windows has already recognized that the SHIFT key has been pressed and will apply it to the tab message that the AFXWND40 window receives.

Simulating a TAB in the PressEnter Event

The DataWindow by default, moves left to right and right to left by using the tab key and shift-tab keys respectively. It also uses enter and shift-enter to move down and up respectively. Users wishing to move left and right with the tab and shift-tab combination need to simulate a tab when the enter key is pressed. The press enter event of the DataWindow allows you to override the default behaviour of the enter key. In the press enter event you need to send a tab key pressed message to the DataWindow, the PBDWX050 window.

The press enter event contains a flag called ActionCode that instructs the DataWindow how to process the message internally. In this case we want to tell the DataWindow to ignore the enter key press message. This is accomplished by setting the ActionCode to 1

Removing the Border from a DataWindow

By default, all DataWindows are displayed with a border and there is no option in Power++ that will disable the border. If you wish to disable the border then you need to call the Windows API function SetWindowLong(). This function sets various attributes of any window or control that is displayed on your form. At runtime, the AFXWND40 creates the PBDWX050 window with a style called WS_BORDER. This treatment will reset the styles of the PBDWX050 window without the WS_BORDER style. The minimum styles required for the DataWindow are WS_CHILD, WS_VISIBLE, WS_CLIPSIBLINGS and WS_CLIPCHILDREN.



Click here to see Tip#14

Return to Power++ Home Page.


to top of page

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