VS 2010 C ++ DrawText函数忽略为HDC选择的字体。 [英] VS 2010 C++ DrawText function ignores font selected for HDC.

查看:144
本文介绍了VS 2010 C ++ DrawText函数忽略为HDC选择的字体。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题,我已经打了6个月。我希望其他人遇到这个问题并找到解决方案或解决方法。



我正在使用VS 2010 C ++ Express在运行64位Win 7 Home Edition的PC上开发W32应用程序。我遇到的所有这类应用程序的一个长期问题是,在使用DrawText函数渲染文本时,版本* .exe将间接替换系统字体代替指定的字体。



在IDE中的Debug下运行应用程序时,问题永远不会发生。问题只出现在以下环境中运行的版本* .exe:



偶尔从VS 2010 IDE运行

更频繁地运行托管VS 2010的同一台PC上的目录。

更频繁地在另一台PC上运行

64位Win 7专业版。

或32位Win 7家庭版

或XP w / SP3

或Win NT



问题仅发生在使用TextOut()写入其自己的窗口的Dialog回调中。所有字体都是使用引用LOGFONT结构的CreateFontIndirect()创建的。



似乎没有出现模式。该问题将仅在一次调用回调中的某些(但不是全部)DrawText()中使用。



有时问题会出现在回调的第二次或第三次调用中。在其他时候,在回调被调用20次或更多次之前不会发生问题。一次出现可能会在一次调用回调后显示,然后是多次回调调用,而不会发生任何事件。即,问题似乎与内存泄漏,堆栈溢出或堆空间不足有关。



解决方案我试过了。

(1)字体由主WinProc创建一次作为全局变量。

vs. Font通过主WinProc创建一次作为静态变量(并传递给回调)

vs.在WM_INITDIALOG下回调创建一次作为回调中的静态变量。

vs.在每次调用回调时,在回调中作为静态变量创建/销毁的字体。

vs.在每次引用DrawText()之前和之后,在回调中创建/销毁Font作为非静态变量。这个配置似乎效果最好。



(2)尝试在Linker下的堆栈大小和堆大小的所有大小值组合 - >系统。每个的最小值似乎效果最好。



有人可以帮忙吗?

解决方案

(评论提升为回答)



听起来像是GDI泄漏:)



你在销毁它之前重新选择旧字体回到DC吗? / BLOCKQUOTE>

This is a problem I have beating my head against for 6 months. I'm hoping that someone else has encountered this issue and found either a solution or a workaround.

I am using VS 2010 C++ Express to develop W32 apps on a PC running 64-bit Win 7 Home edition. A chronic problem I encounter w/ all such apps is that the release *.exe will INTERMITTENTLY substitute the system font in lieu of the specified font when rendering text using the DrawText function.

The problem never occurs while running the app under Debug in the IDE. The problem manifests only with the release *.exe running in the following environments:

Occasionally running from VS 2010 IDE
More frequently running from a directory on same PC hosting VS 2010.
Still more frequently on another PC running
64-bit Win 7 Professional Edition.
or 32-bit Win 7 Home Edition
or XP w/ SP3
or Win NT

The problem ONLY occurs in a Dialog callback that uses TextOut() to write to its own window. All fonts are created using CreateFontIndirect() referencing a LOGFONT structure.

There appears to be no pattern to occurrences. The problem will manifest only for some (but not all) uses of DrawText () in a single call to the callback.

Sometimes the problem will manifest in the 2nd or 3rd call to the callback. At other times, the problem will not occur until the callback has been called 20 or more times. A single occurrence may manifest on one call to callback followed by multiple callback calls w/o any occurrences. I.e., the issues does not appear to be related to a memory leakage, stack overflow or inadequate heap space.

Solutions I have tried.
(1) Font created one time as a global variable by main WinProc.
vs. Font created one time as a static variable by main WinProc (and passed to callback)
vs. Font created one time as a static variable in callback under WM_INITDIALOG.
vs. Font created/destroyed as a static variable in callback on each all call to callback.
vs. Font created/destroyed as a non-static variable in callback before and following each reference to DrawText (). This config seems to work best.

(2) Tried all combinations of large and small values for stack size and heap size under Linker -> System. Minimum values for each seem to work best.

Can anyone help?

解决方案

(comment promoted to answer)

sounds like a GDI leak :)

you ARE re-selecting the old font back into the DC before you destroy it?


这篇关于VS 2010 C ++ DrawText函数忽略为HDC选择的字体。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆