SystemParametersInfo (SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作
2012-08-15 16:46
645 查看
在codeproject上面看见一个颜色选择控件CColourPopup, 地址是 http://www.codeproject.com/Articles/713/A-color-picker-button
这里控件看到很多人再用, 但是在这个函数里面有点小问题
上面这段代码在VC 6.0 中工作正常,但是在VC2008 + XP系统里面 SystemParametersInfo 返回 0, 因为VS2008默认你是面向Vista开发的软件, GetLastError 返回的是 0
简单订正如下:
实际是由于从 Vista 和 Windows Server 2008 开始 NONCLIENTMETRICS 在最后增加了iPaddedBorderWidth字段,如果你的程序打算同时支持 vista 或 XP ,Windows 2000, Windows Server 2003,那么应该先调用 GetVersionEx 检测Windows版本,然后决定是否需要减去 sizeof (ncms.iPaddedBorderWidth) ;
=====================================================================
NONCLIENTMETRICS 定义如下
这里控件看到很多人再用, 但是在这个函数里面有点小问题
void CColourPopup::Initialise() { //other code // Create the font NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)); m_Font.CreateFontIndirect(&(ncm.lfMessageFont)); //other code }
上面这段代码在VC 6.0 中工作正常,但是在VC2008 + XP系统里面 SystemParametersInfo 返回 0, 因为VS2008默认你是面向Vista开发的软件, GetLastError 返回的是 0
简单订正如下:
void CColourPopup::Initialise() { //other code // Create the font UINT size; NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); OSVERSIONINFO osv; osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); ::GetVersionEx(&osv); if(osv.dwMajorVersion < 6) //Vista以下的Windows ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth); size = ncm.cbSize; VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, &ncm, 0)); m_Font.CreateFontIndirect(&(ncm.lfMessageFont)); //other code }
实际是由于从 Vista 和 Windows Server 2008 开始 NONCLIENTMETRICS 在最后增加了iPaddedBorderWidth字段,如果你的程序打算同时支持 vista 或 XP ,Windows 2000, Windows Server 2003,那么应该先调用 GetVersionEx 检测Windows版本,然后决定是否需要减去 sizeof (ncms.iPaddedBorderWidth) ;
=====================================================================
NONCLIENTMETRICS 定义如下
typedef struct tagNONCLIENTMETRICSW { UINT cbSize; int iBorderWidth; int iScrollWidth; int iScrollHeight; int iCaptionWidth; int iCaptionHeight; LOGFONTW lfCaptionFont; int iSmCaptionWidth; int iSmCaptionHeight; LOGFONTW lfSmCaptionFont; int iMenuWidth; int iMenuHeight; LOGFONTW lfMenuFont; LOGFONTW lfStatusFont; LOGFONTW lfMessageFont; #if(WINVER >= 0x0600) int iPaddedBorderWidth; #endif /* WINVER >= 0x0600 */ } NONCLIENTMETRICSW, *PNONCLIENTMETRICSW, FAR* LPNONCLIENTMETRICSW;
相关文章推荐
- SystemParametersInfo ( SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作
- SystemParametersInfo ( SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作
- SystemParametersInfo ( SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作
- SystemParametersInfo ( SPI_GETNONCLIENTMETRICS...)在VC 2008 里不能正常工作
- SystemParametersInfo ( SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作
- SystemParametersInfo 在VC6.0正常,在VC 2008 里不能正常工作 的解决办法
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 出错。不同系统或者不同版本VS
- SystemParametersInfo (SPI_GETNONCLIENTMETRICS ... 返回false的原因分析
- GetSystemMetrics与SystemParametersInfo
- MFC特定函数的应用20160720(SystemParametersInfo,GetWindowRect,WriteProfileString,GetSystemMetrics)
- SystemParametersInfo GetSystemMetrics
- SystemParametersInfo获取桌面工作区域
- VC MFC 中 Class Wizard 不能正常工作的时候几种处理方法
- WatiN+Nunit在Win Server 2008 R2下不能正常工作的解决方法
- c++ winform 不能调用获取屏幕分辨率函数GetSystemMetrics的问题
- jQuery 1.4.2 getJSON() 不能正常工作的原因
- VC++获取屏幕大小第一篇 像素大小GetSystemMetrics
- jQuery 1.4.2 getJSON() 不能正常工作的原因
- VC++获取屏幕大小第一篇 像素大小GetSystemMetrics
- SystemParametersInfo 在VS 2008里异常