Значит хочу написать утилитку которая выводит информацию о диске, да только нифига не получается. Пример взят из книги Румянцева "Работа с файлами в Win32 API".
Использовал Visual Studio 2005
Вот исходник:
[more]
Вайл resource.h
-------------------------------------------
#define DiskMenu 101
#define IDM_EXIT 102
----------------------------------------------
InfoDisks.cpp
---------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
typedef struct _FLAGDISK
{
DWORD dwFlag;
char* cDisk;
}
FLAGDISK;
FLAGDISK FlagDisk[26]={0x1,"A:\\",
0x2, "B:\\",
0x4, "C:\\",
0x8, "D:\\",
0x10, "E:\\",
0x20, "F:\\",
0x40, "G:\\",
0x80, "H:\\",
0x100, "I:\\",
0x200, "J:\\",
0x400, "K:\\",
0x800, "L:\\",
0x1000, "M:\\",
0x2000, "N:\\",
0x4000, "O:\\",
0x8000, "P:\\",
0x10000, "Q:\\",
0x20000, "R:\\",
0x40000, "S:\\",
0x80000, "T:\\",
0x100000, "U:\\",
0x200000, "V:\\",
0x400000, "W:\\",
0x800000, "X:\\",
0x1000000, "Y:\\",
0x2000000, "Z:\\"};
long WINAPI DisksWndProc(HWND,UINT,UINT,LONG);
void ViewDiskInfo(WORD);
int APIENTRY WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
WNDCLASS WndClass;
MSG Msg;
hInst = hInstance;
/*Register our window class */
/*Fill WNDCLASS structure */
WndClass.style = CS_HREDRAW | CS_VREDRAW ;
WndClass.lpfnWndProc = (WNDPROC) DisksWndProc;
WndClass.cbClsExtra = 0 ;
WndClass.cbWndExtra = 0 ;
WndClass.hInstance = hInstance ;
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
WndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
WndClass.lpszMenuName = "DiskMenu";
WndClass.lpszClassName = "Disks";
if (!RegisterClass(&WndClass))
{
MessageBox(NULL,"Cannont register class","Error",MB_OK);
return 0;
}
hWnd = CreateWindow("Disks","Viewer of disks",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL,
hInstance, NULL);
if(!hWnd)
{
MessageBox(NULL,"Cannont create window","Error",MB_OK);
return 0;
}
// Show our Window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Begine of message cycle
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
long WINAPI DisksWndProc (HWND hWnd,UINT Message,UINT wParam, LONG IParam)
{
DWORD dwDisks;
int i,j;
switch (Message)
{
case WM_CREATE:
dwDisks = GetLogicalDrives();
// Теперь проверяем возвращенное функцией значение.
// В случае нахождения диска его букву добавляем в меню.
j=0;
for (i=0; i<26; i++)
{
if (dwDisks & FlagDisk[i].dwFlag)
{
// Необходимо добавить все найденные диски в меню
InsertMenu(GetSubMenu(GetMenu(hWnd),0),j,
MF_STRING | MF_BYPOSITION, IDM_EXIT + i + 1,
FlagDisk[i].cDisk);
j++;
}
}
return DefWindowProc(hWnd,Message,wParam, IParam);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_EXIT + 1:
case IDM_EXIT + 2:
case IDM_EXIT + 3:
case IDM_EXIT + 4:
case IDM_EXIT + 5:
case IDM_EXIT + 6:
case IDM_EXIT + 7:
case IDM_EXIT + 8:
case IDM_EXIT + 9:
case IDM_EXIT + 10:
case IDM_EXIT + 11:
case IDM_EXIT + 12:
case IDM_EXIT + 13:
case IDM_EXIT + 14:
case IDM_EXIT + 15:
case IDM_EXIT + 16:
case IDM_EXIT + 17:
case IDM_EXIT + 18:
case IDM_EXIT + 19:
case IDM_EXIT + 20:
case IDM_EXIT + 21:
case IDM_EXIT + 22:
case IDM_EXIT + 23:
case IDM_EXIT + 24:
case IDM_EXIT + 25:
case IDM_EXIT + 26:
ViewDiskInfo(LOWORD(wParam)- IDM_EXIT - 1);
return 0;
case IDM_EXIT:
SendMessage(hWnd, WM_DESTROY, 0,0);
default:
return DefWindowProc(hWnd,Message,wParam,IParam);
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,Message,wParam,IParam);
}
}
void ViewDiskInfo(WORD wld)
{
char cBuffer[0x400];
char cVolumeNameBuffer[0x80];
//DWORD dwVolumeNameSize;
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD dwFileSystemFlags;
char cFileSystemNameBuffer[0x80];
//DWORD dwFileSystemNameSize;
DWORD dwSelectorsPerCluster;
DWORD dwBytesPerSector;
DWORD dwNumberOfFreeClusters;
DWORD dwTotalNumberOfClusters;
if(GetVolumeInformation(FlagDisk[wld].cDisk, cVolumeNameBuffer, 0x80,
&dwVolumeSerialNumber,
&dwMaximumComponentLength,
&dwFileSystemFlags,
cFileSystemNameBuffer, 0x80))
{
GetDiskFreeSpace(FlagDisk[wld].cDisk,&dwSelectorsPerCluster,
&dwBytesPerSector,
&dwNumberOfFreeClusters,
&dwTotalNumberOfClusters);
sprintf_s(cBuffer,"Drive - %03s\n Volume name - %s\n\
Volume serial number - %08x\n\
Maximum component lenth - %08x\n\
File system flags - %08x\n\
File system name - %s\n\n\
Sectors per cluster - %08x\n\
Bytes per sector - %08x\n\
Number of free clusters - %08x\n\
Total number of clusters -%08x",
FlagDisk[wld].cDisk, cVolumeNameBuffer, dwVolumeSerialNumber,
dwMaximumComponentLength, dwFileSystemFlags,
cFileSystemNameBuffer, dwSelectorsPerCluster, dwBytesPerSector,
dwNumberOfFreeClusters, dwTotalNumberOfClusters);
MessageBox(NULL,cBuffer,"Drive info",MB_OK);
}
else
MessageBox(NULL,"May be, there is not diskette or CD in this drive", "Error",MB_OK);
}
-----------------------------------------------------------------
[/more]
Все компилится все класно только вот выводится пустое белое окно и все.
Помогите пожалуйста... Где я натупил...???
Использовал Visual Studio 2005
Вот исходник:
[more]
Вайл resource.h
-------------------------------------------
#define DiskMenu 101
#define IDM_EXIT 102
----------------------------------------------
InfoDisks.cpp
---------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
typedef struct _FLAGDISK
{
DWORD dwFlag;
char* cDisk;
}
FLAGDISK;
FLAGDISK FlagDisk[26]={0x1,"A:\\",
0x2, "B:\\",
0x4, "C:\\",
0x8, "D:\\",
0x10, "E:\\",
0x20, "F:\\",
0x40, "G:\\",
0x80, "H:\\",
0x100, "I:\\",
0x200, "J:\\",
0x400, "K:\\",
0x800, "L:\\",
0x1000, "M:\\",
0x2000, "N:\\",
0x4000, "O:\\",
0x8000, "P:\\",
0x10000, "Q:\\",
0x20000, "R:\\",
0x40000, "S:\\",
0x80000, "T:\\",
0x100000, "U:\\",
0x200000, "V:\\",
0x400000, "W:\\",
0x800000, "X:\\",
0x1000000, "Y:\\",
0x2000000, "Z:\\"};
long WINAPI DisksWndProc(HWND,UINT,UINT,LONG);
void ViewDiskInfo(WORD);
int APIENTRY WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
WNDCLASS WndClass;
MSG Msg;
hInst = hInstance;
/*Register our window class */
/*Fill WNDCLASS structure */
WndClass.style = CS_HREDRAW | CS_VREDRAW ;
WndClass.lpfnWndProc = (WNDPROC) DisksWndProc;
WndClass.cbClsExtra = 0 ;
WndClass.cbWndExtra = 0 ;
WndClass.hInstance = hInstance ;
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
WndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
WndClass.lpszMenuName = "DiskMenu";
WndClass.lpszClassName = "Disks";
if (!RegisterClass(&WndClass))
{
MessageBox(NULL,"Cannont register class","Error",MB_OK);
return 0;
}
hWnd = CreateWindow("Disks","Viewer of disks",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL,
hInstance, NULL);
if(!hWnd)
{
MessageBox(NULL,"Cannont create window","Error",MB_OK);
return 0;
}
// Show our Window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Begine of message cycle
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
long WINAPI DisksWndProc (HWND hWnd,UINT Message,UINT wParam, LONG IParam)
{
DWORD dwDisks;
int i,j;
switch (Message)
{
case WM_CREATE:
dwDisks = GetLogicalDrives();
// Теперь проверяем возвращенное функцией значение.
// В случае нахождения диска его букву добавляем в меню.
j=0;
for (i=0; i<26; i++)
{
if (dwDisks & FlagDisk[i].dwFlag)
{
// Необходимо добавить все найденные диски в меню
InsertMenu(GetSubMenu(GetMenu(hWnd),0),j,
MF_STRING | MF_BYPOSITION, IDM_EXIT + i + 1,
FlagDisk[i].cDisk);
j++;
}
}
return DefWindowProc(hWnd,Message,wParam, IParam);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_EXIT + 1:
case IDM_EXIT + 2:
case IDM_EXIT + 3:
case IDM_EXIT + 4:
case IDM_EXIT + 5:
case IDM_EXIT + 6:
case IDM_EXIT + 7:
case IDM_EXIT + 8:
case IDM_EXIT + 9:
case IDM_EXIT + 10:
case IDM_EXIT + 11:
case IDM_EXIT + 12:
case IDM_EXIT + 13:
case IDM_EXIT + 14:
case IDM_EXIT + 15:
case IDM_EXIT + 16:
case IDM_EXIT + 17:
case IDM_EXIT + 18:
case IDM_EXIT + 19:
case IDM_EXIT + 20:
case IDM_EXIT + 21:
case IDM_EXIT + 22:
case IDM_EXIT + 23:
case IDM_EXIT + 24:
case IDM_EXIT + 25:
case IDM_EXIT + 26:
ViewDiskInfo(LOWORD(wParam)- IDM_EXIT - 1);
return 0;
case IDM_EXIT:
SendMessage(hWnd, WM_DESTROY, 0,0);
default:
return DefWindowProc(hWnd,Message,wParam,IParam);
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,Message,wParam,IParam);
}
}
void ViewDiskInfo(WORD wld)
{
char cBuffer[0x400];
char cVolumeNameBuffer[0x80];
//DWORD dwVolumeNameSize;
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD dwFileSystemFlags;
char cFileSystemNameBuffer[0x80];
//DWORD dwFileSystemNameSize;
DWORD dwSelectorsPerCluster;
DWORD dwBytesPerSector;
DWORD dwNumberOfFreeClusters;
DWORD dwTotalNumberOfClusters;
if(GetVolumeInformation(FlagDisk[wld].cDisk, cVolumeNameBuffer, 0x80,
&dwVolumeSerialNumber,
&dwMaximumComponentLength,
&dwFileSystemFlags,
cFileSystemNameBuffer, 0x80))
{
GetDiskFreeSpace(FlagDisk[wld].cDisk,&dwSelectorsPerCluster,
&dwBytesPerSector,
&dwNumberOfFreeClusters,
&dwTotalNumberOfClusters);
sprintf_s(cBuffer,"Drive - %03s\n Volume name - %s\n\
Volume serial number - %08x\n\
Maximum component lenth - %08x\n\
File system flags - %08x\n\
File system name - %s\n\n\
Sectors per cluster - %08x\n\
Bytes per sector - %08x\n\
Number of free clusters - %08x\n\
Total number of clusters -%08x",
FlagDisk[wld].cDisk, cVolumeNameBuffer, dwVolumeSerialNumber,
dwMaximumComponentLength, dwFileSystemFlags,
cFileSystemNameBuffer, dwSelectorsPerCluster, dwBytesPerSector,
dwNumberOfFreeClusters, dwTotalNumberOfClusters);
MessageBox(NULL,cBuffer,"Drive info",MB_OK);
}
else
MessageBox(NULL,"May be, there is not diskette or CD in this drive", "Error",MB_OK);
}
-----------------------------------------------------------------
[/more]
Все компилится все класно только вот выводится пустое белое окно и все.
Помогите пожалуйста... Где я натупил...???