Win32 应用程序可以从代码中打开系统的设置吗?
Can Win32 applications open the system's settings from code?
是否可以使用来自 C 的 Win32 API 调用打开 Windows' 设置对话框?例如显示器设置(允许您设置显示器分辨率的设置)和网络设置(允许您设置 Wifi 设置的设置)。
如果可以,怎么做?
或者,这根本不可能,用户必须手动打开它们吗?
Launch the Windows Settings app 解释了如何使用 ms-settings:
URI 方案启动 Windows 设置应用程序。它还列出了支持的 URI,包括这个问题要求的 URI(ms-settings:network-wifi
和 ms-settings:display
)。
虽然文档建议使用 Windows 运行时 API Launcher.LaunchUriAsync
this is a fair bit complex with C (as opposed to C++). Since the URIs can be invoked from the command prompt using the start
command (e.g. start ms-settings:display
), it's reasonable to assume that ShellExecuteExW
也可以处理 ms-settings:
URI 方案。
事实上,这似乎有效:
#include <Windows.h>
#include <stdio.h>
int main() {
SHELLEXECUTEINFOW sei = {
.cbSize = sizeof(sei),
.hwnd = NULL,
.lpVerb = L"open",
.lpFile = L"ms-settings:display",
//.lpFile = L"ms-settings:network-wifi",
.nShow = SW_SHOWNORMAL,
};
if (!ShellExecuteExW(&sei))
{
printf("Failed with error code %d", GetLastError());
}
}
我找不到任何指定此行为的文档,因此这很可能是不受支持的实现细节。我还要提到的是,虽然 SHELLEXECUTEINFOW
有一个 lpClass
字段可用于指定 URI 协议方案,但我使用它的迭代 none 对 ms-settings:
URI 有效方案。
是否可以使用来自 C 的 Win32 API 调用打开 Windows' 设置对话框?例如显示器设置(允许您设置显示器分辨率的设置)和网络设置(允许您设置 Wifi 设置的设置)。
如果可以,怎么做?
或者,这根本不可能,用户必须手动打开它们吗?
Launch the Windows Settings app 解释了如何使用 ms-settings:
URI 方案启动 Windows 设置应用程序。它还列出了支持的 URI,包括这个问题要求的 URI(ms-settings:network-wifi
和 ms-settings:display
)。
虽然文档建议使用 Windows 运行时 API Launcher.LaunchUriAsync
this is a fair bit complex with C (as opposed to C++). Since the URIs can be invoked from the command prompt using the start
command (e.g. start ms-settings:display
), it's reasonable to assume that ShellExecuteExW
也可以处理 ms-settings:
URI 方案。
事实上,这似乎有效:
#include <Windows.h>
#include <stdio.h>
int main() {
SHELLEXECUTEINFOW sei = {
.cbSize = sizeof(sei),
.hwnd = NULL,
.lpVerb = L"open",
.lpFile = L"ms-settings:display",
//.lpFile = L"ms-settings:network-wifi",
.nShow = SW_SHOWNORMAL,
};
if (!ShellExecuteExW(&sei))
{
printf("Failed with error code %d", GetLastError());
}
}
我找不到任何指定此行为的文档,因此这很可能是不受支持的实现细节。我还要提到的是,虽然 SHELLEXECUTEINFOW
有一个 lpClass
字段可用于指定 URI 协议方案,但我使用它的迭代 none 对 ms-settings:
URI 有效方案。