C++获取系统信息
C++获取系统信息
-
判断当前系统是32位还是64位
::SYSTEM_INFO si; ::GetNativeSystemInfo(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_IA64) { cout << "64位操作系统" << endl; } else { cout << "32位操作系统" << endl; }
-
获取系统目录
WCHAR buff[MAX_PATH] = { 0 };//存储系统目录 int len = ::GetSystemDirectory(buff, MAX_PATH);//返回值为系统目录的长度
-
获取屏幕分辨率
int value = ::GetSystemMetrics(SM_CXSCREEN); int value2 = ::GetSystemMetrics(SM_CYSCREEN);
列举常用的参数获取值:
SM_CMONITORS:获取显示器的数量(但在复制屏下获取的是1)
-
获取当前时间
SYSTEMTIME time; ::GetLocalTime(&time);
-
获取当前目录
WCHAR buffer[MAX_PATH] = { 0 }; ::_wgetcwd(buffer, MAX_PATH);
-
获取运行程序路径
WCHAR buffer[MAX_PATH] = { 0 }; GetModuleFileName(nullptr, buffer, MAX_PATH);