Thanks Saulius,

At least SetConsoleMenuClose grayed also the option Close in caption menu not 
only the button in title bar. :)
I still don't understand why we have to introduce HB_BREAK_FLAG in Inkey Poll 
in response to CTRL_CLOSE_EVENT.
I think if we do this .-
---
Index: gtwin.c
===================================================================
--- gtwin.c     (revision 14068)
+++ gtwin.c     (working copy)
@@ -569,9 +569,9 @@
          bHandled = FALSE;
          break;

-      case CTRL_CLOSE_EVENT:
       case CTRL_BREAK_EVENT:
          s_bBreak = HB_TRUE;
+      case CTRL_CLOSE_EVENT:
          bHandled = TRUE;
          break;

---
Everyone happy and does the same that Clipper program with .-

PROCEDURE Main()
   ? "Click [X] Not close windows"
   Wait
   RETURN

Best regards,
--
Xavi

El 05/03/2010 10:19, Saulius Zrelskis escribió:
[for those interested]
Sample below really controls console close button on Windows XP and
later systems. Please test it and enjoy:)

--->>>
#include 'inkey.ch'

proc main()
   local nKey

  while (nKey := Inkey(0)) # K_ESC
    Qout(Str(nKey) +'  "' +Chr(nKey) +'"')
    if nKey == Asc("0") .or. nKey == Asc("1")
       SetConsoleMenuClose(nKey == Asc("1"))
       Qqout(if(SetConsoleMenuClose(), '  enabled', '  disabled'))
    endif
  end
return

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

BOOL WINAPI
SetConsoleMenuClose( IN BOOL fEnable );

// SetConsoleMenuClose( lEnable )  ->   lPreviousState
HB_FUNC( SETCONSOLEMENUCLOSE )
{
    HMENU hSysMenu = GetSystemMenu( GetConsoleWindow(), FALSE );

    if( hSysMenu )
    {
       BOOL fCurrent = ( GetMenuState( hSysMenu, SC_CLOSE, MF_BYCOMMAND
)&  MF_GRAYED ) == FALSE;

       if( hb_pcount() )
       {
          BOOL fEnable = hb_parl( 1 );

          if( fCurrent != fEnable )
          {
             /*
                SetConsoleMenuClose() API really controls Close Menu
status, but "forgets"
                to gray close button on titlebar. EnableMenuItem() API
does this trick.
                Without SetConsoleMenuClose() clicking on titlebar icon
close button becomes enabled.
             */
             SetConsoleMenuClose( fEnable );
             EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | (
fEnable ? MF_ENABLED : MF_GRAYED ) );
          }
       }
       hb_retl( fCurrent );
    }
    else
       hb_retl( FALSE );
}
#PRAGMA ENDDUMP
<<<---

Best regards,
Saulius
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to