在onPaint函数中所有代码,在我的电脑上是正常的,可以看到三行文本,在我朋友的电脑上 只能看到第一行文本,我在save()中打印错误码,发现错误码为 2 让我很费解,为什么在我的电脑上是正常的,但是在他的电脑上就不对了。
只是有一部分用户的机器上运行异常 绝大多数用户电脑上都是正常的,有人遇到类似的问题么,求解决。
这两个函数外的 drawimage和drawline都是正常的,没有问题 可以看到图片也能看到线,所以我就更不知道哪有问题了,求解决
我有调用初始化函数
// Initialize GDI+.
GdiplusStartupInput m_gdiplusStartupInput;
GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);
LRESULT CMainDlg::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDC _dc(m_hWnd);
RECT rc;
GetClientRect(&rc);
CMemoryDC _memdc(_dc,rc);
_memdc.FillSolidRect(&rc,RGB(255,255,255));
RECT rcText={20,20,200,40};
std::wstring sTest=_T("this draw by DrawText!");
_memdc.DrawText(sTest.c_str(),sTest.length(),&rcText,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
RectF gRect(20,40,200,60);
sTest=_T("this draw by GDI+ and 255!");
Gdiplus::Graphics grap(_memdc);
Gdiplus::SolidBrush SolidBrush2(Color(255,51,51,51));
Gdiplus::FontFamily fontFamily(_T("宋体"));
Gdiplus::Font font(&fontFamily,12,Gdiplus::FontStyleRegular,Gdiplus::UnitPixel);
grap.SetSmoothingMode( SmoothingModeHighSpeed );
StringFormat _strformat;
_strformat.SetTrimming(StringTrimmingEllipsisWord);
_strformat.SetLineAlignment(StringAlignmentCenter);
Status sNext = grap.DrawString(sTest.c_str(),sTest.length(),&font,gRect,&_strformat,&SolidBrush2);
if(sNext!=S_OK)
Save(sNext);
RectF gRect2(20,60,200,80);
sTest=_T("this draw by GDI+ and 254!");
SolidBrush2.SetColor(Color(120,255,0,0));
Status sNext2 = grap.DrawString(sTest.c_str(),sTest.length(),&font,gRect2,&_strformat,&SolidBrush2);
if(sNext2!=S_OK)
Save(sNext2);
return TRUE;
}