
Author: Todd G. Nist, Protech Systems Inc.
The source code for the window as shown in the picture is attached: w-disablex.w.
When you want to disable the [X]-button in the title bar and also want to remove the 'Close'-option from the system menu, you only have to call this function from within the main block of the window:
{windows.i}
FUNCTION DisableWindowClose RETURNS LOGICAL
( /* parameter-definitions */ ) :
/*---------------------------------------
Purpose:
Notes:
-----------------------------------------*/
DEFINE VARIABLE hSysMenu AS INTEGER NO-UNDO.
DEFINE VARIABLE hParent AS INTEGER NO-UNDO.
DEFINE VARIABLE hInstance AS INTEGER NO-UNDO.
DEFINE VARIABLE iRetCode AS INTEGER NO-UNDO.
DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.
RUN GetParent IN hpApi(INPUT {&window-name}:HWND,
OUTPUT hParent).
/* Get handle to the window's system menu
(Restore, Maximize, Move, close etc.) */
RUN GetSystemMenu IN hpApi(INPUT hParent,
INPUT 0,
OUTPUT hSysMenu).
IF hSysMenu NE 0 THEN
DO:
/* Get System menu's menu count */
RUN GetMenuItemCount IN hpApi(INPUT hSysMenu,
OUTPUT iCnt).
IF iCnt NE 0 THEN
DO:
/* Menu count is based on 0 (0, 1, 2, 3...) */
/* remove the "close option" */
RUN RemoveMenu IN hpApi(INPUT hSysMenu,
INPUT iCnt - 1,
INPUT {&MF_BYPOSITION} + {&MF_REMOVE},
OUTPUT iRetCode).
/* remove the seperator */
RUN RemoveMenu IN hpApi(INPUT hSysMenu,
INPUT iCnt - 2,
INPUT {&MF_BYPOSITION} + {&MF_REMOVE},
OUTPUT iRetCode).
/* Force caption bar's refresh which
will disable the window close ("X") button */
RUN DrawMenuBar IN hpApi(INPUT hParent,
OUTPUT iRetCode).
{&window-name}:TITLE = "Try to close me!".
END. /* if iCnt NE 0... */
END. /* if hSysMenu NE 0... */
RETURN FALSE. /* Function return value. */
END FUNCTION.
Because you now have restricted the user from closing the window you will have to close it yourself from within 4GL. This statement will do it:
apply "window-close" to {&window-name}.
There are many ways for doing things. To refresh the title bar, instead of running DrawMenuBar, you could also
run FlashWindow in hpApi(hParent,0, output iRetCode).
| Attachment | Size |
|---|---|
| w-disablex.w.zip | 3.33 KB |