| Код | BOOL CALLBACK DlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) { switch(msg) { HANDLE_MSG(hWnd,WM_INITDIALOG,DlgOnInitDialog); HANDLE_MSG(hWnd,WM_COMMAND,DlgOnCommand); default:return FALSE; } return TRUE; // ! }
void DlgOnCommand(HWND hWnd,int id,HWND hWndCtrl,UINT CodeNotify) { char *pszVolume; UINT n; switch(id) { case ID_COMBO: if(CodeNotify == CBN_SELCHANGE) { // индекс обновляется раньше, чем текст в ComboBox Index = ComboBox_GetCurSel(hWndCtrl); n = ComboBox_GetLBTextLen(hWndCtrl, Index)+1; pszVolume = new char[n]; // buffer overflow protection //SendMessage(hWndCtrl, CB_GETLBTEXT,(WPARAM)Index,(LPARAM)pszVolume); ComboBox_GetLBText(hWndCtrl, Index, pszVolume); FillInfo(hWnd,pszVolume); delete []pszVolume; } break; case IDCANCEL:EndDialog(hWnd,0); } }
void FillInfo(HWND hWnd, LPSTR szVol) { char szText[80]; int nDriverType = GetDriveType(szVol);
szText[0] = 0; // если этого не сделать может возникнуть выход за пределы массива!!!
switch (nDriverType) { case DRIVE_REMOVABLE:strcpy(szText,"Съёмний диск"); break; case DRIVE_FIXED: strcpy(szText,"Жесткий диск"); break; case DRIVE_CDROM: strcpy(szText,"СД-Диск"); break; } SetWindowText(GetDlgItem(hWnd,ID_DRIVERTYPE),szText);
char szLabel[20]; char szFat[10]; char szTemp[20]; DWORD dwVolser = 0, dwMaxLen = 0, dwFlags = 0;
szLabel[0] = szFat[0] = szTemp[0] = 0;
GetVolumeInformation(szVol,szLabel,sizeof(szLabel),&dwVolser,&dwMaxLen,&dwFlags,szFat,sizeof(szFat)); strcpy(szText,szLabel); strcat(szText,"\n"); wsprintf(szTemp,"%X",dwVolser);
strcat(szText,szTemp); strcat(szText,"\n"); strcat(szText,szFat); SetWindowText(GetDlgItem(hWnd,ID_VOLINFO),szText);
DWORD dwSectorsPerCluster = 0, dwBytesPerSector = 0, dwFreeCluster = 0, dwClusters = 0; // либо проверяй, что возвращает функция GetDiskFreeSpace, либо зануляй переменные. GetDiskFreeSpace(szVol,&dwSectorsPerCluster,&dwBytesPerSector,&dwFreeCluster,&dwClusters); wsprintf(szTemp,"%d",dwBytesPerSector); strcpy(szText,szTemp); strcat(szText,"\n");
wsprintf(szTemp,"%d",dwSectorsPerCluster); strcat(szText,szTemp); strcat(szText,"\n");
wsprintf(szTemp,"%d",dwClusters); strcat(szText,szTemp); strcat(szText,"\n");
wsprintf(szTemp,"%d",dwFreeCluster); strcat(szText,szTemp); SetWindowText(GetDlgItem(hWnd,ID_DISKINFO),szText); }
|
|