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.
In some cases, you don't need to worry about the runtime system, because 32-bit Windows manages 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". 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 are instead received by "MyMsgHandler". Your message handler should intercept and act on the messages it cares about. At the end, it should 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:
See the Visual C++ .NET documentation for details about these messages.