OS : Windows 7 32 bit Developping Tool : Visual Studio 2008
Problem : When run at Windows 7 it's ok, but at XP there is assertion error at DEBUG mode, invisible grid control error at RELEASE mode. (like you can see it as pictures below)
Situation :
The grid control class, I used for the program, was downloaded from code-project. (I think I can't upload the file in stackoverflow? If you need it, plz tell me.)
I used to use this class in VS 6.0. It's my first time using it in VS 9.0. There was no error when I used it in VS 6.0.
There is no compiling error when I compile the program in Windows 7 and XP.
On Windows 7, it runs well both at DEBUG and RELEASE mode.
On Windows XP, running exe file in the DEBUG folder gives an assertion error. And when I run exe file in the RELEASE folder, the grid control doesn't show up.
And I also tried to compile on XP with Visual Studio to see if there is any error, but it only gives run-time error.
Error :
Debug Assertion Failed! Program : ... File : .../gridctrl_src/gridcell.cpp Line : 228
For information on how your program can cause an assertion failure, see the Visual C+ documentation on asserts.
The below is gridcell.cpp source code at the error line.
开发者_开发技巧/////////////////////////////////////////////////////////////////////////////
// CGridDefaultCell
CGridDefaultCell::CGridDefaultCell()
{
#ifdef _WIN32_WCE
m_nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX;
#else
m_nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX | DT_END_ELLIPSIS;
#endif
m_crFgClr = CLR_DEFAULT;
m_crBkClr = CLR_DEFAULT;
m_Size = CSize(30,10);
m_dwStyle = 0;
#ifdef _WIN32_WCE
LOGFONT lf;
GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
SetFont(&lf);
#else // not CE
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));
SetFont(&(ncm.lfMessageFont));
#endif
}
Thank you in advance!!
I encountered the same issue with CGridCtrl while porting a project from VC6 to VS2012.
In your project set _WIN32_WINNT
to the lowest target platform you want your application to support. That's 0x0501
for XP SP1.
No code changes should be required in CGridDefaultCell.
Related discussion on MSDN
Answer my own question...
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ...) problem
// Initially use the system message font for the GridCtrl font
NONCLIENTMETRICS ncm;
memset(&ncm,0,sizeof(NONCLIENTMETRICS));
ncm.cbSize = sizeof(NONCLIENTMETRICS);
#if (WINVER >= 0x0600)
ncm.cbSize -= 4; //<== ADD HERE!!
#endif
BOOL f = SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS), &ncm, 0);
VERIFY(f);
if(f){
memcpy (&m_LogFont, &ncm.lfMessageFont, sizeof (LOGFONT));
m_LogFont.lfHeight = -MulDiv (11, dc.GetDeviceCaps (LOGPIXELSY), 72);
m_LogFont.lfWeight = FW_NORMAL;
m_LogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
m_LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
m_LogFont.lfQuality = DEFAULT_QUALITY;
m_LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
m_LogFont.lfCharSet = ANSI_CHARSET;
_tcscpy (m_LogFont.lfFaceName, _T ("Courier New"));
}
精彩评论