Home >Backend Development >C#.Net Tutorial >C/C++ determines whether it is a laptop computer

C/C++ determines whether it is a laptop computer

黄舟
黄舟Original
2017-01-22 14:33:102595browse

First of all, we know that the difference between a desktop and a notebook is whether there is a power supply.

If there is an API for reading power information that provides a return value, can we determine whether it is a notebook or a desktop?


Let’s take a look at an API


GetSystemPowerStatus function

C/C++ determines whether it is a laptop computer

We can generally know that

This is a function that retrieves the system power status. This status implies whether the system is DC or AC, and the current load of the battery is cleared, etc.


Let me take a look at the parameters:

SYSTEM_POWER_STATUS

C/C++ determines whether it is a laptop computer

C/C++ determines whether it is a laptop computer

We can see the BatterFlag member, which loads the battery status and included flags

It can be seen that when the value is 128 and 255, the response is that there is no voltage or the voltage cannot be read,

So you can type the following code:

#include <Windows.h>  
#include <stdio.h>  
  
int main()  
{  
    SYSTEM_POWER_STATUS a;  
    GetSystemPowerStatus(&a);  
  
    if (a.BatteryFlag == 128 && a.BatteryFlag == 255)  
    {  
        printf("台式电脑\n");  
    }  
    else  
    {  
        printf("笔记本电脑\n");  
    }  
  
    return 0;  
}

Running results:

C/C++ determines whether it is a laptop computer


##The above is C/C++ to determine whether it is a laptop For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn