SystemParametersInfo函数总是返回FALSE,上网查了一下,发现是NONCLIENTMETRICS的结构体大小的问题。NONCLIENTMETRICS是这样定义的
typedef struct tagNONCLIENTMETRICS {
UINT cbSize;
int iBorderWidth;
int iScrollWidth;
int iScrollHeight;
int iCaptionWidth;
int iCaptionHeight;
LOGFONT lfCaptionFont;
int iSmCaptionWidth;
int iSmCaptionHeight;
LOGFONT lfSmCaptionFont;
int iMenuWidth;
int iMenuHeight;
LOGFONT lfMenuFont;
LOGFONT lfStatusFont;
LOGFONT lfMessageFont;
#if (WINVER >= 0x0600)
int iPaddedBorderWidth;
#endif
} NONCLIENTMETRICS,
*LPNONCLIENTMETRICS;
修改方法:
ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth);
原因:
由于从 Vista 和 Windows Server 2008 开始,NONCLIENTMETRICS 在最后增加了 iPaddedBorderWidth 字段。
如果程序打算同时支持 vista 和 XP,Windows 2000, Windows Server 2003,那么应该先调用 GetVersionEx() 检测Windows版本,然后决定是否需要减去 sizeof (ncms.iPaddedBorderWidth) 。