Home>Article>Backend Development> C/C++ determines whether it is a laptop computer
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
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
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#include int main() { SYSTEM_POWER_STATUS a; GetSystemPowerStatus(&a); if (a.BatteryFlag == 128 && a.BatteryFlag == 255) { printf("台式电脑\n"); } else { printf("笔记本电脑\n"); } return 0; }
Running results: