Okay so I am posting this as an answer because I think it would be too much for a comment. If it doesn't relate to the question please comment so I can delete it. I do not have a Lenovo Yoga 7i
but my Acer Travelmate Spin
also has a tablet mode.
As per GetSystemMetrics GetSystemMetrics(SM_CONVERTIBLESLATEMODE); // 0x2003
we seem to be able to read if we are in slate mode 0
or 1
where slate 0 = tablet
and slate 1 = laptop or other devices
according to convertibleslatemode.
The docs claim that:
Reflects the state of the laptop or slate mode, 0 for Slate Mode and
non-zero otherwise. When this system metric changes, the system sends
a broadcast message via WM_SETTINGCHANGE with "ConvertibleSlateMode"
in the LPARAM. Note that this system metric doesn't apply to desktop
PCs. In that case, use GetAutoRotationState.
I tried to do this broadcast myself via:
DWORD_PTR res;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"ConvertibleSlateMode", SMTO_ABORTIFHUNG, 1000, &res);
Which did not work.
I then realised that there was a regkey at: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PriorityControl
called ConvertibleSlateMode
which reflected the values mentioned before of slate 0 and 1
.
If you are in tablet mode (slate 0
) and set the value of the regkey to 1 it enters desktop mode. I am unsure if the broadcast (mentioned above) is required or not but for me it worked to (while in tablet mode) set the regkey to 0 and then to 1.
In c++ this can be done with:
void setRegKey(const DWORD value) {
HKEY hKey;
LONG regStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\PriorityControl", 0, KEY_SET_VALUE, &hKey);
if (regStatus != ERROR_SUCCESS) {
std::cout << "Error opening registry key.\n";
return;
}
const wchar_t* valueName = L"ConvertibleSlateMode";
regStatus = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
if (regStatus != ERROR_SUCCESS) {
std::cout << "Error setting registry value.\n";
RegCloseKey(hKey);
return;
}
RegCloseKey(hKey);
std::cout << "Registry value set successfully.\n";
}
and then in main:
int main() {
setRegKey(0);
setRegKey(1);
}
EDIT: As mentioned by @BenVoigt and @KeshavV. you can most likely also follow this: Windows 10 tablet mode Registry setting: 'When this device automatically switches tablet mode on or off'
More related links:
GetSystemMetrics
WM_SETTINGCHANGE
SendMessageTimeout
convertibleslatemode