ContentsIndexPreviousNext

Using C and COBOL

If you want to use COBOL in conjunction with C, you must take care to cooperate with the runtime system in how the screen is displayed.

There are some cases in which you don't need to worry about the runtime system, because 32-bit Windows will manage everything. Generally speaking, this occurs when your C code displays data in its own window. For example, you can display and accept data from a dialog box without interacting with the runtime system (all you need is the handle of the runtime's window, which you have in "mswinsub.c").

In other cases, you'll need to cooperate with the runtime's message handler. For example, if you want to display a graphical object in the main application window, you must monitor "paint" messages to the runtime system and draw your object when appropriate. The general technique for doing this is called "subclassing". When you subclass a window, you instruct 32-bit Windows to pass all of its messages to your own message handler. Typically, your message handler acts on one or more messages and then passes all the messages to the original message handler. For detailed instructions on subclassing, see any 32-bit Windows programming text. The following is an example of a typical case.

Suppose that you want to intercept messages to the runtime system and pass them to a routine called "MyMsgHandler". To do so, you would first declare "MyMsgHandler" as a function designed to be called from 32-bit Windows:

LRESULT CALLBACK MyMsgHandler( HWND, UINT, WPARAM, LPARAM );

Next, in your start-up code, you would get the address of the ACUCOBOL-GT message handler and then direct 32-bit Windows to send messages to your handler instead. The code reads like this:

FARPROC  lpfnMyMsgHandler, lpfnAcuWndProc;
lpfnMyMsgHandler = MakeProcInstance((FARPROC) MyMsgHandler, hAcuInstance );
lpfnAcuWndProc = (FARPROC) GetWindowLong( hAcuWnd, GWL_WNDPROC );
SetWindowLong( hAcuWnd, GWL_WNDPROC, (long) lpfnMyMsgHandler );

At this point, all messages that 32-bit Windows would normally direct to the ACUCOBOL-GT main window procedure will instead be received by "MyMsgHandler". Your message handler should intercept and act on the messages it cares about. At the end, it should then pass each message on to the original message handler and return the result. This is usually done with a line that reads like this:

return CallWindowProc( lpfnAcuWndProc, hWnd, iMsg, wParam, lParam );

For reference, ACUCOBOL-GT for 32-bit Windows currently acts on the following messages:

WM_ACTIVATE

WM_ACTIVATEAPP

WM_CHAR

WM_CLOSE

WM_COMMAND

WM_CREATE

WM_CTLCOLOR

WM_CTLCOLORBTN

WM_CTLCOLOREDIT

WM_CTLCOLORLG

WM_CTLCOLORLISTBOX

WM_CTLCOLORMSGBOX

WM_CTLCOLORSCROLLBAR

WM_CTLCOLORSTATIC

WM_DESTROY

WM_DRAWITEM

WM_ENDSESSION

WM_ERASEBKGND

WM_GETMINMAXINFO

WM_HSCROLL

WM_INITMENU

WM_INITMENUPOPUP

WM_KEYDOWN

WM_KILLFOCUS

WM_LBUTTONDBLCLK

WM_LBUTTONDOWN

WM_LBUTTONUP

WM_MBUTTONDBLCLK

WM_MBUTTONDOWN

WM_MBUTTONUP

WM_MEASUREITEM

WM_MOUSEMOVE

WM_NCLBUTTONDBLCLK

WM_NCLBUTTONDOWN

WM_NCPAINT

WM_PAINT

WM_PALETTECHANGED

WM_QUERYDRAGICON

WM_QUERYENDSESSION

WM_QUERYNEWPALETTE

WM_RBUTTONDBLCLK

WM_RBUTTONDOWN

WM_RBUTTONUP

WM_SETCURSOR

WM_SETFOCUS

WM_SIZE

WM_SIZING

WM_SYSCHAR

WM_SYSCOLORCHANGED

WM_SYSCOMMAND

WM_TIMER

WM_VSCROLL

See the SDK documentation for details about these messages.