GetSystemDirectory获取系统目录
windows说明
WINBASEAPI
UINT
WINAPI
GetSystemDirectoryA(
LPSTR lpBuffer, //缓冲区用于存放取得的系统目录
UINT uSize //缓冲区长度
);
WINBASEAPI
UINT
WINAPI
GetSystemDirectoryW(
LPWSTR lpBuffer,
UINT uSize
);
#ifdef UNICODE
#define GetSystemDirectory GetSystemDirectoryW
#else
#define GetSystemDirectory GetSystemDirectoryA
#endif // !UNICODE
GetWindowsDirectory 获取windows安装目录
windows定义
WINBASEAPI
UINT
WINAPI
GetWindowsDirectoryA(
LPSTR lpBuffer, //缓冲区
UINT uSize //缓冲区长度
);
WINBASEAPI
UINT
WINAPI
GetWindowsDirectoryW(
LPWSTR lpBuffer,
UINT uSize
);
#ifdef UNICODE
#define GetWindowsDirectory GetWindowsDirectoryW
#else
#define GetWindowsDirectory GetWindowsDirectoryA
#endif // !UNICODE
GetUserName 获取用户名
windows定义
WINADVAPI
BOOL
WINAPI
GetUserNameA (
LPSTR lpBuffer, //缓冲区
LPDWORD nSize //设置缓冲区长度
);
WINADVAPI
BOOL
WINAPI
GetUserNameW (
LPWSTR lpBuffer,
LPDWORD nSize
);
#ifdef UNICODE
#define GetUserName GetUserNameW
#else
#define GetUserName GetUserNameA
#endif // !UNICODE
GetComputerName 获取主机名
系统定义
WINBASEAPI
BOOL
WINAPI
SetComputerNameA (
LPCSTR lpComputerName
);
WINBASEAPI
BOOL
WINAPI
SetComputerNameW (
LPCWSTR lpComputerName
);
#ifdef UNICODE
#define SetComputerName SetComputerNameW
#else
#define SetComputerName SetComputerNameA
#endif // !UNICODE
SystemParametersInfo 获取和设置外设信息
系统定义
WINUSERAPI
BOOL
WINAPI
SystemParametersInfoA(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni);
WINUSERAPI
BOOL
WINAPI
SystemParametersInfoW(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni);
#ifdef UNICODE
#define SystemParametersInfo SystemParametersInfoW
#else
#define SystemParametersInfo SystemParametersInfoA
#endif // !UNICODE
设置系统参数函数
BOOL SystemParametersInfo(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinlni);
SystemParametersInfo函数查询或设置系统级参数。函数原型是BOOL SystemParametersInfo。该函数也可以在设置参数中更新用户配置文件,这个函数还有很多其它功能,比如获取桌面工作区的大小。
#include <Windows.h>
#include <stdio.h>
//#include <stdafx.h>
int main()
{
TCHAR szStr[MAX_PATH];
TCHAR szWindowspath[MAX_PATH];
TCHAR szComputerName[20+1];
DWORD dwComputerNameLength = 20+1;
TCHAR szUserName[32];
DWORD nUserNameLength = 32;
if(GetSystemDirectory(szStr,strlen(szStr)) <= 0)
{
printf("Getsystemdirectory error,Error No:%d\n",GetLastError());
return 1;
}
printf("System path:%s\n",szStr);
GetWindowsDirectory(szWindowspath,MAX_PATH);
printf("Windows path:%s\n",szWindowspath);
GetComputerName(szComputerName,&dwComputerNameLength);
printf("computer name:%s\n",szComputerName);
GetUserName(szUserName,&nUserNameLength);
printf("User name:%s\n",szUserName);
BOOL fResult = false;
int aMouseInfo[3];
fResult = SystemParametersInfo(SPI_GETMOUSE,0,&aMouseInfo,0);
if(fResult)
{
aMouseInfo[2] *= 2;
SystemParametersInfo(SPI_SETMOUSE,0,aMouseInfo,SPIF_SENDCHANGE);
}
SERIALKEYS keys;
SystemParametersInfo(SPI_GETPOWEROFFACTIVE,1,&keys,sizeof(keys));
printf("mouse chaned ok!\n");
return 0;
}
单于大爷
发布了25 篇原创文章 · 获赞 1 · 访问量 6321
私信
关注