Aller au contenu

[C] Fonction pour info système


HyPnOz

Messages recommandés

Voila je dois faire un petit programme pour les cours qui me récupère des informations sur le système que ca place dans un fichier log. Pour la RAM j'ai trouvé MemoryStatus mais par contre pour le disque dur je trouve pas la fonction :yes:

Je suis un peu newbie en C j'avoue :incline: Merci :incline:

Lien vers le commentaire
Partager sur d’autres sites

Pour accéder à la ressource demandée, vous devez être authentifié.
Veuillez saisir vos nom d'utilisateur et mot de passe pour accéder à cette ressource.

La culture proprio, ça me dépasse.

pareil, surtout que c'est gratuit ensuite.....

je vous mets les fichiers pour ceux qui ne veulent pas s'inscrire (désolé pour la longueur)

diskinfo.c

#define _WIN32_WINNT	  0x501

#include <windows.h>

#include <commctrl.h>

#include "resource.h"

#include <Setupapi.h>

#pragma comment(lib, "comctl32.lib")

#pragma comment(lib, "Setupapi.lib")

#define MAX_DISK 8

#define MAX_PARTITION 16

typedef struct tagPARTITION_DESCRIPTION

{

BYTE Active; // TRUE ou FALSE

BYTE Type;

BYTE Bootable;

BYTE Formatted;

BYTE Allocated;

BYTE UsagePercent;

WORD DriveLetter;

BYTE Primary;

BYTE a1;

BYTE a2;

BYTE a3;

RECT rc; // Rectangle pour tester si la souris est dessus

RECT rcPaint; // Rectangle sur le dessin

TCHAR szMBSize[16];

DWORD dwOffset;

DWORD dwLowSize; // Taille en octets sur 64 bits

DWORD dwHighSize;

DWORD dwSize; // Taille en secteurs

DWORD dwSerial;

BYTE BootSector[512];

} PARTITION_DESCRIPTION, *LPPARTITION_DESCRIPTION;

typedef struct tagDISK_DESCRIPTION

{

TCHAR FriendlyName[128];

BYTE bRemovable;

BYTE nPartitions;

BYTE ExtendedPartition;

BYTE b0;

PARTITION_DESCRIPTION ExtendedPartDescription;

TCHAR szMBSize[16];

DWORD dwSize;

DWORD dwLowSize;

DWORD dwHighSize;

DWORD dwExtendOffset;

BYTE MBR[512];

} DISK_DESCRIPTION, *LPDISK_DESCRIPTION;

typedef struct tagPARTITION_INFO

{

HBRUSH hBrush;

LPTSTR lpName;

} PARTITION_INFO, *LPPARTITION_INFO;

typedef struct tagTABLE_ENTRY

{

BYTE state;

BYTE headBegin;

WORD sectorCylinderBegin;

BYTE partitionType;

BYTE headEnd;

WORD sectorCylinderEnd;

DWORD distBetweenSectAndBootSect;

DWORD partitionSize; // En secteurs

} TABLE_ENTRY, *LPTABLE_ENTRY;

BYTE DriveBootSectors[26][512];

BOOL DriveFormatted[26];

char DriveLetters[26];

BYTE DriveUsage[26];

DWORD nDrives;

HINSTANCE g_hInst;

HWND g_hDlg;

HANDLE g_hHeap, g_hPartitionsWnd;

HICON g_hIcons[2];

HBRUSH hBrushes[10], g_hUnformatted, g_hUnallocated, g_hExtendBrush, g_hUsedBrush;

RECT rcPartitions, rcPartitions2;

HFONT hHexFont;

LPBYTE lpBootSector;

OPENFILENAME ofn;

TCHAR szFileName[MAX_PATH];

DISK_DESCRIPTION DiskDescriptions[MAX_DISK];

PARTITION_DESCRIPTION PartitionDescriptions[MAX_DISK][MAX_PARTITION];

LPPARTITION_DESCRIPTION lpPartitions[MAX_DISK][MAX_PARTITION];

PARTITION_INFO PartitionInfo[256];

int nDisks;

int g_selDisk = -1;

int g_selPart = -1;

__inline char* bnstrcpy(char *dst, char *src) // return ptr sur NULL final

{

__asm

{

mov eax, dst

mov ecx, src

dec eax

LcpyLoop:

mov dl, [ecx]

inc eax

inc ecx

mov [eax], dl

or dl, dl

jz short LcpyOut

mov dl, [ecx]

inc eax

inc ecx

mov [eax], dl

or dl, dl

jz short LcpyOut

mov dl, [ecx]

inc eax

inc ecx

mov [eax], dl

or dl, dl

jnz short LcpyLoop

LcpyOut:

}

}

__declspec(naked) char* __fastcall bnultoa(unsigned int dwnum, char* szdst)

{ // ECX = dwnum, EDX = szdst

__asm {

or ecx, ecx

jnz short L1

lea eax, [edx+1]

mov byte ptr[edx], 48

mov byte ptr[eax], cl

ret 0

L1:

mov [esp-4], edi

mov [esp-8], edx

mov edi, edx

L2:

mov eax, -858993459

mul ecx

mov eax, edx

shr eax, 3

mov edx, ecx

lea ecx, [eax+eax*8]

add ecx, eax

sub edx, ecx

add dl, 48

mov [edi], dl

mov ecx, eax

inc edi

test eax, eax

jnz short L2

mov byte ptr[edi], al

mov [esp-12], edi

mov eax, [esp-8]

L3:

dec edi

mov dl, [eax]

mov cl, [edi]

mov [edi], dl

mov [eax], cl

inc eax

cmp eax, edi

jb short L3

mov eax, [esp-12]

mov edi, [esp-4]

ret 0

}

}

__declspec(naked) BOOL __fastcall SameSector(LPBYTE lpSect1, LPBYTE lpSect2)

{ // ECX = lpSect1, EDX = lpSect2

__asm {

push ebx

mov eax, edx

mov ebx, 32

Next:

mov edx, [ecx]

cmp edx, [eax]

jne short Diff

mov edx, [ecx+4]

cmp edx, [eax+4]

jne short Diff

mov edx, [ecx+8]

cmp edx, [eax+8]

jnz short Diff

mov edx, [ecx+12]

cmp edx, [eax+12]

jne short Diff

dec ebx

jz short samExit

add ecx, 16

add eax, 16

jmp short Next

Diff:

xor eax, eax

samExit:

pop ebx

ret 0

}

}

DWORD GetPartitions(HANDLE hDevice, int nDisk, int nPartition, DWORD dwOffset)

{

int n;

char lpBuffer[512], *p, *q;

DWORD d = -1;

int i = 0;

LONG lowPart, highPart;

TABLE_ENTRY entry;

PARTITION_INFORMATION PartitionInformation;

DWORD TotalSize = 63;

BOOL b;

__asm

{

xor edx, edx

mov ecx, 512

mov eax, dwOffset

mul ecx

mov lowPart, eax

mov highPart, edx

}

lowPart = SetFilePointer(hDevice, lowPart, &highPart, FILE_BEGIN);

ReadFile(hDevice, lpBuffer, 512, &d, 0);

if(!dwOffset)

CopyMemory(DiskDescriptions[nDisk].MBR, lpBuffer, 512);

p = lpBuffer + 446;

for(n = 0; n < 4; n++)

{

CopyMemory(&entry, p, sizeof entry);

p += sizeof entry;

switch(entry.partitionType)

{

case 0: // Pas de partition

break;

case 0x5: // Partition étendue

case 0xF:

if(DiskDescriptions[nDisk].dwExtendOffset == -1)

{

DiskDescriptions[nDisk].ExtendedPartition = 1;

DiskDescriptions[nDisk].ExtendedPartDescription.Type = entry.partitionType;

DiskDescriptions[nDisk].ExtendedPartDescription.Primary = 1;

DiskDescriptions[nDisk].dwExtendOffset = entry.distBetweenSectAndBootSect;

DiskDescriptions[nDisk].ExtendedPartDescription.dwSize = entry.partitionSize;

q = bnultoa(DiskDescriptions[nDisk].ExtendedPartDescription.dwSize >> 11, DiskDescriptions[nDisk].ExtendedPartDescription.szMBSize);

*q++ = ' ';

*q++ = 'M';

*q++ = 'o';

*q++ = 0;

nPartition = GetPartitions(hDevice, nDisk, nPartition, DiskDescriptions[nDisk].dwExtendOffset);

}

else

nPartition = GetPartitions(hDevice, nDisk, nPartition, DiskDescriptions[nDisk].dwExtendOffset + entry.distBetweenSectAndBootSect);

break;

default: // Cas général

DiskDescriptions[nDisk].nPartitions++;

d = dwOffset + entry.distBetweenSectAndBootSect;

__asm

{

xor edx, edx

mov ecx, 512

mov eax, d

mul ecx

mov lowPart, eax

mov highPart, edx

}

DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO, 0, 0,

&PartitionInformation, sizeof PartitionInformation, &d, 0);

lowPart = SetFilePointer(hDevice, lowPart, &highPart, FILE_BEGIN);

ReadFile(hDevice, PartitionDescriptions[nDisk][nPartition].BootSector, 512, &d, 0);

PartitionDescriptions[nDisk][nPartition].Formatted = TRUE;

if(entry.partitionType == 0xB // Types reconnus par Windows

|| entry.partitionType == 0xC

|| entry.partitionType == 0x7

|| entry.partitionType == 0x1

|| entry.partitionType == 0x4

|| entry.partitionType == 0x6)

{

PartitionDescriptions[nDisk][nPartition].BootSector[0x41] = 1;

for(d = 0; d < nDrives; d++)

{

b = SameSector(PartitionDescriptions[nDisk][nPartition].BootSector, DriveBootSectors[d]);

if(b)

{

PartitionDescriptions[nDisk][nPartition].Formatted = DriveFormatted[d];

PartitionDescriptions[nDisk][nPartition].DriveLetter = MAKEWORD(DriveLetters[d], ':');

d = nDrives;

}

}

}

switch(entry.partitionType)

{

case 0xB:

case 0xC: // FAT32

PartitionDescriptions[nDisk][nPartition].dwSerial = *(DWORD*)(PartitionDescriptions[nDisk][nPartition].BootSector + 0x43);

break;

case 0x7: // NTFS

PartitionDescriptions[nDisk][nPartition].dwSerial = *(DWORD*)(PartitionDescriptions[nDisk][nPartition].BootSector + 0x48);

break;

case 0x1:

case 0x4:

case 0x6: // FAT16 - FAT12

PartitionDescriptions[nDisk][nPartition].dwSerial = *(DWORD*)(PartitionDescriptions[nDisk][nPartition].BootSector + 0x27);

break;

default:

PartitionDescriptions[nDisk][nPartition].dwSerial = 0;

}

if(!PartitionDescriptions[nDisk][nPartition].Formatted)

PartitionDescriptions[nDisk][nPartition].dwSerial = 0;

lpPartitions[nDisk][nPartition] = &PartitionDescriptions[nDisk][nPartition];

PartitionDescriptions[nDisk][nPartition].dwOffset = dwOffset + entry.distBetweenSectAndBootSect;

PartitionDescriptions[nDisk][nPartition].Primary = (dwOffset == 0);

PartitionDescriptions[nDisk][nPartition].Allocated = TRUE;

PartitionDescriptions[nDisk][nPartition].Bootable = TRUE;

PartitionDescriptions[nDisk][nPartition].Active = entry.state;

PartitionDescriptions[nDisk][nPartition].Type = entry.partitionType;

PartitionDescriptions[nDisk][nPartition].dwSize = entry.partitionSize;

q = bnultoa(PartitionDescriptions[nDisk][nPartition].dwSize >> 11, PartitionDescriptions[nDisk][nPartition].szMBSize);

*q++ = ' ';

*q++ = 'M';

*q++ = 'o';

*q++ = 0;

nPartition++;

}

TotalSize += entry.partitionSize;

}

return nPartition;

}

void swap(LPPARTITION_DESCRIPTION* lpPart, int i, int j)

{

LPPARTITION_DESCRIPTION temp;

temp = lpPart[i];

lpPart[i] = lpPart[j];

lpPart[j] = temp;

}

void SortPartitions(LPPARTITION_DESCRIPTION* lpPart, int left, int right)

{

int i, last;

if(left >= right)

return;

swap(lpPart, left, (left + right) / 2);

last = left;

for(i = left + 1; i <= right; i++)

if(lpPart[i]->dwOffset < lpPart[left]->dwOffset)

swap(lpPart, ++last, i);

swap(lpPart, left, last);

SortPartitions(lpPart, left, last - 1);

SortPartitions(lpPart, last + 1, right);

}

void LookForFreeSpace(int nDisk)

{

LPPARTITION_DESCRIPTION* lpPart = lpPartitions[nDisk];

int nPartitions = DiskDescriptions[nDisk].nPartitions;

int n = 0, i = 0, j;

char* p;

DWORD dwOffset = lpPart[0]->dwOffset;

next:

dwOffset += lpPart[i]->dwSize + 63;

i++;

if(i != nPartitions)

{

if(lpPart[i]->dwOffset != dwOffset)

{ // Espace Libre, ajouter partition non allouée

PartitionDescriptions[nDisk][nPartitions].Allocated = FALSE;

PartitionDescriptions[nDisk][nPartitions].Primary = TRUE;

PartitionDescriptions[nDisk][nPartitions].dwSize = lpPart[i]->dwOffset - dwOffset;

p = bnultoa((lpPart[i]->dwOffset - dwOffset) >> 11, PartitionDescriptions[nDisk][nPartitions].szMBSize);

*p++ = ' ';

*p++ = 'M';

*p++ = 'o';

*p++ = 0;

for(j = nPartitions; j > i; j--)

lpPartitions[nDisk][j] = lpPartitions[nDisk][j - 1];

lpPartitions[nDisk][i] = &PartitionDescriptions[nDisk][nPartitions];

nPartitions++;

i++;

dwOffset = lpPart[i]->dwOffset;

}

goto next;

}

DiskDescriptions[nDisk].nPartitions = nPartitions;

}

BOOL PhysicalDiskInfo(HANDLE hDevice, int nDisk)

{

DWORD d = -1;

DISK_GEOMETRY_EX DiskGeometry;

char* p;

int x, cx, cy, nPartition, widthLeft, sizeLeft;

int width[MAX_PARTITION];

DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &DiskGeometry,

sizeof DiskGeometry, &d, 0);

DiskDescriptions[nDisk].bRemovable = (DiskGeometry.Geometry.MediaType == RemovableMedia);

DiskDescriptions[nDisk].dwHighSize = DiskGeometry.DiskSize.HighPart;

DiskDescriptions[nDisk].dwLowSize = DiskGeometry.DiskSize.LowPart;

DiskDescriptions[nDisk].dwExtendOffset = -1;

DiskDescriptions[nDisk].dwSize = (DiskGeometry.DiskSize.LowPart >> 9) | (DiskGeometry.DiskSize.HighPart << 23);

p = bnultoa(DiskDescriptions[nDisk].dwSize >> 11, DiskDescriptions[nDisk].szMBSize);

*p++ = ' ';

*p++ = 'M';

*p++ = 'o';

*p++ = 0;

GetPartitions(hDevice, nDisk, 0, 0);

SortPartitions(lpPartitions[nDisk], 0, DiskDescriptions[nDisk].nPartitions - 1);

LookForFreeSpace(nDisk);

x = 0;

cx = rcPartitions.right - rcPartitions.left;

cy = rcPartitions.bottom - rcPartitions.top;

widthLeft = cx; // Il reste tout

sizeLeft = 0;

// 1ère passe: calcule somme des tailles des partitions (pas exactement celle du disque!)

for(nPartition = 0; nPartition < DiskDescriptions[nDisk].nPartitions; nPartition++)

sizeLeft += lpPartitions[nDisk][nPartition]->dwSize >> 11;

// 2ème passe

// Les partitions qui font moins de 1 pixel sont mis a 5 pour qu'on les voit

// L'espace restant est partagé proportionnellement entre les partitions restantes

for(nPartition = 0; nPartition < DiskDescriptions[nDisk].nPartitions; nPartition++)

{

x = (cx * (lpPartitions[nDisk][nPartition]->dwSize >> 10)) / (DiskDescriptions[nDisk].dwSize >> 10);

if(lpPartitions[nDisk][nPartition]->DriveLetter && x <= 20)

{

width[nPartition] = 18;

sizeLeft -= lpPartitions[nDisk][nPartition]->dwSize >> 11;

widthLeft -= 18;

}

else if(x <= 10)

{

width[nPartition] = 10;

sizeLeft -= lpPartitions[nDisk][nPartition]->dwSize >> 11;

widthLeft -= 10;

}

else

width[nPartition] = -1; // Recalculer après

}

#define SEP 2

widthLeft -= SEP * (DiskDescriptions[nDisk].nPartitions - 1) + 2;

if(DiskDescriptions[nDisk].ExtendedPartition)

widthLeft -= 8; // 4 à gauche et 4 à droite

x = 0;

// 3ème passe: calcul pour les 'grosses' partitions

for(nPartition = 0; nPartition < DiskDescriptions[nDisk].nPartitions; nPartition++)

{

if(width[nPartition] == -1)

{ // Taille == 5

width[nPartition] = widthLeft * (lpPartitions[nDisk][nPartition]->dwSize >> 11) / sizeLeft;

sizeLeft -= lpPartitions[nDisk][nPartition]->dwSize >> 11;

widthLeft -= width[nPartition];

}

}

// 4ème passe: calcul des rectangles

x = 1;

sizeLeft = 1; // Primary

for(nPartition = 0; nPartition < DiskDescriptions[nDisk].nPartitions; nPartition++)

{

if(sizeLeft && !lpPartitions[nDisk][nPartition]->Primary) // 1ère part. logique

{

DiskDescriptions[nDisk].ExtendedPartDescription.rcPaint.left = x;

DiskDescriptions[nDisk].ExtendedPartDescription.rcPaint.top = 0;

DiskDescriptions[nDisk].ExtendedPartDescription.rcPaint.bottom = cy;

DiskDescriptions[nDisk].ExtendedPartDescription.rc.left = rcPartitions.left + x;

DiskDescriptions[nDisk].ExtendedPartDescription.rc.top = rcPartitions.top;

DiskDescriptions[nDisk].ExtendedPartDescription.rc.bottom = rcPartitions.bottom;

rcPartitions.top += 3;

rcPartitions.bottom -= 3;

x += 4;

sizeLeft = 0;

}

if(!sizeLeft && lpPartitions[nDisk][nPartition]->Primary) // après dernière part. logique

{

rcPartitions.top -= 3;

rcPartitions.bottom += 3;

DiskDescriptions[nDisk].ExtendedPartDescription.rcPaint.right = x + 4 - SEP;

DiskDescriptions[nDisk].ExtendedPartDescription.rc.right = rcPartitions.left + x + 4 - SEP;

x += 4;

sizeLeft = 1;

}

if(lpPartitions[nDisk][nPartition]->Primary)

{

lpPartitions[nDisk][nPartition]->rcPaint.left = x;

lpPartitions[nDisk][nPartition]->rcPaint.right = x + width[nPartition];

lpPartitions[nDisk][nPartition]->rcPaint.top = 0;

lpPartitions[nDisk][nPartition]->rcPaint.bottom = cy;

}

else

{

lpPartitions[nDisk][nPartition]->rcPaint.left = x;

lpPartitions[nDisk][nPartition]->rcPaint.right = x + width[nPartition];

lpPartitions[nDisk][nPartition]->rcPaint.top = 3;

lpPartitions[nDisk][nPartition]->rcPaint.bottom = cy - 3;

}

lpPartitions[nDisk][nPartition]->rc.left = rcPartitions.left + x;

lpPartitions[nDisk][nPartition]->rc.right = rcPartitions.left + x + width[nPartition];

lpPartitions[nDisk][nPartition]->rc.top = rcPartitions.top;

lpPartitions[nDisk][nPartition]->rc.bottom = rcPartitions.bottom;

x += width[nPartition] + SEP;

}

if(!sizeLeft && !lpPartitions[nDisk][nPartition - 1]->Primary) //dernière partition est logique

{

DiskDescriptions[nDisk].ExtendedPartDescription.rcPaint.right = x + 4 - SEP;

DiskDescriptions[nDisk].ExtendedPartDescription.rc.right = rcPartitions.left + x + 4 - SEP;

}

return TRUE;

}

void GetLogicalDrivesBootSectors()

{

DWORD dwDrives = GetLogicalDrives();

char szDrive[] = "\\\\.\\A:";

DWORD dwDrive = '\\:A';

HANDLE hFile;

DWORD dwRead;

ULARGE_INTEGER TotalNumberOfFreeBytes, TotalNumberOfBytes;

nDrives = 0;

while(dwDrives)

{

dwRead = GetDriveType((char*)&dwDrive);

if((dwDrives & 1) && (dwRead == DRIVE_REMOVABLE || dwRead == DRIVE_FIXED))

{

if(!GetDiskFreeSpaceEx((char*)&dwDrive, 0, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))

DriveFormatted[nDrives] = FALSE;

else

{

DriveUsage[nDrives] = 100 - (BYTE)((100 * TotalNumberOfFreeBytes.QuadPart) / TotalNumberOfBytes.QuadPart);

DriveFormatted[nDrives] = TRUE;

}

hFile = CreateFile(szDrive, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

0, OPEN_EXISTING, 0, NULL);

ReadFile(hFile, DriveBootSectors[nDrives], 512, &dwRead, 0);

DriveBootSectors[nDrives][0x41] = 1;

CloseHandle(hFile);

DriveLetters[nDrives] = szDrive[4];

nDrives++;

}

szDrive[4]++;

(*(LPBYTE*)&dwDrive)++;

dwDrives >>= 1;

}

}

void FillListBox(HWND hLBWnd)

{

HDEVINFO DeviceInfoSet;

SP_DEVICE_INTERFACE_DATA DeviceInterfaceData = {sizeof DeviceInterfaceData};

PSP_DEVICE_INTERFACE_DETAIL_DATA lpDeviceInterfaceDetailData;

SP_DEVINFO_DATA DeviceInfoData = {sizeof DeviceInfoData};

HANDLE hFile;

int i = 0;

DWORD d;

BOOL b;

GetLogicalDrivesBootSectors();

DeviceInfoSet = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK,

NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

do

{

b = SetupDiEnumDeviceInterfaces(DeviceInfoSet, 0, &GUID_DEVINTERFACE_DISK,

i, &DeviceInterfaceData);

if(b)

{

SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, NULL, 0,

&d, &DeviceInfoData);

lpDeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapAlloc(g_hHeap, HEAP_ZERO_MEMORY, d);

lpDeviceInterfaceDetailData->cbSize = sizeof *lpDeviceInterfaceDetailData;

b = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData,

lpDeviceInterfaceDetailData, d, &d, &DeviceInfoData);

SetupDiGetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData, SPDRP_FRIENDLYNAME,

NULL, (PBYTE)DiskDescriptions[i].FriendlyName, 244, &d);

hFile = CreateFile(lpDeviceInterfaceDetailData->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

0, OPEN_EXISTING, 0, NULL);

HeapFree(g_hHeap, 0, lpDeviceInterfaceDetailData);

PhysicalDiskInfo(hFile, i);

CloseHandle(hFile);

SendMessage(hLBWnd, LB_INSERTSTRING, -1, (LPARAM)DiskDescriptions[i].FriendlyName);

}

i++;

} while(GetLastError() != ERROR_NO_MORE_ITEMS);

nDisks = i - 1;

}

void OnDrawItem(LPDRAWITEMSTRUCT lpdis)

{

char szDriveName[100], *p;

HBITMAP hbmp;

HDC hdc;

int nPartition;

HBRUSH* lpBrush = NULL;

hdc = CreateCompatibleDC(lpdis->hDC);

hbmp = CreateCompatibleBitmap(lpdis->hDC, lpdis->rcItem.right,

lpdis->rcItem.bottom);

SelectObject(hdc, hbmp);

SetBkMode(hdc, TRANSPARENT);

switch(lpdis->CtlID)

{

case IDC_DISKLIST:

SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));

if(lpdis->itemState & ODS_SELECTED)

{

FillRect(hdc, &lpdis->rcItem, hBrushes[1]);

lpdis->rcItem.bottom--;

lpdis->rcItem.left++;

lpdis->rcItem.right--;

lpdis->rcItem.top++;

FillRect(hdc, &lpdis->rcItem, hBrushes[0]);

lpdis->rcItem.bottom++;

lpdis->rcItem.left--;

lpdis->rcItem.right++;

lpdis->rcItem.top--;

}

else

FillRect(hdc, &lpdis->rcItem, GetStockObject(WHITE_BRUSH));

if(DiskDescriptions[lpdis->itemID].bRemovable)

DrawIcon(hdc, lpdis->rcItem.left + 10, lpdis->rcItem.top + 10, g_hIcons[0]);

else

DrawIcon(hdc, lpdis->rcItem.left + 10, lpdis->rcItem.top + 10, g_hIcons[1]);

SetTextColor(lpdis->hDC, 0);

SelectObject(lpdis->hDC, GetStockObject(DEFAULT_GUI_FONT));

lpdis->rcItem.left += 60;

p = szDriveName;

*(DWORD*)p = 'qsiD';

p += 4;

*(DWORD*)p = 'n eu';

p += 4;

*p++ = '°';

*p++ = ' ';

p = bnultoa(lpdis->itemID + 1, p);

*p++ = ' ';

*p++ = '-';

*p++ = ' ';

p = bnstrcpy(p, DiskDescriptions[lpdis->itemID].FriendlyName);

*p++ = ' ';

*p++ = '(';

p = bnultoa(DiskDescriptions[lpdis->itemID].dwSize >> 11, p);

*p++ = ' ';

*p++ = 'M';

*p++ = 'o';

*p++ = ')';

*p++ = ' ';

DrawText(hdc, szDriveName, p - szDriveName, &lpdis->rcItem, DT_VCENTER | DT_SINGLELINE);

lpdis->rcItem.left -= 60;

lpdis->rcItem.bottom += 100;

break;

case IDC_PARTITIONS: // Dessin des partitions

FillRect(hdc, &rcPartitions2, GetSysColorBrush(COLOR_3DLIGHT));

if(g_selDisk != -1)

{

if(DiskDescriptions[g_selDisk].ExtendedPartition)

{

FillRect(hdc, &DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, GetStockObject(LTGRAY_BRUSH));

InflateRect(&DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, -1, -1);

FillRect(hdc, &DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, g_hExtendBrush);

InflateRect(&DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, 1, 1);

if(g_selPart == DiskDescriptions[g_selDisk].nPartitions)

{ // Partition étendue est séléctionnée

FrameRect(hdc, &DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint,

GetStockObject(BLACK_BRUSH));

InflateRect(&DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, -1, -1);

FrameRect(hdc, &DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint,

GetStockObject(BLACK_BRUSH));

InflateRect(&DiskDescriptions[g_selDisk].ExtendedPartDescription.rcPaint, 1, 1);

}

}

for(nPartition = 0; nPartition < DiskDescriptions[g_selDisk].nPartitions; nPartition++)

{

if(!lpPartitions[g_selDisk][nPartition]->Allocated)

lpBrush = &g_hUnallocated;

else if(!lpPartitions[g_selDisk][nPartition]->Formatted)

lpBrush = &g_hUnformatted;

else

lpBrush = &PartitionInfo[lpPartitions[g_selDisk][nPartition]->Type].hBrush;

FillRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint, GetStockObject(LTGRAY_BRUSH));

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, -1, -1);

FillRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint, *lpBrush);

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, -2, -4);

FillRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint, GetStockObject(LTGRAY_BRUSH));

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, -1, -1);

FillRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint,

GetStockObject(WHITE_BRUSH));

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, 3, 5);

if(nPartition == g_selPart)

{

FrameRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint,

GetStockObject(BLACK_BRUSH));

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, 1, 1);

FrameRect(hdc, &lpPartitions[g_selDisk][nPartition]->rcPaint,

GetStockObject(BLACK_BRUSH));

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, -1, -1);

}

InflateRect(&lpPartitions[g_selDisk][nPartition]->rcPaint, 1, 1);

if(lpPartitions[g_selDisk][nPartition]->DriveLetter)

DrawText(hdc, (char*)&lpPartitions[g_selDisk][nPartition]->DriveLetter,

2, &lpPartitions[g_selDisk][nPartition]->rcPaint, DT_CENTER | DT_SINGLELINE | DT_VCENTER);

}

}

break;

}

BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,

lpdis->rcItem.right - lpdis->rcItem.left,

lpdis->rcItem.bottom - lpdis->rcItem.top,

hdc, lpdis->rcItem.left, lpdis->rcItem.top, SRCCOPY);

DeleteObject(hbmp);

DeleteDC(hdc);

}

void Copy(HWND hWnd, LPVOID lParam, int nLength)

{

HGLOBAL hglbCopy;

LPTSTR lptstrCopy;

hglbCopy = GlobalAlloc(GHND, 512);

lptstrCopy = GlobalLock(hglbCopy);

CopyMemory(lptstrCopy, lParam, nLength);

GlobalUnlock(hglbCopy);

OpenClipboard(hWnd);

EmptyClipboard();

SetClipboardData(CF_TEXT, hglbCopy);

CloseClipboard();

}

void OnSaveAs(HWND hWnd)

{

HANDLE hFile;

DWORD d;

ofn.Flags = OFN_OVERWRITEPROMPT | OFN_SHAREAWARE;

if(GetSaveFileName(&ofn))

{

hFile = CreateFile(ofn.lpstrFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);

if(hFile == INVALID_HANDLE_VALUE)

MessageBox(hWnd, "Impossible de créer le fichier.", 0, MB_ICONHAND);

else

{

WriteFile(hFile, lpBootSector, 512, &d, 0);

if(d != 512)

MessageBox(hWnd, "Erreur lors de l'écriture.", 0, MB_ICONHAND);

CloseHandle(hFile);

}

}

}

void Init(HWND hWnd, BOOL bPartition)

{

TCHAR szTitle[64], *p = szTitle;

if(bPartition)

{

*(DWORD*)p = 'tceS';

p += 4;

*(DWORD*)p = ' rue';

p += 4;

*(DWORD*)p = 'b ed';

p += 4;

*(DWORD*)p = ' too';

p += 4;

*(DWORD*)p = 'iD -';

p += 4;

*(DWORD*)p = 'euqs';

p += 4;

*(DWORD*)p = '°n ';

p += 3;

p = bnultoa(g_selDisk + 1, p);

p = bnstrcpy(p, ", Partition n°");

p = bnultoa(g_selPart + 1, p);

}

else

{

*(DWORD*)p = 'tsaM';

p += 4;

*(DWORD*)p = 'b re';

p += 4;

*(DWORD*)p = ' too';

p += 4;

*(DWORD*)p = 'ocer';

p += 4;

*(DWORD*)p = '- dr';

p += 4;

*(DWORD*)p = 'siD ';

p += 4;

*(DWORD*)p = ' euq';

p += 4;

*(DWORD*)p = '°n';

p += 2;

p = bnultoa(g_selDisk + 1, p);

}

SetWindowText(hWnd, szTitle);

}

INT_PTR CALLBACK BootSectDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

int i, j;

BYTE szLine[128], *p, *q;

LPDRAWITEMSTRUCT lpdis;

switch(uMsg)

{

case WM_INITDIALOG:

Init(hDlg, (BOOL)lParam);

break;

case WM_DRAWITEM:

lpdis = (LPDRAWITEMSTRUCT)lParam;

SetBkMode(lpdis->hDC, TRANSPARENT);

FillRect(lpdis->hDC, &lpdis->rcItem, GetStockObject(WHITE_BRUSH));

SelectObject(lpdis->hDC, hHexFont);

for(i = 0; i < 32; i++)

{

i <<= 4;

p = lpBootSector + i;

q = szLine;

*(DWORD*)q = '0000';

q += 4;

*q++ = '0';

*q = (BYTE)(i >> 8) & 0xF;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*q = (BYTE)(i >> 4) & 0xF;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*q = (BYTE)i & 0xF;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*(DWORD*)q = ' ';

q += 4;

i >>= 4;

j = 0;

while(j < 8)

{

*q = (p[j] & 0xF0) >> 4;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*q = p[j] & 0x0F;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*q++ = ' ';

j++;

}

while(j < 16)

{

*q++ = ' ';

*q = (p[j] & 0xF0) >> 4;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

*q = p[j] & 0x0F;

if(*q > 9)

*q += 'A' - 10;

else

*q += '0';

q++;

j++;

}

*(DWORD*)q = ' ';

q += 4;

for(j = 0; j < 16; j++)

if(!IsCharAlphaNumeric(p[j]))

*q++ = '.';

else

*q++ = p[j];

TextOut(lpdis->hDC, 2, i * 13 + 2, szLine, q - szLine);

}

return 1;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDC_SAVEAS:

OnSaveAs(hDlg);

break;

case IDC_COPY:

Copy(hDlg, lpBootSector, 512);

break;

case IDCANCEL:

EndDialog(hDlg, 0);

break;

}

break;

}

return FALSE;

}

void OnLButtonDown(HWND hDlg, LPPOINT lpPoint)

{

int nPartition;

char s[64], *p;

DWORD d;

g_selPart = -1;

if(PtInRect(&rcPartitions, *lpPoint))

{

for(nPartition = 0; nPartition < DiskDescriptions[g_selDisk].nPartitions; nPartition++)

{

if(PtInRect(&lpPartitions[g_selDisk][nPartition]->rc, *lpPoint))

{

g_selPart = nPartition;

if(lpPartitions[g_selDisk][nPartition]->dwSerial)

{

d = lpPartitions[g_selDisk][nPartition]->dwSerial;

p = s;

*p = (BYTE)(d >> 28) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p = (BYTE)(d >> 24) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p = (BYTE)(d >> 20) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p = (BYTE)(d >> 16) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p++ = '-';

*p = (BYTE)(d >> 12) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p = (BYTE)(d >> 8) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

*p += '0';

p++;

*p = (BYTE)(d >> 4) & 0xF;

if(*p >= 10)

*p += 'A' - 10;

else

 &

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...