trm_control_subclass()

Purpose

Allows subclassing of all or individual control classes used by the 4.600 terminal manager

Syntax

long pascal trm_control_subclass(int type,long NewWndProc)

Parameters

int type

See Description below

 

long NewWndProc

See Description below

Description

In 4.500 the only window created by DP4 is the window returned by trm_get_hwnd(). In 4.600, however, every control in every map is a separate window. Consequently subclassing terminal manager windows has to be handled differently.

The function trm_control_subclass() allows subclassing of all or individual control classes used by the 4.600 terminal manager. The types of control are listed in MAPS.H, namely the defines from CT_EDIT to CT_VCR. Note that CT_ICON and CT_BITMAP use the same Windows class, as do all the classes CT_CHECKBOX to CT_VCR.

There are two ways to use this function:

  • If you pass a specific type, such as CT_EDIT, you only subclass controls with the corresponding window class. Because some control types share window classes, however, you may subclass several control types. For example, passing CT_BUTTON would also subclass checkboxes and radio buttons.

  • If you pass 0 as the type, all classes used by the terminal manager are subclassed with NewWndProc, which should be a pointer to a window function or 0. 0 removes subclassing previously installed by trm_control_subclass().

When subclassing a single control type, the return value is the previous window function for the class. This value can be used to pass on messages to the old window function through CallWindowProc().

When subclassing all types of control, the return value must be ignored. To pass on a call to the previous window function, use GetClassLong() as follows:

CallWindowProc(GetClassLong(hWnd,0),hWnd,wMsg,wParam,lParam);

See the Example program below.

Note that when trm_control_subclass() is used in this way, calls to it cannot be nested successfully. The return value from GetClassLong(0) is set when trm_control_subclass() is first called and is not changed by subsequent calls to the function.

Calling trm_control_subclass(0,NewWndProc) does not subclass the main window of the application. To subclass this window, proceed as follows:

hWnd = (HWND) trm_get_hwnd();
OldWndProc = GetWindowLong(hWnd,GWL_WNDPROC);
SetWindowLong(hWnd, GWL_WNDPROC,NewWndProc);

As a convenience to programmers GetClassLong(hWnd, 0) also returns the original Window function for the window, allowing one Window function to subclass all windows created by the terminal manager.

Please note the following two very important points concerning trm_subclass():

  • trm_control_subclass() is only effective for Windows created after the call to trm_control_subclass() is made. Terminal manager windows that already existed before the call are not subclassed.

  • Similarly, if trm_control_subclass(,0) is called to remove subclassing, the subclassing is only removed for Windows created after the call to trm_control_subclass(). The subclassing window function remains in effect for controls that remain on screen. If your subclass function resides in a DLL that may be unloaded (for example inside an OSDI), then your program will terminate with an unrecoverable error if the DLL is unloaded before the windows are destroyed. For this reason it is advisable to ensure that you clear the screen before removing subclassing, for example by calling map_clear_all() followed by trm_refresh().

Return values

See Description above

Example

#include <windows.h>
#include "dp4far.h"
#include "dp4capi.h"
#include "600.h"

long CALLBACK NewWndProc(HWND hWnd, int wMsg,int wParam, long lParam) { printf("subclass %x %x %x %x\r\n",hWnd,sMsg,wParam,lParam); return CallWindowProc(GetClassLong(hWnd,0),hWnd,sMsg,wParam,lParam); }
void process() { char x[8]; trm_control_subclass(0,(long) caddr(NewWndProc)); map_load("PROGMAKE"); map_datamap(505); askf_u(505,1,x); }