Exemple #1
0
static void fillComboBox(HWND hWnd) 
{
  HWND hWndCB = GetDlgItem(hWnd, ID_COMBO_DIR);
  HWND hWndTempLB = GetDlgItem(hWnd, ID_LISTTEMP_DIR);
  if(hWndCB == NULL)
    return;
  ComboBox_ResetContent(hWndCB);
  ListBox_ResetContent(hWndTempLB);
  ListBox_Dir(hWndTempLB, DDL_DRIVES|DDL_EXCLUSIVE, (LPSTR)"*");

  int iDriveCount = ListBox_GetCount(hWndTempLB);
  int iCurDrive=_getdrive() - 1;

  char szDrive[16];
  char szItem[80];

  for (int i = 0; i < iDriveCount;  i++) 
  {
    ListBox_GetText(hWndTempLB, i, szDrive);
    CharLower(szDrive);
    int iDrive = szDrive[2] - 'a';
    char szRoot[16];
    sprintf(szRoot, "%c:\\", szDrive[2]);

    int iType = DriveType(iDrive);

    if(iType < 2)
      continue;

    //Start the item string with the drive letter, colon, and two spaces
    sprintf(szItem, "%c%s", szDrive[2], ": ");

    if((iType == DRIVE_FIXED) || (iType == DRIVE_RAMDISK)) 
    { // get volume ID
      char szVolumeID[80];
      DWORD dwMaxLength;
      DWORD dwSysFlags;
      GetVolumeInformation(szRoot,             // address of root directory of the file system 
                           szVolumeID,         // address of name of the volume 
                           sizeof(szVolumeID), // length of lpVolumeNameBuffer 
                           NULL,               // address of volume serial number 
                           &dwMaxLength,       // address of system's maximum filename length
                           &dwSysFlags,        // address of file system flags 
                           NULL,               // address of name of file system 
                           NULL);              // length of lpFileSystemNameBuffer 

      CharLower(szVolumeID);
      lstrcat(szItem, szVolumeID);
    }

    //For network drives, go grab the \\server\share for it.
    if(DRIVE_REMOTE == iType) 
    {
      char szNet[64];
      szNet[0] = '\0';
      DWORD dwSizeOfszNet = sizeof(szNet);

      sprintf(szDrive, "%c:", szDrive[2]);
      CharUpper(szDrive);
      WNetGetConnection(szDrive, szNet, &dwSizeOfszNet);
      CharLower(szNet);
      lstrcat(szItem, szNet);
    }

    int index = ComboBox_AddString(hWndCB, szItem);
    ComboBox_SetItemData(hWndCB, index, MAKELONG(iDrive, iType));
    if(iDrive == iCurDrive)
      ComboBox_SetCurSel(hWndCB, index);
    if(szUNCRoot[0] != '\0')
      ComboBox_SetCurSel(hWndCB, -1);
  }
}
Exemple #2
0
/* Resets and fills the given combobox with a list of current
 * drives.  The type of drive is stored with the item data.
 */
void FASTCALL DriveListInitialize(HWND hList, HWND hTempList, UINT iCurDrive )
{
   UINT i, iItem;
   UINT cch;
   UINT cItems;
   UINT iDrive, iType;
   char szDrive[ 10 ];
   char szNet[ 64 ];
   char szItem[ 68 ];

   if( NULL == hList )
      return;

   /* Clear out all the lists. */
   ComboBox_ResetContent( hList );
   ListBox_ResetContent( hTempList );

   /* Get available drive letters in the temp list */
   ListBox_Dir( hTempList, DDL_DRIVES | DDL_EXCLUSIVE, "*" );
   iCurDrive -= 1;       /* Fix for zero-based drive indexing */

   /* Walk through the list of drives, parsing off the "[-" and "-]"
    * For each drive letter parsed, add a string to the combobox
    * composed of the drive letter and the volume label.  We then
    * determine the drive type and add that information as the item data.
    */
   cItems = ListBox_GetCount( hTempList );
   for( i = 0; i < cItems; i++ )
      {
      ListBox_GetText( hTempList, i, szDrive );

      /* Ensure lowercase drive letters */
      AnsiLower(szDrive);
      iDrive = szDrive[ 2 ] - 'a';
      iType = AmDriveType( szDrive );        /* See Below */
      if( iType < 2 )                  /* Skip non-existent drive B's */
         continue;

      /* Start the item string with the drive letter, color, and two spaces */
      wsprintf( szItem, "%c%s", szDrive[ 2 ], (LPSTR)":  " );

      /* For fixed or ram disks, append the volume label which we find
       * using _dos_findfirst and attribute _A_VOLID.
       */
      if( DRIVE_FIXED == iType || DRIVE_RAMDISK == iType )
         {
      #ifdef WIN32
         wsprintf( szDrive, "%c:\\", szDrive[ 2 ] );
         GetVolumeInformation( szDrive, szItem + strlen( szItem ), 20, NULL, NULL, NULL, NULL, 0 );
      #else
         FINDDATA fi;
         HFIND hFind;
         char ch;

         wsprintf( szDrive, "%c:\\*.*", szDrive[ 2 ] );
         if( ( hFind = Amuser_FindFirst( szDrive, _A_VOLID, &fi ) ) != -1 )
            {
            /* Convert volume to lowercase and strip any '.' in the name. */
            AnsiLower( fi.name );

            /* If a period exists, it has to be in position 8, so clear it. */
            ch = fi.name[ 8 ];
            fi.name[ 8 ] = 0;
            strcat( szItem, fi.name );

            /* If we did have a broken volume name, append the last 3 chars */
            if( '.' == ch )
               strcat( szItem, &fi.name[ 9 ] );
            }
         Amuser_FindClose( hFind );
      #endif
         }

      /* For network drives, go grab the \\server\share for it. */
      if( DRIVE_REMOTE == iType )
         {
         szNet[ 0 ] = 0;
         cch = sizeof( szNet );

         wsprintf( szDrive, "%c:", szDrive[ 2 ] );
         AnsiUpper(szDrive);

//       if( WNetGetConnection( (LPSTR)szDrive, (LPSTR)szNet, &cch ) == NO_ERROR )
//          {
//          AnsiLower(szNet);
//          strcat( szItem, szNet );
//          }
         }
      iItem = ComboBox_AddString( hList, szItem );
      ComboBox_SetItemData( hList, iItem, MAKELONG( iDrive, iType ) );
      if( iDrive == iCurDrive )
         ComboBox_SetCurSel( hList, iItem );
      }
}