Esempio n. 1
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// Is called from handlers ShutDown method to unregister any required hotkeys.
VOID CALLBACK UnregisterHandlerHotkey ( BYTE bHandlerID , BYTE bHotkeyID )
{
    // hotkey id WORD value' low byte equal to hotkey ID and high byte equal to handler id.
    WORD wHotkey = MAKEWORD ( bHotkeyID , bHandlerID ) ; 
    
    // Check whether we haven't exceeded maximum amount of hotkeys or handlers
    if ( ( 0xff == bHotkeyID ) || ( 0xBFFF <= wHotkey ) )
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HOTKEY_CLEANUP_FAILED ) ;

    if ( !UnregisterHotKey ( g_hWnd , wHotkey ) )
        ShowWin32Error ( GetLastError ( ) , IDS_CAPTION_ERROR , IDS_ERROR_HOTKEY_CLEANUP_FAILED ) ;
}
Esempio n. 2
0
bool DeleteACE(UserManager *panel,bool selection)
{
  bool res=false,has_dir=false;
  CFarPanelSelection sp((HANDLE)panel,selection);
  if(sp.Number())
  {
    for(int i=0;i<sp.Number();i++)
      if(sp[i].FileAttributes&FILE_ATTRIBUTE_DIRECTORY)
      {
        has_dir=true;
        break;
      }
    if(has_dir) ShowCustomError(mDelFolderWarning);
    else
    {
      TCHAR warning[TINY_BUFFER];
      if(sp.Number()==1)
      {
        TCHAR Truncated[MAX_PATH];
        _tcscpy(Truncated,sp[0].FileName);
        FSF.TruncPathStr(Truncated,50);
        FSF.sprintf(warning,GetMsg(mDelOne),Truncated);
      }
      else
        FSF.sprintf(warning,GetMsg(mDelACEN+NumberType(sp.Number())),sp.Number());
      const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)};
      if(!Info.Message(&MainGuid,&DelACEMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2))
        for(int i=0;i<sp.Number();i++)
        {
          if(sp[i].UserData.FreeData)
          {
            if(UpdateAcl(panel,panel->level,GetSidFromUserData(sp[i].UserData.Data),GetItemTypeFromUserData(sp[i].UserData.Data),GetLevelFromUserData(sp[i].UserData.Data),actionDelete))
              res=true;
            else
              break;
          }
        }
    }
  }
  return res;
}
Esempio n. 3
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// Is called from handlers initialization method to register any required hotkeys. This function 
// should take care of unique hotkey IDs that are being assigned. Returns ID of the registered
// hotkeys or 0 if failed.
BYTE CALLBACK RegisterHandlerHotkey ( BYTE bHandlerID , UINT fsModifiers , UINT vkCode )
{
    static BYTE bNextHotkeyID = 0 ;

    // When receiving the WM_HOTKEY message we will need to find out which handler it belongs to. So
    // in order to simplify this we will make hotkey WORD value' low byte equal to hotkey ID and
    // high byte equal to handler id.
    WORD wHotkey = MAKEWORD ( ++bNextHotkeyID , bHandlerID ) ; 
    
    // Check whether we haven't exceeded maximum amount of hotkeys or handlers
    if ( ( 0xff == bNextHotkeyID ) || ( 0xBFFF <= wHotkey ) )
    {
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HANDLER_NOT_INITIALIZED ) ;
        return 0 ;
    }

    BOOL bRegistered = RegisterHotKey ( g_hWnd , wHotkey , fsModifiers , vkCode ) ;
    if ( bRegistered )
        return bNextHotkeyID ;
    else
        return 0 ;
}
Esempio n. 4
0
bool GetComputer(UserManager *panel,bool selection)
{
  bool res=false;
  if(selection)
  {
    /*
      000000000011111111112222222222333333333344444444
      012345678901234567890123456789012345678901234567
    00                                                00
    01   ÉÍÍÍÍÍÍÍÍÍÍÍ Select Computer ÍÍÍÍÍÍÍÍÍÍÍÍ»   01
    02   º Computer:                              º   02
    03   º ZG                                    ³º   03
    04   º (empty for local system)               º   04
    05   ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ   05
    06                                                06
      000000000011111111112222222222333333333344444444
      012345678901234567890123456789012345678901234567
    */
    static const TCHAR *ComputerHistoryName=_T("UserManager\\Computer");
    FarDialogItem DialogItems[]=
    {
    /*0*/  {DI_DOUBLEBOX,3,1,44,5,{0},NULL,               NULL,0,                    GetMsg(mSelCompTitle),   0,0,{0,0}},
    /*1*/  {DI_TEXT,     5,2, 0,0,{0},NULL,               NULL,0,                    GetMsg(mSelCompLabel),   0,0,{0,0}},
    /*2*/  {DI_EDIT,     5,3,42,0,{0},ComputerHistoryName,NULL,DIF_HISTORY|DIF_FOCUS,_T(""),                  0,0,{0,0}},
    /*3*/  {DI_TEXT,     5,4, 0,0,{0},NULL,               NULL,0,                    GetMsg(mSelCompFootnote),0,0,{0,0}},
    };
    DialogItems[2].Data=panel->computer_ptr;
    CFarDialog dialog;
    int DlgCode=dialog.Execute(MainGuid,GetComputerGuid,-1,-1,48,7,NULL,DialogItems,ArraySize(DialogItems),0,0,ComputerDialogProc,0);
    if(DlgCode!=-1)
    {
      if(dialog.Str(2)[0])
      {
        TCHAR tmp[512];
        if(_tcsncmp(dialog.Str(2),_T("\\\\"),2))
        {
          _tcscpy(tmp,_T("\\\\"));
          _tcscat(tmp,dialog.Str(2));
        }
        else
        {
          _tcscpy(tmp,dialog.Str(2));
        }
        HANDLE hSScr=Info.SaveScreen(0,0,-1,-1);
        const TCHAR *MsgItems[]={_T(""),GetMsg(mOtherConnect)};
        Info.Message(&MainGuid,&MessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),0);
        wchar_t temp_computer_name[MAX_PATH];
        _tcscpy(temp_computer_name,tmp);
        DWORD count;
        PVOID buffer;
        if(NetQueryDisplayInformation(temp_computer_name,2,0,1,MAX_PREFERRED_LENGTH,&count,&buffer)==NERR_Success)
        {
          NetApiBufferFree(buffer);
          wcscpy(panel->computer,temp_computer_name);
          panel->computer_ptr=panel->computer;
          res=true;
        }
        else ShowCustomError(mOtherNetNotFound);
        Info.RestoreScreen(hSScr);
      }
      else
      {
        wcscpy(panel->computer,L"");
        panel->computer_ptr=NULL;
        res=true;
      }
    }
  }
  else
  {
    wcscpy(panel->computer,L"");
    panel->computer_ptr=NULL;
    res=true;
  }
  return res;
}
Esempio n. 5
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// Application entry point
int APIENTRY _tWinMain ( HINSTANCE hInstance ,
                         HINSTANCE hPrevInstance ,
                         LPTSTR    lpCmdLine ,
                         int       nCmdShow )
{
    UNREFERENCED_PARAMETER ( hPrevInstance ) ;
    UNREFERENCED_PARAMETER ( lpCmdLine ) ;
    UNREFERENCED_PARAMETER ( nCmdShow ) ;

    g_hInst = hInstance ;

    // Ensure that only one copy of our application is running.
    HANDLE mutex = CreateMutex ( NULL , FALSE , INSTANCE_MUTEX ) ;
    DWORD dwRetVal = WaitForSingleObject ( mutex , 0 ) ;
    if ( dwRetVal == WAIT_TIMEOUT )
    {
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_ALREADY_RUNNING ) ;
        return 1 ;
    }

    // Create a fake window to listen to events.
    WNDCLASSEX wclx =  { 0 } ;
    wclx.cbSize         = sizeof( wclx ) ;
    wclx.lpfnWndProc    = &WindowProc ;
    wclx.hInstance      = hInstance ;
    wclx.lpszClassName  = WINDOWCLASS_NAME ;
    RegisterClassEx ( &wclx ) ;
    g_hWnd = CreateWindow ( WINDOWCLASS_NAME ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            0 ,
                            HWND_MESSAGE ,
                            0 ,
                            g_hInst ,
                            0 ) ;

    // Initialize array of handlers. Note to app extenders: register your hotkey handlers here.
    g_pHandlers [ 0 ] = new CLayoutSwitcher   ( ) ;
    g_pHandlers [ 1 ] = new CShellExecutor    ( ) ;
    g_pHandlers [ 2 ] = new CClipboardHistory ( ) ;
    g_pHandlers [ 3 ] = new CDummyTextGenerator ( ) ;
    g_pHandlers [ 4 ] = new CZOrderChanger ( ) ;

    for ( BYTE index = 0 ; index < NUM_LIVEKEYS_HANDLERS ; index++ )
    {
        BOOL bInitialized = g_pHandlers [ index ]->Initialize ( 
            index , g_hWnd , g_hInst , RegisterHandlerHotkey ) ;
        if ( !bInitialized )
        {
            ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HANDLER_NOT_INITIALIZED ) ;
            delete g_pHandlers [ index ] ;
            g_pHandlers [ index ] = NULL ;
        }
    }

    // Set hook on all keyboard events in order to implement hotkeys functionality.
    g_hHook = SetWindowsHookEx ( WH_KEYBOARD_LL , 
                                 LowLevelHookProc , 
                                 GetModuleHandle ( NULL ) , 
                                 0 ) ;
    if ( NULL == g_hHook )
    {
        ShowCustomError ( IDS_CAPTION_ERROR , IDS_ERROR_HOOK_FAILED ) ;
        return 1 ;
    }

    // And finally start message handling loop.
    MSG msg ;
    while ( GetMessage ( &msg , NULL , 0 , 0 ) )
    {
        TranslateMessage ( &msg ) ;
        DispatchMessage ( &msg ) ;
    }

    // Some cleanup here
    for ( BYTE index = 0 ; index < NUM_LIVEKEYS_HANDLERS ; index++ )
        if ( NULL != g_pHandlers [ index ] )
        {
            g_pHandlers [ index ]->ShutDown ( UnregisterHandlerHotkey ) ;
            delete g_pHandlers [ index ] ;
        }

    UnregisterClass ( WINDOWCLASS_NAME , hInstance ) ;
    DestroyWindow ( g_hWnd ) ;
    UnhookWindowsHookEx ( g_hHook ) ;
 
    return 0 ;
}