Windows 95/98 boot mode can be divided into normal mode and safe mode, in Safe mode, there are many functions are limited to use, such as multimedia functions, network functions. Sometimes, the programs we write just need these limited features, so we want to automatically detect if the current Windows startup mode is safe Mode when the program is running to determine whether to continue running the program.
So how do you detect if the current Windows is started in normal or safe mode in a C + + Builder program? This requires the use of the API function GetSystemMetrics to detect. API function GetSystemMetrics can get some configuration information about Windows, such as the number of mouse keys, the width of the border of the form, it can also measure the current Windows in the boot mode.
In the Windows API, the function is defined as follows:
int getsystemmetrics (int nindex);
There are a lot of values for parameter nindex, and if you want to detect only the startup mode of Windows, the value will confirm the mode in which the current Windows started, as long as the parameter value is sm_cleanboot. It has a return value of three:
0: normal start-up mode;
1: Safe mode to start Windows;
2: Start in safe mode, but have network function.
We can use this function at the beginning of the program, as in the following example, the application displays different prompts depending on the Windows startup mode, and the user can add new processing code specifically in actual programming.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
switch(GetSystemMetrics(SM_CLEANBOOT))
{
case 0:
ShowMessage("正常模式启动");
break;
case 1:
ShowMessage("安全模式启动");
break;
case 2:
ShowMessage("安全模式启动,但带网络附带功能");
break;
default:
ShowMessage("错误,系统启动有问题。");
break;
}
}