Thank you. I did implement similar a few days ago in GTWIN.

SetConsoleMenuClose() is an undocumented Windows API function, 
so IMO it's not a good idea to use it in Harbour.

Brgds,
Viktor

On 2010 Mar 5, at 10:19, Saulius Zrelskis wrote:

> [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

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

Reply via email to