📄 formatdrive.cpp
字号:
UNREFERENCED_PARAMETER(lParam);
switch (nCode)
{
case HCBT_DESTROYWND:
{
char buffer[255];
GetWindowText(reinterpret_cast<HWND>(wParam),buffer,sizeof(buffer));
CString csWindowTitle(buffer);
// only handle the 'Format' dialog and Exclude the FormatDriveSample dialog.
if (reinterpret_cast<HWND>(wParam) == m_hFormatDialog)
{
UnhookWindowsHookEx(m_hHook);
CFormatDriveDialog::m_hHook = NULL;
m_hFormatDialog = NULL;
}
}
break;
case HCBT_ACTIVATE:
{
char buffer[255];
GetWindowText(reinterpret_cast<HWND>(wParam),buffer,sizeof(buffer));
CString csWindowTitle(buffer);
// only handle the 'Format' dialog and Exclude the FormatDriveSample dialog.
if ( (-1 != csWindowTitle.Find(INCLUDE_DIALOG_TITLE1)) &&
(-1 == csWindowTitle.Find(EXCLUDE_DIALOG_TITLE1)) &&
(-1 == csWindowTitle.Find(EXCLUDE_DIALOG_TITLE2)) )
{
// Set the FormatDialog to the window that is created
m_hFormatDialog = reinterpret_cast<HWND>(wParam);
EnumChildWindows(m_hFormatDialog,EvaluateWindowElements,NULL);
}
}
break;
case HCBT_CREATEWND:
case HCBT_CLICKSKIPPED:
case HCBT_KEYSKIPPED:
case HCBT_SETFOCUS:
if (NULL != m_hFormatDialog)
{
switch (GetTheSystemVersion())
{
case WINDOWS_95OSR1:
case WINDOWS_95OSR2:
case WINDOWS_98FE:
case WINDOWS_98SE:
case WINDOWS_NT4:
EnumChildWindows(m_hFormatDialog,EvaluateWindowElements,NULL);
break;
case WINDOWS_2000:
case WINDOWS_XP:
case UNKNOWN_OS:
case WINDOWS_ME:
case WINDOWS_NT35:
default:
break;
}
}
break;
case HCBT_SYSCOMMAND:
case HCBT_MOVESIZE:
case HCBT_MINMAX:
case HCBT_QS:
default:
// Unknown code for this type of dialog
break;
}
return FALSE;
}
/**********************************************************************************
// FUNCTION : CFormatDriveDialog::EvaluateWindowElements()
//
// Description : This function will be called whenever the FormatDrive dialog
// is created and every element on that dialog need to be
// evaluated
//
// Created : [23-6-2002 17:20:30]
// Returns : [int] - ALWAYS TRUE!!
// Parameters : [IN : xxx] See MSDN (EnumChildWindows method)
***********************************************************************************/
BOOL CALLBACK CFormatDriveDialog::EvaluateWindowElements( HWND hwnd, LPARAM lParam )
{
UNREFERENCED_PARAMETER(lParam);
char sClassName[256];
GetClassName(hwnd,sClassName,sizeof(sClassName));
// Disable all the Edit boxes on the window
if(0 == strcmp(sClassName,"Edit"))
{
SetWindowText(hwnd,m_sVolumeLabel);
EnableWindow(hwnd,FALSE);
}
// Disable all the Combo boxes on the window
if(0 == strcmp(sClassName,"ComboBox"))
{
EnableWindow(hwnd,FALSE);
}
// Disable some Buttons on the window (depends on OS type)
// Windows 95/98 contain a different dialog than Windows 2000 based
// systems.
if(0 == strcmp(sClassName,"Button"))
{
char sButtonText[255];
GetWindowText(hwnd,sButtonText,sizeof(sButtonText));
long ButtonStyle = GetWindowLong(hwnd,GWL_STYLE);
// Now disable only the buttons that are allowed to be disabled.
// (If due to language problems some language problems some buttons cannot
// be properly detected they will be disabled. Therefore the default
// format settings must be logical chosen.)
switch (GetTheSystemVersion())
{
case WINDOWS_95OSR1:
case WINDOWS_95OSR2:
case WINDOWS_98FE:
case WINDOWS_98SE:
case WINDOWS_NT4:
{
CString csButtonText(sButtonText);
if ((-1 == csButtonText.Find(QUICK_DETECT_TEXT_ON_FORMATDLG)) &&
(-1 == csButtonText.Find(FULL_DETECT_TEXT_ON_FORMATDLG)) )
{
// Only Checkboxes can have these options set
if ((ButtonStyle & BS_CHECKBOX) || (ButtonStyle & BS_RADIOBUTTON))
{
EnableWindow(hwnd,FALSE);
}
}
}
break;
case WINDOWS_2000:
{
// Only Checkboxes can have these options set
if ((ButtonStyle & BS_CHECKBOX) || (ButtonStyle & BS_RADIOBUTTON))
{
EnableWindow(hwnd,FALSE);
}
CString csButtonText(sButtonText);
if (-1 != csButtonText.Find(QUICK_DETECT_TEXT_ON_FORMATDLG))
{
EnableWindow(hwnd,TRUE);
}
}
break;
case WINDOWS_XP:
{
// Only Checkboxes can have these options set
if ((ButtonStyle & BS_CHECKBOX) || (ButtonStyle & BS_RADIOBUTTON))
{
EnableWindow(hwnd,FALSE);
}
CString csButtonText(sButtonText);
if (-1 != csButtonText.Find(QUICK_DETECT_TEXT_ON_FORMATDLG))
{
EnableWindow(hwnd,TRUE);
}
}
break;
case UNKNOWN_OS:
case WINDOWS_ME:
case WINDOWS_NT35:
default:
{
// Only Checkboxes can have these options set
if ((ButtonStyle & BS_CHECKBOX) || (ButtonStyle & BS_RADIOBUTTON))
{
EnableWindow(hwnd,FALSE);
}
//unsupported Operating system
}
break;
}
}
return TRUE;
}
/**********************************************************************************
// FUNCTION : CFormatDriveDialog::GetTheSystemVersion()
//
// Description : This function can be used to detect the OS version this app is
// running on.
//
// Created : [23-6-2002 17:20:30]
// Returns : [int] - OS_VERSIONS: Version ID of the OS this app is running
// Parameters : [IN : void]
***********************************************************************************/
OS_VERSIONS CFormatDriveDialog::GetTheSystemVersion(void)
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
static OS_VERSIONS OsAlreadyDetected = UNKNOWN_OS;
// The following check is only used for performance improvement of this check
// (This check normally returns always the same value per Application Run, the
// OS will never change during runtime of this application)
if (UNKNOWN_OS != OsAlreadyDetected)
{
return OsAlreadyDetected;
}
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi);
if( !bOsVersionInfoEx )
{
// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
{
OsAlreadyDetected = UNKNOWN_OS;
return UNKNOWN_OS;
}
}
switch (osvi.dwPlatformId)
{
// Tests for Windows NT product family.
case VER_PLATFORM_WIN32_NT:
// Test for the product.
if ( osvi.dwMajorVersion <= 4 )
{
OsAlreadyDetected = WINDOWS_NT35;
return WINDOWS_NT35;
}
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
{
OsAlreadyDetected = WINDOWS_2000;
return WINDOWS_2000;
}
if( bOsVersionInfoEx ) // Use information from GetVersionEx.
{
if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1) )
{
OsAlreadyDetected = WINDOWS_XP;
return WINDOWS_XP;
}
else
{
OsAlreadyDetected = UNKNOWN_OS;
return UNKNOWN_OS;
}
}
else // Use the registry on early versions of Windows NT.
{
HKEY hKey;
char szProductType[PRODUCT_TYPE_BUFSIZE];
DWORD dwBufLen = PRODUCT_TYPE_BUFSIZE;
LONG lRet;
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_QUERY_VALUE, &hKey );
if( lRet != ERROR_SUCCESS )
{
OsAlreadyDetected = UNKNOWN_OS;
return UNKNOWN_OS;
}
lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
(LPBYTE) szProductType, &dwBufLen);
if( (lRet != ERROR_SUCCESS) || (dwBufLen > PRODUCT_TYPE_BUFSIZE) )
{
OsAlreadyDetected = UNKNOWN_OS;
return UNKNOWN_OS;
}
RegCloseKey( hKey );
if (( lstrcmpi( "WINNT", szProductType) == 0 ) ||
( lstrcmpi( "LANMANNT", szProductType) == 0 ) ||
( lstrcmpi( "SERVERNT", szProductType) == 0 ) )
{
OsAlreadyDetected = WINDOWS_NT4;
return WINDOWS_NT4;
}
}
break;
// Test for the Windows 95 product family.
case VER_PLATFORM_WIN32_WINDOWS:
if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0))
{
if ( (osvi.szCSDVersion[1] == 'C') || (osvi.szCSDVersion[1] == 'B') )
{
OsAlreadyDetected = WINDOWS_95OSR2;
return WINDOWS_95OSR2;
}
else
{
OsAlreadyDetected = WINDOWS_95OSR1;
return WINDOWS_95OSR1;
}
}
if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 10))
{
if ( osvi.szCSDVersion[1] == 'A' )
{
OsAlreadyDetected = WINDOWS_98SE;
return WINDOWS_98SE;
}
else
{
OsAlreadyDetected = WINDOWS_98FE;
return WINDOWS_98FE;
}
}
if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 90))
{
OsAlreadyDetected = WINDOWS_ME;
return WINDOWS_ME;
}
break;
}
OsAlreadyDetected = UNKNOWN_OS;
return UNKNOWN_OS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -