Windows Application Development Relevant Articles

Windows应用开发相关


    case WM_CREATE:
    {
        RECT windowRect;
        GetWindowRect(hWnd, &windowRect);
        // Disable the minimize button, the maximize button and window resizing.
        SetWindowLongA(hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) & ~WS_MINIMIZEBOX);
        SetWindowLongA(hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
        SetWindowLongA(hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) & ~WS_SIZEBOX);
        break;
    }

Visual Studio 2019创建平台通用的DLL库项目

使用下图模板创建项目:

1.jpg


请注意这个项目名与桌面DLL的区别:

2.jpg


这样就能生成x86、x64、ARM以及ARM64这四种目标平台了。随后我们在项目属性中,将每个平台的“生成预编译头”选项设置为 NO 即可。


Win32 API Fetch Number of Cores

通过Win32 API来获取CPU的核心个数主要分两步:第一步是通过调用 GetSystemInfo 函数来获取逻辑核心的总个数;第二步则是调用 GetLogicalProcessorInformationEx 函数来获取逻辑核与物理核的关联信息,最终即可判定出当前处理器有多少核心了。

代码如下所示:

#include <Windows.h>
#include <stdio.h>

int main(void)
{
    SYSTEM_INFO sysInfo;
    // 获取系统信息,
    // SYSTEM_INFO结构体中可获取当前系统的逻辑处理器的个数
    GetSystemInfo(&sysInfo);

    // 方便起见,假定我们当前系统最多有128个关系信息
    SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX logicalInfos[128];

    DWORD paramSize = (DWORD)sizeof(logicalInfos);

    printf("Number of logical processors: %u\n", sysInfo.dwNumberOfProcessors);

    // 获取指定逻辑处理器所关联的处理器核心的信息
    if (GetLogicalProcessorInformationEx(RelationProcessorCore, logicalInfos, &paramSize))
    {
        DWORD nCores = sysInfo.dwNumberOfProcessors;
        // 当前x86架构的处理器中,一个核心最多只有两个逻辑核
        if (logicalInfos[0].Processor.Flags == LTP_PC_SMT)
            nCores /= 2;

        printf("Number of Cores: %u\n", nCores);
    }

    return 0;
}

Windows 10的日常使用