本主题包含切换笔记本电脑/平板电脑模式指示器状态的示例代码。
int __cdecl ToggleConversionIndicator(
__in int argc,
__in_ecount(argc) char **argv)
{
LPWSTR DevicePath;
HANDLE FileHandle;
BOOL b;
BYTE buffer;
HWND hwnd;
MSG msg;
//assuming our GetDevicePath method is creating a device path using use SetupDi API
DevicePath = GetDevicePath((LPGUID)&GUID_GPIOBUTTONS_LAPTOPSLATE_INTERFACE);
FileHandle = CreateFile(DevicePath,
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
buffer = 0;
WriteFile(FileHandle, &buffer, sizeof(buffer), NULL, NULL);
return 0;
}
注意: 笔记本电脑/平板电脑模式指示器设备一次只能由一个进程打开。 当另一个进程已打开设备时,CreateFile 将失败,GetLastError 将返回ERROR_ACCESS_DENIED。