예제 #1
0
파일: chgdir.c 프로젝트: cixonline/ameol
/* This function handles the WM_COMMAND message.
 */
void FASTCALL ChangeDir_OnCommand( HWND hwnd, int id, HWND hwndCtl, UINT codeNotify )
{
   static BOOL fListHasFocus = FALSE;

   switch( id )
      {
      case IDD_NETWORK:
         if( WNetConnectionDialog( hwnd, WNTYPE_DRIVE ) == WN_SUCCESS )
            {
#ifndef WIN32
            HINSTANCE hinstNetDriver;
            int iDrive;

            hinstNetDriver = (HINSTANCE)WNetGetCaps( 0xFFFF );
            if( hinstNetDriver )
               {
               LPWNETGETLASTCONNECTION lpDialogAPI;

               lpDialogAPI = (LPWNETGETLASTCONNECTION)GetProcAddress( hinstNetDriver, (LPSTR)ORD_WNETGETLASTCONNECTION);
               if( lpDialogAPI != NULL )
                  if( lpDialogAPI( WNTYPE_DRIVE, &iDrive ) == WN_SUCCESS )
                     {
                     ++iDrive;
                     DriveListInitialize( GetDlgItem( hwnd, IDD_DRIVELIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), iDrive );
//                   SendDlgCommand( hwnd, IDD_DRIVELIST, CBN_SELCHANGE );
                     }
               }
#endif
            }
         break;

      case IDD_DIRECTORYLIST:
         if( codeNotify == LBN_SETFOCUS )
            fListHasFocus = TRUE;
         else if( codeNotify == LBN_KILLFOCUS )
            fListHasFocus = FALSE;
         else if( codeNotify == LBN_DBLCLK ) {
            UINT i;
            DWORD dw;
            char szDir[_MAX_PATH];
            char szCurDir[_MAX_PATH];
            LPSTR lpsz;

            /* On double-click, change directory and reinit the
             * listbox.  But all we stored in the string was
             * the directory's single name, so we use the bitmap
             * type to tell if we're below the current directory
             * (in which case we just chdir to our name) or above
             * (in which case we prepend "..\"'s as necessary.
             */
            i = ListBox_GetCurSel( hwndCtl );
            dw = ListBox_GetItemData( hwndCtl, i );

            /* If out bitmap is IDB_FOLDERCLOSED or the root,
             * then just .  If we're IDB_FOLDEROPENSELECT,
             * don't do anything.  If we're IDB_FOLDEROPEN then
             * we get the full current path and truncate it
             * after the directory to which we're switching.
             */
            if( IDB_FOLDEROPENSELECT == HIWORD( dw ) )
               {
               id = IDOK;
               goto CloseDialog;
               }

            /* Get get the directory for sub-directory changes. */
            ListBox_GetText( hwndCtl, i, szCurDir );
            if( IDB_FOLDEROPEN == HIWORD( dw ) && 0 != i )
               {
               /* Get the current path and find us in this path */
               GetWindowText( hwndCtl, szDir, sizeof( szDir ) );
               lpsz=_fstrstr( szDir, szCurDir );

               /* Null terminate right after us. */
               *( lpsz + strlen( szCurDir ) ) = '\0';

               /* Get this new directory in the right place */
               strcpy( szCurDir, szDir );
               }
            /* chdir has a nice way of validating for us. */
            if( 0 == _chdir( szCurDir ) )
               {
               /* Get the new full path. */
               Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH );
               DirectoryListInitialize( hwndCtl, GetDlgItem( hwnd, IDD_TEMPLIST ), szCurDir );
               //???? YH18/04/96 AnsiLower( szCurDir );
               SetDlgItemText( hwnd, IDD_EDIT, szCurDir );
               }
            }
         break;

      case IDD_DRIVELIST:
         if( codeNotify == CBN_SELCHANGE )
            {
            UINT i, iCurDrive;
            char szCurDir[ _MAX_PATH ];
            char szDrive[ _MAX_PATH ]; /* Enough for drive:volume */

            /* Get the first letter in the current selection */
            i = ComboBox_GetCurSel( hwndCtl );
            ComboBox_GetLBText( hwndCtl, i, szDrive );
            iCurDrive = _getdrive();  /* Save in case of restore */

            /* Attempt to set the drive and get the current
             * directory on it.  Both must work for the change
             * to be certain.  If we are certain, reinitialize
             * the directories.  Note that we depend on drives
             * stored as lower case in the combobox.
             */
            if( _chdrive( (int)( szDrive[ 0 ] - 'a' + 1 ) ) == 0 && ( Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH ) != 0 ) )
               {
               DirectoryListInitialize( GetDlgItem( hwnd, IDD_DIRECTORYLIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), szCurDir );

               /* Insure that the root is visible (UI guideline) */
               SendDlgItemMessage( hwnd, IDD_DIRECTORYLIST, LB_SETTOPINDEX, 0, 0L );
               AnsiLower( szCurDir );
               SetDlgItemText( hwnd, IDD_EDIT, szCurDir );
               break;
               }

            /* Changing drives failed so restore drive and selection */
            _chdrive( (int)iCurDrive );
            wsprintf( szDrive, "%c:", (char)( iCurDrive + 'a' - 1 ) );
            ComboBox_SelectString( hwndCtl, -1, szDrive );
            }
         break;

      case IDD_EDIT:
         if( codeNotify == EN_UPDATE )
            EnableControl( hwnd, IDOK, Edit_GetTextLength( hwndCtl ) > 0 );
         break;

      case IDOK: {
         LPCHGDIR lpChgDir;

         if( fListHasFocus )
            {
//          PostDlgCommand( hwnd, IDD_DIRECTORYLIST, LBN_DBLCLK );
            break;
            }
CloseDialog:
         lpChgDir = (LPCHGDIR)GetWindowLong( hwnd, DWL_USER );
         Edit_GetText( GetDlgItem( hwnd, IDD_EDIT ), lpChgDir->szPath, sizeof( lpChgDir->szPath ) );
         }

      case IDCANCEL: {
         register int i;

         for( i = IDB_DRIVEMIN; i <= IDB_DRIVEMAX; i++ )
            DeleteBitmap( rghBmpDrives[ i - IDB_DRIVEMIN ] );
         for( i = IDB_FOLDERMIN; i <= IDB_FOLDERMAX; i++ )
            DeleteBitmap( rghBmpFolders[ i - IDB_FOLDERMIN ] );
         fBitmapsLoaded = FALSE;
         _chdrive( iCurDrive );
         _chdir( szDefDir );
         EndDialog( hwnd, id == IDOK );
         break;
         }
      }
}
예제 #2
0
파일: wfinit.c 프로젝트: mingpen/OpenNT
VOID NEAR PASCAL InitMenus()
{
  WORD i;
  HMENU hMenu;
  OFSTRUCT os;
  INT iMax;
  CHAR szValue[MAXPATHLEN];
  HWND hwndActive;

  ENTER("InitMenus");

  hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  if (hwndActive && GetWindowLong(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
      iMax = 1;
  else
      iMax = 0;

  GetPrivateProfileString(szSettings, szUndelete, szNULL, szValue, sizeof(szValue), szTheINIFile);

  if (szValue[0]) {

        // create explicit filename to avoid searching the path

        GetSystemDirectory(os.szPathName, sizeof(os.szPathName));
        AddBackslash(os.szPathName);
        lstrcat(os.szPathName, szValue);

        if (MOpenFile(os.szPathName, &os, OF_EXIST) > 0) {

                hModUndelete = MLoadLibrary(szValue);

                if (hModUndelete >= (HANDLE)32) {
                    lpfpUndelete = (FM_UNDELETE_PROC)GetProcAddress(hModUndelete, "UndeleteFile");

                        if (lpfpUndelete) {
                                hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_FILE + iMax);
                                LoadString(hAppInstance, IDS_UNDELETE, szValue, sizeof(szValue));
                                InsertMenu(hMenu, 4, MF_BYPOSITION | MF_STRING, IDM_UNDELETE, szValue);
                        }
                } else {
                        FreeLibrary(hModUndelete);

                }
        }
  }

  /* Init the Disk menu. */
  hMenu = GetMenu(hwndFrame);

  if (nFloppies == 0)
    {
      EnableMenuItem(hMenu, IDM_DISKCOPY, MF_BYCOMMAND | MF_GRAYED);
      EnableMenuItem(hMenu, IDM_FORMAT,   MF_BYCOMMAND | MF_GRAYED);
      EnableMenuItem(hMenu, IDM_SYSDISK,  MF_BYCOMMAND | MF_GRAYED);
    }

  bNetAdmin = WNetGetCaps(WNNC_ADMIN) & WNNC_ADM_GETDIRECTORYTYPE;

  /* Should we enable the network items? */
  i = (WORD)WNetGetCaps(WNNC_DIALOG);

  i = 0;

  bConnect    = i & WNNC_DLG_ConnectDialog;     // note, these should both
  bDisconnect = i & WNNC_DLG_DisconnectDialog;  // be true or both false

  // use submenu because we are doing this by position

  hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_DISK + iMax);

  if (i)
        InsertMenu(hMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);

  if (bConnect && bDisconnect) {

        // lanman style double connect/disconnect

        LoadString(hAppInstance, IDS_CONNECT, szValue, sizeof(szValue));
        InsertMenu(hMenu, 6, MF_BYPOSITION | MF_STRING, IDM_CONNECT, szValue);
        LoadString(hAppInstance, IDS_DISCONNECT, szValue, sizeof(szValue));
        InsertMenu(hMenu, 7, MF_BYPOSITION | MF_STRING, IDM_DISCONNECT, szValue);
  } else if (WNetGetCaps(WNNC_CONNECTION)) {

  }

  hMenu = GetMenu(hwndFrame);

  if (bStatusBar)
      CheckMenuItem(hMenu, IDM_STATUSBAR, MF_BYCOMMAND | MF_CHECKED);
  if (bMinOnRun)
      CheckMenuItem(hMenu, IDM_MINONRUN,  MF_BYCOMMAND | MF_CHECKED);
  if (bSaveSettings)
      CheckMenuItem(hMenu, IDM_SAVESETTINGS,  MF_BYCOMMAND | MF_CHECKED);

  InitDriveBitmaps();

  InitExtensions();

  LEAVE("InitMenus");
}
예제 #3
0
파일: chgdir.c 프로젝트: cixonline/ameol
/* This function handles the WM_INITDIALOG message.
 */
BOOL FASTCALL ChangeDir_OnInitDialog( HWND hwnd, HWND hwndFocus, LPARAM lParam )
{
#ifndef WIN32
   HINSTANCE hinstNetDriver;
#endif
   LPCHGDIR lpChgDir;
   int iDrive;

   /* Set the current directory value
    */
   lpChgDir = (LPCHGDIR)lParam;
   if( *lpChgDir->szPath )
      {
      Edit_SetText( GetDlgItem( hwnd, IDD_EDIT ), lpChgDir->szPath );
      lstrcpy( szCurDir, lpChgDir->szPath );
      if( szCurDir[ 1 ] == ':' )
         iDrive = ( toupper( *szCurDir ) - 'A' ) + 1;
      else
         iDrive = _getdrive();
      }
   else
      {
      Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH );
      iDrive = _getdrive();
      }

   /* Show the Network button if we're running WorkGroups
    * or a similiar networking O/S.
    */
#ifdef WIN32
   ShowWindow( GetDlgItem( hwnd, IDD_NETWORK ), SW_SHOW );
#else
   hinstNetDriver = (HINSTANCE)WNetGetCaps( 0xFFFF );
   if( hinstNetDriver )
      {
      LPWNETSERVERBROWSEDIALOG lpDialogAPI;

      lpDialogAPI = (LPWNETSERVERBROWSEDIALOG)GetProcAddress( hinstNetDriver, (LPSTR)ORD_WNETSERVERBROWSEDIALOG);
      if( lpDialogAPI != NULL )
         ShowWindow( GetDlgItem( hwnd, IDD_NETWORK ), SW_SHOW );
      }
#endif

   /* Set window title
    */
   if( *lpChgDir->szTitle )
      SetWindowText( hwnd, lpChgDir->szTitle );

   /* Set the prompt title
    */
   if( *lpChgDir->szPrompt )
      SetWindowText( GetDlgItem( hwnd, IDD_PROMPT ), lpChgDir->szPrompt );

   /* Initialise the drive and directory lists
    */
   DriveListInitialize( GetDlgItem( hwnd, IDD_DRIVELIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), iDrive );
   DirectoryListInitialize( GetDlgItem( hwnd, IDD_DIRECTORYLIST ), GetDlgItem( hwnd, IDD_TEMPLIST), szCurDir );
   AnsiLower( szCurDir );

   /* Remember the current drive and directory
    */
   Amdir_GetCurrentDirectory( szDefDir, _MAX_PATH );
   iCurDrive = _getdrive();
   if( iDrive != iCurDrive )
      _chdrive( iDrive );
   if( strcmp( szDefDir, szCurDir ) != 0 )
      _chdir( szCurDir );

   /* Disable OK if directory blank
    */
   EnableControl( hwnd, IDOK, Edit_GetTextLength( GetDlgItem( hwnd, IDD_EDIT ) ) > 0 );

   /* Remember pointer to directory
    */
   SetWindowLong( hwnd, DWL_USER, lParam );
   return( TRUE );
}