Problem:
By default, the COBOL Text Window comes with the system menu that allows to minimize, restore down, and close the application window. Clicking on these buttons does not unfortunately trigger an event for the application to act upon, so it abruptly terminates the COBOL application without giving any chance to stop graciously. This often results to data file corruptions and other unexpected results.
The proposed solution in the past (see CloseButton.zip at the Examples and Utilities page) was to remove the system menu by using a Windows API functions GetWindowLong and SetWindowLong, and this does avoid the users to click on the Close button. What if you simply want to disable the Close button and keep the minimize and restore down buttons enabled?
Resolution:
There are actually other Windows API functions that can be used to disable the Close button from the system menu, and the following codes show how to use GetSystemMenu and EnableMenuItem:
|
*>get handle of text window *>get handle of window menu if ws-HMENU = 0 *>disable close button only if retlong not = 0 |
Here is a complete demo: CBLTxtWinNoClose.zip
You may find all the Windows API functions at the MSDN site, but GetSystemMenu, SetSystemMenu, and other related functions can be found specifically at the Menu Functions