开发者

How to set last Unused drive letter to Combobox in MFC (VC++)?

开发者 https://www.devze.com 2023-01-25 21:23 出处:网络
How to set last Unused drive letter to Combobox in MFC (VC++) ? My code is like this : TCHAR g_szDrvMsg[] = _T(\"A:\\n\");

How to set last Unused drive letter to Combobox in MFC (VC++) ? My code is like this :

TCHAR g_szDrvMsg[] = _T("A:\n"); 

int main(int argc, char* argv[]) {
   ULONG uDriveMask = _getdrives(); 



 if (uDriveMask == 0)
   {
      printf( "_getdrives() failed with failure code: %d\n",
              GetLastError()); //So GetLastError retuns a sring or char*?
开发者_运维技巧   }
   else
   {
      printf("The following logical drives are being used:\n");


  while (uDriveMask) {
     if (!(uDriveMask & 1))
         m_objCmbdrive.AddString(g_szDrvMsg);

     ++g_szDrvMsg[0];
     uDriveMask >>= 1;




  }

} }

m_objCmbdrive.SetCurSel(); 

What value i should pass to SetCurSel to set Drive letter in descending order.

This code gives me Drive All drive letters which are being used in the system. how to get all unused one out ?


To select the last item in your combobox, you can do:

m_objCmbdrive.SetCurSel(m_objCmbdrive.GetCount() - 1);

To fill your combobox with unused drive letters in descending order, use the InsertString() method:

for (int i = 0; i < 26; ++i) {
    if (!(uDriveMask & 1)) {
        m_objCmbdrive.InsertString(0, g_szDrvMsg);
    }
    ++g_szDrvMsg[0];
    uDriveMask >>= 1;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消