Syswait() question

Syswait() question

Postby wartiaga » Mon Apr 17, 2023 1:55 pm

Hi,

How can I lock the keyboard before a Syswait() and release it again after?

Thanks in advance.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: Syswait() question

Postby karinha » Mon Apr 17, 2023 4:03 pm

Try this:

Code: Select all  Expand view

   BlockInput(.T.)

   BlockInput(.F.)

DLL32 STATIC FUNCTION BlockInput( lTrava AS BOOL ) AS BOOL LIB "User32.DLL"
 




Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Syswait() question

Postby karinha » Mon Apr 17, 2023 4:11 pm

or

Code: Select all  Expand view

   TRAVATEC(.T.)  // TRAVA O TECLADO
   TRAVATEC(.F.)  // LIBERA O TECLADO

#pragma begindump
#include "windows.h"
#include "winable.h"
#include "hbapi.h"

HB_FUNC( TRAVATEC )
{
   BlockInput( hb_parl(1) );
}
#pragma enddump

 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Syswait() question

Postby wartiaga » Mon Apr 17, 2023 4:49 pm

karinha wrote:or

Code: Select all  Expand view

   TRAVATEC(.T.)  // TRAVA O TECLADO
   TRAVATEC(.F.)  // LIBERA O TECLADO

#pragma begindump
#include "windows.h"
#include "winable.h"
#include "hbapi.h"

HB_FUNC( TRAVATEC )
{
   BlockInput( hb_parl(1) );
}
#pragma enddump

 


Regards, saludos.


Thank you Karinha but it doesn't work well, in addition to that it also disables the mouse and when pressing several keys simultaneously the program interrupts.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: Syswait() question

Postby karinha » Mon Apr 17, 2023 6:36 pm

Would you like to turn off the entire keyboard or just CTRL+ALT+DEL?

¿Le gustaría apagar todo el teclado o simplemente CTRL+ALT+DEL?

Try this:

Code: Select all  Expand view

   TRAVATEC(.T.)  // TRAVA O TECLADO
   TRAVATEC(.F.)  // LIBERA O TECLADO

#pragma begindump

#include "windows.h"
#include "winable.h"
#include "winuser.h" // new
#include "hbapi.h"

HB_FUNC( TRAVATEC )
{
   BlockInput( hb_parl(1) );
}
#pragma enddump
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Syswait() question

Postby karinha » Mon Apr 17, 2023 7:21 pm

Mira esto se sirve:

Code: Select all  Expand view

Manuel Mercado gentilmente(in memory)

#Include "FiveWin.Ch"
#Include "Dll.Ch"

Function Teclado() //Main()

/*
   MsgStop( StartButton( .F. ), "Desabilitando o botão Start(Iniciar) - Win 9x, NT, 2K, XP" )

   MsgStop( StartButton( .T. ), "Habilitando   o botão Start(Iniciar) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowDesktop( .F. ), "Desabilitando o Desktop - Win 9x, NT, 2K, XP" )

   MsgStop( DesktopProc( "MyDesktop2", "Calc.exe" ), "Executando uma tarefa em outro desktop - Win NT, 2K, XP" )

   MsgStop( ShowDesktop( .T. ), "Habilitando o Desktop - Win 9x, NT, 2K, XP" )

   MsgStop( ShowTaskbar( .F. ), "Desabilitando o Taskbar(Barra de Tarefas) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowTaskbar( .T. ), "Habilitando   o Taskbar(Barra de Tarefas) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowClock( .F. ), "Desabilitando o Clock(Relogio) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowClock( .T. ), "Habilitando o Clock(Relogio) - Win 9x, NT, 2K, XP" )

   MsgStop( AltTabEnable( 0, .F. ), "Desabilitando ALT+TAB e ALT+ESC - Windows NT, 2k" )

   MsgStop( AltTabEnable( 0, .T. ), "Habilitando   ALT+TAB e ALT+ESC - Windows NT, 2k" )

   // Para Windows XP/NT e 2000 / 2003
   IF IsWinNT() .OR. IsWin2000()  //??? Nao testei em 2000/2003

       MsgStop( CtrlAltDel( .F. ), "Desabilitando o Ctrl+Alt+Del - Windows NT, 2k" )

       MsgStop( CtrlAltDel( .T. ), "Habilitando   o Ctrl+Alt+Del - Windows NT, 2k" )

   ELSE  //-> Windows 95/98 - Millenium Edition

      Ctrl_Alt_Del( .f. )

      MsgAlert( "CTRL+ALT+DEL DESLIGADO" + CRLF + "Please, press CTRL + ALT + DEL", "Desligado" )

      Ctrl_Alt_Del( .t. )

      MsgAlert( "CTRL+ALT+DEL LIGADO" + CRLF + "Please, press CTRL + ALT + DEL", "Ligado" )

   ENDIF
*/


Return Nil
//
//-> Comentario: Simplesmente, FANTASTICO!!!
//
//-> Complementando para Windows 95/98 Milleniun Edition
//
// Antonio Carlos Pantaglione
// Toninho@fwi.com.br
// Agosto/2001
//

//#include "fivewin.ch"
//#include "dll.ch"

//----------------------------------------------------------------------------//

//-> Modifiquei para nao ter choque com a funcao par o Windows NT(XP)
Function Ctrl_Alt_Del( lState )

   if !lState
      SysParInfo( 97, 1, 0, 0 )
   else
      SysParInfo( 97, 0, 0, 0 )
   endif

return Nil

//----------------------------------------------------------------------------//

dll32 static function SysParInfo( uAction AS LONG, uParam AS LONG, vParam AS LONG, uWinIni AS LONG ) ;
      AS LONG PASCAL  FROM "SystemParametersInfoA" LIB "User32.dll"

//----------------------------------------------------------------------------//

//-> Rotina em C -> By Manuel Mercado - The Best

#pragma BEGINDUMP

#include    <windows.h>
#include    <stdlib.h>
#include    <hbapi.h>
#define     ID_STARTBUTTON  0x130                  // Start button ID
#define     ID_TRAY         0x12F                  // System tray ID
#define     ID_CLOCK        0x12F                  // System clock ID
#define     PROGRAM_MANAGER "Program Manager"   // Program manager window name
#define     TASKBAR         "Shell_TrayWnd"     // Taskbar class name

int WINAPI TaskManager_Enable_Disable( BOOL ) ;
int WINAPI StartButton_Show_Hide( BOOL ) ;
int WINAPI Desktop_Show_Hide( BOOL ) ;
int WINAPI Process_Desktop(char *, char * ) ;
int WINAPI Taskbar_Show_Hide( BOOL ) ;
int WINAPI Clock_Show_Hide( BOOL ) ;
int WINAPI AltTab_Enable_Disable( HWND, BOOL ) ;
BOOL StartProcess( char *, char * ) ;
LRESULT CALLBACK LowLevelMouseHookProc( int nCode, WORD wParam, DWORD lParam ) ;
LRESULT CALLBACK MouseHookProc( int nCode, WORD wParam, DWORD lParam ) ;

HHOOK       hHook ;          // Mouse hook
HINSTANCE   hInst ;         // Instance handle

HB_FUNC( ALTTABENABLE )
{
   HWND hWnd    = (HWND ) hb_parnl( 1 ) ;
   BOOL bEnable = hb_parl( 2 ) ;
   int iRet ;

   iRet = AltTab_Enable_Disable( hWnd, bEnable ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( SHOWCLOCK )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Clock_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( SHOWTASKBAR )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Taskbar_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

/*  // CONTEM ERROS
HB_FUNC( DESKTOPPROC )
{
   char* c1 = hb_parc( 1 ) ;
   char* c2 = hb_parc( 2 ) ;
   int iRet ;

   iRet = Process_Desktop( c1, c2 ) ;
   hb_retni( iRet ) ;
}
*/


HB_FUNC( SHOWDESKTOP )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Desktop_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( STARTBUTTON )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = StartButton_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( CTRLALTDEL )
{
   BOOL bEnable = hb_parl( 1 ) ;
   int iRet ;

   iRet = TaskManager_Enable_Disable( bEnable ) ;
   hb_retni( iRet ) ;
}

int WINAPI TaskManager_Enable_Disable(BOOL bEnableDisable)
{
    #define KEY_DISABLETASKMGR  "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"
    #define VAL_DISABLETASKMGR  "DisableTaskMgr"

    HKEY    hKey;
    DWORD   val;
    LONG    r;

    if (RegOpenKey(HKEY_CURRENT_USER, KEY_DISABLETASKMGR, &hKey) != ERROR_SUCCESS)
        if (RegCreateKey(HKEY_CURRENT_USER, KEY_DISABLETASKMGR, &hKey) != ERROR_SUCCESS)
            return 0;

    if (bEnableDisable) // Enable
    {
        r = RegDeleteValue(hKey, VAL_DISABLETASKMGR);
    }
    else                // Disable
    {
        val = 1;
        r = RegSetValueEx(hKey, VAL_DISABLETASKMGR, 0, REG_DWORD, (BYTE *)&val, sizeof(val));
    }

    RegCloseKey(hKey);

    return (r == ERROR_SUCCESS ? 1 : 0) ;
}

int WINAPI StartButton_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd;

    hWnd = GetDlgItem( FindWindow( TASKBAR, NULL ), ID_STARTBUTTON ) ;
    if ( hWnd == NULL )
       return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE) ;
    UpdateWindow( hWnd );

    return 1 ;
}

int WINAPI Taskbar_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd;

    hWnd = FindWindow( TASKBAR, NULL ) ;
    if ( hWnd == NULL )
        return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE ) ;
    UpdateWindow(hWnd) ;

    return 1 ;
}

int WINAPI Desktop_Show_Hide( BOOL bShowHide )
{
    OSVERSIONINFO   osvi ;
    BOOL            bIsWindowsNT4SP3orLater ;
    int             iServicePack ;
    char           *p ;

    // Determine the current windows version
    osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ) ;
    GetVersionEx( &osvi );
    for (p = osvi.szCSDVersion; *p  && ! isdigit( *p ) ; *p++ ) ;
    iServicePack = atoi( p ) ;
    bIsWindowsNT4SP3orLater = ( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
                               ( ( ( osvi.dwMajorVersion == 4 ) && ( iServicePack >= 3 ) ) ||
                                     ( osvi.dwMajorVersion > 4 ) ) ;

    if ( ! bShowHide )
    {
        if ( ! hHook )
        {
            hHook  = SetWindowsHookEx( bIsWindowsNT4SP3orLater ? WH_MOUSE_LL : WH_MOUSE,
                                      bIsWindowsNT4SP3orLater ? ( HOOKPROC )LowLevelMouseHookProc : ( HOOKPROC )MouseHookProc,
                             hInst, 0 ) ;
            if ( ! hHook )
                return 0 ;
        }
    }
    else
    {
        UnhookWindowsHookEx(hHook);
        hHook = NULL;
    }

    return SetWindowPos( FindWindow( NULL, PROGRAM_MANAGER ), NULL, 0, 0, 0, 0,
                        bShowHide ? SWP_SHOWWINDOW : SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
}

LRESULT CALLBACK LowLevelMouseHookProc( int nCode, WORD wParam, DWORD lParam )
{
    PMSLLHOOKSTRUCT p = (PMSLLHOOKSTRUCT)lParam ;
    HWND hWnd = WindowFromPoint( p->pt ) ;

    if( nCode >= 0 )
    {
        if ( ( wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN ) && hWnd == GetDesktopWindow() )
        {
            return 1 ;
        }
    }

    return CallNextHookEx( hHook, nCode, wParam, lParam ) ;
}

LRESULT CALLBACK MouseHookProc( int nCode, WORD wParam, DWORD lParam )
{
    if( nCode >= 0 )
    {
        if ( wParam == WM_LBUTTONDBLCLK )
        {
            if ( ( ( MOUSEHOOKSTRUCT * )lParam )->hwnd == GetDesktopWindow() )
            {
                return 1 ;
            }
        }
    }

    return CallNextHookEx( hHook, nCode, wParam, lParam ) ;
}

int WINAPI Process_Desktop(char *szDesktopName, char *szPath )
{
    HDESK   hOriginalThread ;
    HDESK   hOriginalInput ;
    HDESK   hNewDesktop ;

    // Save original ...
    hOriginalThread = GetThreadDesktop( GetCurrentThreadId() ) ;
    hOriginalInput = OpenInputDesktop( 0, FALSE, DESKTOP_SWITCHDESKTOP ) ;

    // Create a new Desktop and switch to it
    hNewDesktop = CreateDesktop( szDesktopName, NULL, NULL, 0, GENERIC_ALL, NULL ) ;
    SetThreadDesktop( hNewDesktop ) ;
    SwitchDesktop( hNewDesktop ) ;

    // Execute process in new desktop
    StartProcess( szDesktopName, szPath ) ;

    // Restore original ...
    SwitchDesktop( hOriginalInput ) ;
    SetThreadDesktop( hOriginalThread ) ;

    // Close the Desktop
    CloseDesktop( hNewDesktop ) ;

    return 0 ;
}

BOOL StartProcess( char *szDesktopName, char *szPath )
{
    STARTUPINFO         si ;
    PROCESS_INFORMATION pi ;

    // Zero these structs
    ZeroMemory( &si, sizeof( si ) ) ;
    si.cb = sizeof( si ) ;
     si.lpTitle = szDesktopName ;
     si.lpDesktop = szDesktopName ;
    ZeroMemory( &pi, sizeof( pi ) ) ;

    // Start the child process
    if (!CreateProcess( NULL,    // No module name (use command line).
                        szPath,  // Command line.
                        NULL,    // Process handle not inheritable.
                        NULL,    // Thread handle not inheritable.
                        FALSE,   // Set handle inheritance to FALSE.
                        0,       // No creation flags.
                        NULL,    // Use parent's environment block.
                        NULL,    // Use parent's starting directory.
                        &si,     // Pointer to STARTUPINFO structure.
                        &pi ) )  // Pointer to PROCESS_INFORMATION structure.
    {
        return FALSE ;
    }

    // Wait until process exits
    WaitForSingleObject( pi.hProcess, INFINITE ) ;

    // Close process and thread handles
    CloseHandle( pi.hProcess ) ;
    CloseHandle( pi.hThread ) ;

    return TRUE ;
}

int WINAPI Clock_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd ;

    hWnd = GetDlgItem( FindWindow( TASKBAR, NULL ), ID_TRAY ) ;
     hWnd = GetDlgItem( hWnd, ID_CLOCK ) ;
    if ( hWnd == NULL )
        return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE ) ;
    UpdateWindow( hWnd ) ;

    return 1 ;
}

int WINAPI AltTab_Enable_Disable( HWND hWnd, BOOL bEnableDisable )
{
    #define m_nHotKeyID 100

    if ( ! bEnableDisable )
    {
        if ( ! RegisterHotKey( hWnd, m_nHotKeyID+0, MOD_ALT, VK_TAB ) )     // Alt+Tab
            return 0 ;
      if ( ! RegisterHotKey( hWnd, m_nHotKeyID+1, MOD_ALT, VK_ESCAPE ) )    // Alt+Esc
            return 0 ;
    }
    else
    {
        if ( ! UnregisterHotKey( hWnd, m_nHotKeyID + 0 ) )
            return 0 ;
        if ( ! UnregisterHotKey( hWnd, m_nHotKeyID + 1 ) )
            return 0 ;
    }
    return 1 ;
}
#pragma ENDDUMP

/*
Saludos

Manuel Mercado
*/

 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Syswait() question

Postby Antonio Linares » Mon Apr 17, 2023 8:07 pm

wartiaga wrote:Hi,

How can I lock the keyboard before a Syswait() and release it again after?

Thanks in advance.


oWndMain:Disable() and oWnd:Enable() later
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Syswait() question

Postby wartiaga » Tue Apr 18, 2023 5:12 pm

Antonio Linares wrote:
wartiaga wrote:Hi,

How can I lock the keyboard before a Syswait() and release it again after?

Thanks in advance.


oWndMain:Disable() and oWnd:Enable() later


Thank You Antonio,

I tried that in dialog but when I press esc the dialog disappears.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: Syswait() question

Postby Antonio Linares » Tue Apr 18, 2023 8:42 pm

Use:

ACTIVATED DIALOG oDlg VALID .F.

or this way:

ACTIVATED DIALOG oDlg VALID CanTheUserExit()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Syswait() question

Postby wartiaga » Wed Apr 19, 2023 3:06 am

Antonio Linares wrote:Use:

ACTIVATED DIALOG oDlg VALID .F.

or this way:

ACTIVATED DIALOG oDlg VALID CanTheUserExit()


It worked, thank you Antonio!
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests