Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

76 views
Skip to first unread message

Scott Coffey

unread,
Nov 29, 2021, 2:35:18 PM11/29/21
to
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

dlzc

unread,
Nov 30, 2021, 9:53:43 AM11/30/21
to
Dear Scott Coffey:
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

Michael Hagl

unread,
Dec 1, 2021, 2:09:15 AM12/1/21
to
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

0 new messages