📄 ramdisk.cpp
字号:
#endif
#ifdef _DEBUG
wsprintfW( &__string[0] , L"--> 'PropPageDlgProc' called , uMessage = 0x%04x " , uMessage ) ;
cString.FormatMessageW ( &__string[0] ) ;
wsprintfW( &__string[0] , L" ( ????????? )\n" ) ;
if ( uMessage == WM_INITDIALOG )
wsprintfW( &__string[0] , L" ( WM_INITDIALOG )\n" ) ;
if ( uMessage == WM_COMMAND )
wsprintfW( &__string[0] , L" ( WM_COMMAND )\n" ) ;
if ( uMessage == WM_NOTIFY )
wsprintfW( &__string[0] , L" ( WM_NOTIFY )\n" ) ;
cString += LPCTSTR ( &__string[0]) ;
// suppress the flood of ....
if ( ( uMessage == WM_SETCURSOR ) ||
( uMessage == WM_NCHITTEST ) ||
( uMessage == WM_MOUSEMOVE ) )
; //suppress
else
OutputDebugStringW ( LPCTSTR ( cString ) ) ;
#endif
switch(uMessage)
{
case WM_COMMAND:
pParams = (PQSOFT_PARAMS) GetWindowLongPtr ( hDlg , DWLP_USER ) ;
// do dialog specific stuff here , not used within this propery page application ....
#ifdef _DEBUG
// if we would place some buttons on the dialog and give them the IDC_GOOK, IDC_GOCANCEL values ...
if ( (WORD)wParam == IDC_GOOK )
OutputDebugStringW ( L">GO OK< pushed \n" ) ;
if ( (WORD)wParam == IDC_GOCANCEL )
OutputDebugStringW ( L">GO CANCEL< pushed \n" ) ;
#endif
// .....
break;
case WM_CONTEXTMENU:
;
return TRUE ;
case WM_HELP:
;
break;
case WM_INITDIALOG:
// The lParam field in the property sheet page struct is set by the
// caller. When we created the property sheet, we passed in a pointer
// to a struct containing information about the device. We save this in
// the user window "long", so we can access it on later messages.
//
pParams = (PQSOFT_PARAMS) ((LPPROPSHEETPAGE)lParam)->lParam;
memset ( (void*)pParams , 0 , sizeof(QSOFT_PARAMS) ) ;
SetWindowLongPtr( hDlg , DWLP_USER, (ULONG_PTR) pParams ) ;
// do dialog specific stuff here
{
DWORD dwBitPosition ;
DWORD dwBitSlider = 1 ;
DWORD dwSizeEntry ;
DWORD dwFreeDrives = ~GetLogicalDrives() & 0x03FFFFFF ;
HKEY hDeviceKey ;
WCHAR szDriveLetter[16] = { 'B' , ':' , 0 } ;
DWORD dwDriveLetter_index ;
DWORD dwDiskSize = dwaDriveSizes[0] ;
DWORD dwDiskSize_index ;
// Query disksize and drive letter
if ( RegOpenKeyW ( HKEY_LOCAL_MACHINE , szRegServices , &hDeviceKey ) == ERROR_SUCCESS )
{
DWORD dwSize ;
DWORD dwError ;
dwSize = sizeof(szDriveLetter) ;
dwError = RegQueryValueExW ( hDeviceKey , L"DriveLetter" , NULL , NULL , (LPBYTE)&szDriveLetter[0] , &dwSize ) ;
dwSize = sizeof(dwDiskSize) ;
dwError = RegQueryValueExW ( hDeviceKey , L"DiskSize" , NULL , NULL , (LPBYTE)&dwDiskSize , &dwSize ) ;
RegCloseKey(hDeviceKey);
}
#ifdef _DEBUG
wsprintfW( &__string[0] , L"--> registry settings : DriveLetter = %s , DiskSize = %d\n" , szDriveLetter , dwDiskSize ) ;
OutputDebugStringW ( &__string[0] ) ;
#endif
// 1. drive letter ...
// adapt drive letter if not valid
dwBitPosition = 0 ;
for ( dwDriveLetter_index = 0 ; dwDriveLetter_index < 26 ; dwDriveLetter_index++ )
{
if ( *(PCHAR)(caDriveLetters[dwDriveLetter_index]) == szDriveLetter[0] )
{ // found the default value
dwBitPosition = 1 << dwDriveLetter_index ;
break ;
}
}
if ( !dwBitPosition )
{
dwBitPosition = 2 ; // reverse to default B: drive
szDriveLetter[0] = (WCHAR)'B' ;
szDriveLetter[1] = (WCHAR)':' ;
szDriveLetter[2] = 0 ;
}
// add the value to the selectable ones ...
dwFreeDrives |= dwBitPosition ;
// keep the value for subsequent processing within the "Apply" sequence
pParams->wcDriveLetter_default = szDriveLetter[0] ;
// go on with retrieving and filling the list box entries
hCtrlHwnd = GetDlgItem ( hDlg , IDC_DRIVESELECT ) ;
pParams->nDriveLetters = dwDriveLetter_index = 0 ;
while ( dwBitSlider < 0x03FFFFFF )
{
dwBitPosition = (DWORD)BitPosition ( dwBitSlider & dwFreeDrives ) ;
if ( dwBitPosition && ( dwBitPosition <= 26 ) )
{
PWCHAR pwcDrive = caDriveLetters[dwBitPosition - 1] ;
ComboBox_AddString ( hCtrlHwnd , pwcDrive ) ;
if ( *pwcDrive == szDriveLetter[0] ) dwDriveLetter_index = pParams->nDriveLetters ; // found the default
pParams->nDriveLetters++ ;
#ifdef _DEBUG
wsprintfW( &__string[0] , L"--> available drive letter = %s\n" , pwcDrive ) ;
OutputDebugStringW ( &__string[0] ) ;
#endif
}
dwBitSlider = dwBitSlider << 1 ;
}
ComboBox_SetCurSel ( hCtrlHwnd , dwDriveLetter_index ) ;
// 2. disk size ...
// adapt size if not valid
dwBitPosition = 0 ; // temporarely used as a mark
for ( dwDiskSize_index = 0 ; dwDiskSize_index < ( sizeof(dwaDriveSizes) / sizeof(DWORD) ) ; dwDiskSize_index++ )
{
if ( dwaDriveSizes[dwDiskSize_index] == dwDiskSize )
{
dwBitPosition = 1 ;
break ;
}
}
if ( !dwBitPosition ) dwDiskSize_index = 0 ; // preset to the smallest value
hCtrlHwnd = GetDlgItem ( hDlg , IDC_DRIVESIZE ) ;
for ( dwSizeEntry = 0 ; dwSizeEntry < ( sizeof(dwaDriveSizes) / sizeof(DWORD) ) ; dwSizeEntry++ )
{
wsprintfW ( &__string[0] , L"%d" , dwaDriveSizes[dwSizeEntry] ) ;
ComboBox_AddString ( hCtrlHwnd , &__string[0] ) ;
}
ComboBox_SetCurSel ( hCtrlHwnd , dwDiskSize_index ) ;
// 3. done ...
#ifdef _DEBUG
wsprintfW( &__string[0] , L"--> default settings : DriveLetter_index = %d , DiskSize_index = %d\n" , dwDriveLetter_index , dwDiskSize_index ) ;
OutputDebugStringW ( &__string[0] ) ;
#endif
}
return TRUE ;
case WM_NOTIFY:
// in case we should need data from our " temporary storage " ( see above )
pParams = (PQSOFT_PARAMS) GetWindowLongPtr ( hDlg , DWLP_USER ) ;
switch ( ((LPNMHDR)lParam)->code )
{
//
// Sent when the user clicks on Apply OR OK !!
//
case PSN_APPLY:
//
// Do specific stuff
//
DWORD dwComboIndex ;
DWORD dwResult ;
// 1. get selected drive letter and validate
hCtrlHwnd = GetDlgItem ( hDlg , IDC_DRIVESELECT ) ;
dwComboIndex = ComboBox_GetCurSel ( hCtrlHwnd ) ;
pParams->wcDriveLetter = 0 ;
if ( dwComboIndex < pParams->nDriveLetters )
{
ComboBox_GetLBText ( hCtrlHwnd , dwComboIndex , &__string[0] ) ;
pParams->wcDriveLetter = __string[0] ;
}
hCtrlHwnd = GetDlgItem ( hDlg , IDC_DRIVESIZE ) ;
dwComboIndex = ComboBox_GetCurSel ( hCtrlHwnd ) ;
// 2. get selected drive size and validate
pParams->dwDriveSize = 0 ;
if ( dwComboIndex < ( sizeof(dwaDriveSizes) / sizeof(DWORD) ) )
{
ComboBox_GetLBText ( hCtrlHwnd , dwComboIndex , &__string[0] ) ;
__string[32] = 0 ;
pParams->dwDriveSize = _wtol ( &__string[0] ) ;
}
#ifdef _DEBUG
{
WCHAR wcDrive[3] ;
wcDrive[0] = pParams->wcDriveLetter ;
wcDrive[1] = (WCHAR)':' ;
wcDrive[2] = 0 ;
wsprintfW( &__string[0] , L"--> APPLY pushed : drive letter = %s , size = %d\n" , &wcDrive[0] , pParams->dwDriveSize ) ;
OutputDebugStringW ( &__string[0] ) ;
}
#endif
if ( pParams->dwDriveSize && pParams->wcDriveLetter )
{
// go and write the registry
// ClassGuid={FFA1C341-4539-11d3-B88D-00C04FAD5172} .. see INF file
GUID __guID = { 0xFFA1C341 , 0x4539 , 0x11D3 , { { 0xB8 } , { 0x8D } , { 0x00 } , { 0xC0 } , { 0x4F } , { 0xAD } , { 0x51 } , { 0x72 } } } ;
HKEY hDeviceKey ;
BOOL bSuccess = FALSE ;
BOOL bInitiallyDisabled = TRUE ;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
DWORD Status ;
DWORD Problem ;
HDEVINFO hDev = SetupDiGetClassDevs ( &__guID , NULL , hDlg , DIGCF_PRESENT ) ;
#ifdef _DEBUG
wsprintfW( &__string[0] , L"--> hDev = %x\n" , hDev ) ;
OutputDebugStringW ( &__string[0] ) ;
#endif
bSuccess = SetupDiEnumDeviceInfo ( hDev , 0 , &DeviceInfoData ) ;
#ifdef _DEBUG
if ( !bSuccess ) OutputDebugStringW ( L"'SetupDiEnumDeviceInfo' not successfull\n" ) ;
#endif
if ( bSuccess )
{
bSuccess = ( CM_Get_DevNode_Status ( &Status, &Problem , DeviceInfoData.DevInst , 0 ) == CR_SUCCESS ) ;
bInitiallyDisabled = ( Status & DN_HAS_PROBLEM ) && ( Problem = CM_PROB_DISABLED ) ;
}
#ifdef _DEBUG
if ( !bSuccess ) OutputDebugStringW ( L"'CM_Get_DevNode_Status' not successfull\n" ) ;
wsprintfW( &__string[0] , L"--> Device : Status = %x , Problem = %x , Disabled = %d\n" , Status, Problem , bInitiallyDisabled ) ;
OutputDebugStringW ( &__string[0] ) ;
#endif
if ( !bInitiallyDisabled )
{
ChangeState ( DICS_DISABLE , 0 , hDev ) ;
#ifdef _DEBUG
{
BOOL bDisabled ;
bSuccess = ( CM_Get_DevNode_Status ( &Status, &Problem , DeviceInfoData.DevInst , 0 ) == CR_SUCCESS ) ;
bDisabled = ( Status & DN_HAS_PROBLEM ) && ( Problem = CM_PROB_DISABLED ) ;
if ( !bSuccess ) OutputDebugStringW ( L"'CM_Get_DevNode_Status' not successfull\n" ) ;
wsprintfW( &__string[0] , L"--> Device[ disabled ] : Status = %x , Problem = %x , Disabled = %d\n" , Status, Problem , bDisabled ) ;
OutputDebugStringW ( &__string[0] ) ;
}
#endif
}
// write new / rewrite existing values into the registry
if ( RegOpenKeyW ( HKEY_LOCAL_MACHINE , szRegServices , &hDeviceKey ) == ERROR_SUCCESS )
{
WCHAR szDriveLetter[3] ;
DWORD dwDiskSize ;
DWORD dwSize ;
DWORD dwError ;
szDriveLetter[0] = pParams->wcDriveLetter ;
szDriveLetter[1] = (WCHAR)':' ;
szDriveLetter[2] = 0 ;
dwSize = sizeof(szDriveLetter) ;
dwError = RegSetValueExW ( hDeviceKey , L"DriveLetter" , 0 , REG_SZ , (PBYTE)&szDriveLetter[0] , dwSize ) ;
dwDiskSize = pParams->dwDriveSize ;
dwSize = sizeof(DWORD) ;
dwError = RegSetValueExW ( hDeviceKey , L"DiskSize" , 0 , REG_DWORD , (PBYTE)&dwDiskSize , dwSize ) ;
RegCloseKey(hDeviceKey);
}
// restore to enable if initially enabled
if ( !bInitiallyDisabled )
{
ChangeState ( DICS_ENABLE , 0 , hDev ) ;
#ifdef _DEBUG
{
BOOL bDisabled ;
bSuccess = ( CM_Get_DevNode_Status ( &Status, &Problem , DeviceInfoData.DevInst , 0 ) == CR_SUCCESS ) ;
bDisabled = ( Status & DN_HAS_PROBLEM ) && ( Problem = CM_PROB_DISABLED ) ;
if ( !bSuccess ) OutputDebugStringW ( L"'CM_Get_DevNode_Status' not successfull\n" ) ;
wsprintfW( &__string[0] , L"--> Device[ re-enabled ] : Status = %x , Problem = %x , Disabled = %d\n" , Status, Problem , bDisabled ) ;
OutputDebugStringW ( &__string[0] ) ;
}
#endif
}
if ( hDev != INVALID_HANDLE_VALUE ) SetupDiDestroyDeviceInfoList ( hDev ) ;
// propagate th new drive letter
if ( pParams->wcDriveLetter_default != pParams->wcDriveLetter )
{
BroadcastVolumeDeviceChange ( DBT_DEVICEREMOVECOMPLETE, pParams->wcDriveLetter_default );
BroadcastVolumeDeviceChange ( DBT_DEVICEARRIVAL , pParams->wcDriveLetter );
}
}
if ( !pParams->dwDriveSize || !pParams->wcDriveLetter )
{
WCHAR szInvalid[128] ;
LoadStringW ( (HINSTANCE)g_hInst, IDS_INVALID , szInvalid , 128 ) ;
::AfxMessageBox ( szInvalid , MB_OK , -1 ) ;
dwResult = PSNRET_INVALID_NOCHANGEPAGE ;
}
else
dwResult = PSNRET_NOERROR ;
// ACK the caller
SetWindowLongPtr ( hDlg , DWLP_MSGRESULT, dwResult ) ;
return TRUE;
default:
return FALSE;
}
}
return FALSE;
} /* PropPageDlgProc */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -