SystemParametersInfo ( SPI_GETNONCLIENTMETRICS... 在VC 2008 里不能正常工作

 NONCLIENTMETRICS ncms = {0} ;


ncms.cbSize = sizeof(NONCLIENTMETRICS);
int s = sizeof(NONCLIENTMETRICS);


BOOL b = SystemParametersInfo (SPI_GETNONCLIENTMETRICS, (int)&s, &ncms, 0);


DWORD dw = GetLastError();


上面这段代码在VC 6.0 中工作正常,但是在VC 2008 里 SystemParametersInfo 返回 0,而 GetLastError 返回的却是 0

 

 


简单订正如下:
ncms.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncms.iPaddedBorderWidth);

 

实际是由于从 Vista 和 Windows Server 2008 开始 NONCLIENTMETRICS 在最后增加了iPaddedBorderWidth字段,如果你的程序打算同时支持 vista 或 XP ,Windows 2000, Windows Server 2003,那么应该先调用 GetVersionEx 检测Windows版本,然后决定是否需要减去 sizeof (ncms.iPaddedBorderWidth) ;

 


参考: http://msdn.microsoft.com/en-us/library/ms724506(VS.85).aspx


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/royer/archive/2008/12/23/3591046.aspx

 

例如:

 

// Create the font NONCLIENTMETRICS ncm = {0}; // if the application is running on Windows Server 2003 or Windows XP/2000, // subtract the size of the iPaddedBorderWidth member from the cbSize member of the NONCLIENTMETRICS structure before calling the SystemParametersInfo function. OSVERSIONINFO osvi = {0}; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); if(osvi.dwMajorVersion <6 ) ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth); else ncm.cbSize = sizeof(NONCLIENTMETRICS); VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));

你可能感兴趣的:(工作,windows,server,XP,application,structure)