• Prevent user from ending program by right-clicking the icon in the tray

    From Scott Coffey@21:1/5 to All on Mon Nov 29 14:35:16 2021
    I have a POS application where I don't want users to exit the program
    by ending it externally. I had already added code to the program to
    prevent the "X" from appearing in the top-right corner, but they can
    still end the program by right-clicking the tray icon and selecting
    "close window". Is there a way to prevent that?
    --
    Scott at Scott dash(-) Coffey dot net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Scott Coffey on Tue Nov 30 06:53:42 2021
    Dear Scott Coffey:

    On Monday, November 29, 2021 at 12:35:18 PM UTC-7, Scott Coffey wrote:
    I have a POS application where I don't want users to exit the program
    by ending it externally. I had already added code to the program to
    prevent the "X" from appearing in the top-right corner, but they can
    still end the program by right-clicking the tray icon and selecting
    "close window". Is there a way to prevent that?
    --
    Scott at Scott dash(-) Coffey dot net

    Might see if this VB code will help? http://vbnet.mvps.org/index.html?code/forms/killclose.htm

    Can probably still kill it from Task Manager...

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Hagl@21:1/5 to All on Tue Nov 30 23:09:14 2021
    Hi Scott,

    try this:


    #PRAGMA BEGINDUMP
    #include "hbapi.h"
    #include "Windows.h"

    HB_FUNC( SETCONSOLETITLE )
    {
    hb_retl( SetConsoleTitle( hb_parc(1) ) );
    }

    HB_FUNC( FINDWINDOW )
    {
    hb_retnl( (LONG)FindWindow( NULL, hb_parc(1) ) ) ;
    }

    HB_FUNC( DELETECLOSEBUTTON )
    {
    DeleteMenu(GetSystemMenu( (HWND)hb_parnl( 1 ), FALSE),
    SC_CLOSE,
    MF_BYCOMMAND ) ;
    DrawMenuBar( (HWND)hb_parnl( 1 ) );
    }

    HB_FUNC( ENABLECLOSEBUTTON )
    {
    DeleteMenu(GetSystemMenu( (HWND)hb_parnl( 1 ), TRUE),
    SC_CLOSE,
    MF_BYCOMMAND ) ;
    DrawMenuBar( (HWND)hb_parnl( 1 ) );
    }

    HB_FUNC( SETFOREGROUNDWINDOW )
    {
    hb_retnl( SetForegroundWindow((HWND)hb_parnl( 1 )));
    }

    HB_FUNC( SENDMAXMESSAGE )
    {
    HWND hWnd;
    BOOL nRtn = 1;

    //---get handle to the window
    hWnd = GetForegroundWindow();

    //---tell the window to maximize iteself. won't be
    // true "full-screen" but it's the best we can do
    // and does not require any user action.
    SendMessage( hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );

    hb_retni( nRtn );
    }
    #PRAGMA ENDDUMP

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)