win_drives.c

 #include <windows.h>
#pragma comment(lib,"ws2_32.lib")

HWND hwnd;
MSG Msg;
HWND LST;
HWND cmdAnaDrive;
HWND cmdAbout;
#define IDB_BUTTON 100
#define IDB_BUTTON1 101
#define ID_LIST1 111
#define MAX_VOLUME_SIZE 256

static void DriveType(const char *drive);

int i;
const char * drvletter[] = { "a:","b:","c:","d:","e:","f:","g:","h:","i:","j:","k:","l:",
"m:","n:","o:","p:","q:","r:","s:","t:","u:","v:","w:","x:",
"y:","z:",0 };

const char g_szClassName[] = "Class";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
cmdAnaDrive = CreateWindowEx(0,"BUTTON","Analyze Drives",WS_VISIBLE | WS_CHILD,120,20,120,20,hwnd,(HMENU) IDB_BUTTON,((LPCREATESTRUCT)lParam)->hInstance,NULL);
cmdAbout = CreateWindowEx(0, "BUTTON", "About", WS_VISIBLE | WS_CHILD,140,325,80,20,hwnd,(HMENU) IDB_BUTTON1, ((LPCREATESTRUCT)lParam)->hInstance,NULL);
LST = CreateWindowEx(WS_EX_STATICEDGE, "ListBox", NULL, WS_CHILD | LBS_STANDARD | WS_VISIBLE, 35, 60, 300, 275, hwnd,(HMENU)ID_LIST1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
break;
case WM_COMMAND:

/*** The button events ***/
switch(wParam)
{
case IDB_BUTTON: // ***cmdAnaDrive***
   {
    SendMessage(GetDlgItem(hwnd,ID_LIST1), LB_RESETCONTENT, 0, 0);
     for(i=0;drvletter[i];i++)
         {
          DriveType(drvletter[i]);
         }
   }
break;

case IDB_BUTTON1: // ***cmdAbout***
{
MessageBox(hwnd,"This program enumerates your computer's drives   \nVer 1.0\nCreated By: Elusive","   About",MB_OK | MB_ICONINFORMATION);
}
break;
}
break;

case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;

wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_INFORMATION);
wc.hIconSm = LoadIcon(NULL,IDI_INFORMATION);
wc.hInstance = hInstance;
wc.lpfnWndProc =  WndProc;
wc.lpszClassName = g_szClassName;
wc.lpszMenuName = NULL;
wc.style = 0;

   if(!RegisterClassEx(&wc))
   {
       MessageBox(NULL, "Window Registration Failed!", "Error!",
           MB_ICONEXCLAMATION | MB_OK);
       return 0;
   }

  hwnd = CreateWindowEx(
       0,
       g_szClassName,
       "Windows Drive Analyzer",
       WS_OVERLAPPED | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_BORDER,
       CW_USEDEFAULT, CW_USEDEFAULT, 375, 375,
       NULL, NULL, hInstance, NULL);

   if(hwnd == NULL)
   {
       MessageBox(NULL, "Window Creation Failed!", "Error!",
           MB_ICONEXCLAMATION | MB_OK);
       return 0;
   }

   ShowWindow(hwnd, nCmdShow);
   UpdateWindow(hwnd);

   while(GetMessage(&Msg, NULL, 0, 0) > 0)
   {
       TranslateMessage(&Msg);
       DispatchMessage(&Msg);
   }
   return Msg.wParam;
}

static void DriveType(const char *drive)
{
char str[500];
strcpy(str,"");
UINT Drv = GetDriveType(drive);
strcat(str,"  ");
strcat(str,drive);
strcat(str,"  -----  is ");
switch(Drv)
{

case DRIVE_REMOVABLE:
{
strcat(str,"a Removable Drive");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

case DRIVE_FIXED:
{
strcat(str,"a Fixed Drive");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

case DRIVE_REMOTE:
{
strcat(str,"a Network Drive");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

case DRIVE_CDROM:
{
strcat(str,"a CD-ROM Drive");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

case DRIVE_RAMDISK:
{
strcat(str,"a Ram Disk");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

case 1:
{
strcpy(str,"");
break;
}

case 0:
{
strcat(str,"Unable to determine drive type!");
SendMessage(GetDlgItem(hwnd, ID_LIST1), LB_ADDSTRING,strlen(str),(LPARAM)(LPCSTR) str);
break;
}

}

}

Project Homepage: