Windows¶
Warning
The current page still doesn't have a translation for this language.
You can read it through google translate.
Windows 是 SOUI 的原生平台,也是唯一不编译 swinx 的平台——SOUI 直接调用系统提供的 Win32 API。
平台定位¶
根 CMakeLists.txt 中的分支非常直白:
if (CMAKE_SYSTEM_NAME MATCHES Windows)
if(MSVC_VERSION LESS 1600)
include_directories(${PROJECT_SOURCE_DIR}/third-part/stdint)
endif()
add_definitions(-DWCHAR_SIZE=2) # 系统 wchar_t 为 2 字节,不引入 swinx
else()
add_subdirectory(swinx) # 其它平台才需要 swinx
...
endif()
也就是说:
swinx/目录在 Windows 构建中完全不参与编译;windows.h、winuser.h等头文件来自 Windows SDK,而不是swinx/include;g_platformAPI(platform_api.h)与 Windows 无关,它只服务于 Android / 鸿蒙。
因此 Windows 上不存在任何兼容层开销,也是 SOUI 特性支持最完整的平台。
Windows 独有的构建选项¶
以下选项只在 Windows 分支中开放,其它平台被强制设定:
if (CMAKE_SYSTEM_NAME MATCHES Windows)
option(SOUI_BUILD_RICHEDIT "using richedit from source code" OFF) # Windows 默认用系统 riched20
option(SOUI_ENABLE_ACC "Enable Acc" OFF) # 无障碍(MSAA)支持
option(SOUI_ENABLE_SPY "Enable Swnd Spy" OFF) # SWnd 调试探测工具
if (MSVC)
add_compile_options(/MP) # 多进程并行编译
endif()
endif()
| 选项 | Windows 默认 | 其它平台 | 说明 |
|---|---|---|---|
SOUI_BUILD_RICHEDIT |
OFF |
强制 ON |
Windows 可用系统 riched20.dll;非 Windows 必须用 SOUI 内置的 richedit 源码实现 |
SOUI_ENABLE_ACC |
可选 OFF |
强制 OFF |
无障碍支持依赖 MSAA/UIA,仅 Windows 可用 |
SOUI_ENABLE_SPY |
可选 OFF |
强制 OFF |
窗口探测工具,仅 Windows 可用 |
SOUI_USE_UNICODE |
ON |
OFF |
Windows 默认 Unicode 构建 |
其它与 Windows / MSVC 相关的全局选项(定义在根 CMakeLists.txt):
SOUI_SHARED_CRT(默认ON):使用动态 CRT(/MD),关闭则用静态 CRT(/MT)。SOUI_XP_TOOLSET(默认ON):兼容 XP 工具集。SOUI_ENABLE_SPECTRE(默认OFF):Spectre 缓解。SOUI_BUILD_WS:WebSocket 模块。MSVC 版本低于 1800(VS2013 及更早)时会被自动关闭。- 安装前缀:64 位为
output_64,32 位为output_32(非 Windows 为/usr/local/soui5)。
渲染工厂¶
Windows 上三种渲染工厂都可用(SOUI/include/SAppCfg.h):
typedef enum _Render
{
Render_Gdi = 0,
Render_Skia,
Render_D2d,
} Render;
SAppCfg cfg;
cfg.SetRender(Render_Skia) // 默认值,跨平台一致
.SetImgDecoder(ImgDecoder_Stb); // Windows 还可用 ImgDecoder_Gdip / ImgDecoder_WIC
若工程需要在 Windows 与其它平台共用一套配置代码,建议统一使用 Render_Skia + ImgDecoder_Stb——这是唯一在六个平台上都可用的组合。
资源加载¶
Windows 使用 PE 资源,这是与其它平台唯一必须区分的地方:
#ifdef _WIN32
cfg.SetSysResPeFile(appDir + _T("/soui-sys-resource.dll")); // 系统皮肤资源在独立 DLL 中
cfg.SetAppResPeHandle(hInstance); // 应用资源编入主模块
#else
cfg.SetSysResZip(strSysRes, "");
cfg.SetAppResZip(strAppRes, "");
#endif
系统资源 DLL 由 soui-sys-resource、soui-sys-resource2、soui-sys-resource-dark、soui-sys-resource-light 等子项目产出,可按主题选择。
入口¶
Windows 由 CRT 直接调用 _tWinMain,不需要额外的 main() 转发:
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpstrCmdLine, int)
{
// 与其它平台完全相同的业务代码
}
跨平台工程中的薄 main() 用 #if !defined(_WIN32) || defined(__MINGW32__) 保护,因此在 MSVC 下不会被编译;MinGW 因为不提供 WinMain 的自动包装,会走 main() 转发分支。
构建¶
# 生成 Visual Studio 工程
cmake -S . -B build -A x64
cmake --build build --config Release
# 或直接打开生成的 build/SOUI4.sln
首次配置需要编译 third-part 下的完整依赖(Skia、OpenSSL、curl、libwebsockets、Scintilla 等),耗时较长;可通过关闭不需要的模块加快速度:
cmake -S . -B build -A x64 -DSOUI_BUILD_WS=OFF -DSOUI_BUILD_DEMOS=OFF -DSOUI_BUILD_GAMES=OFF