为什么win32 api停止显示窗口 [英] Why does win32 api stop showing windows

查看:76
本文介绍了为什么win32 api停止显示窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Win32 API Windows程序,它显示包含法语文档的txt文件。我可以单击一个单词,程序将读取一个字典文件,打开一个编辑窗口并显示英文定义,类型和时态。几次请求后,程序停止显示结果。事实上,任何鼠标点击似乎都没有结果(包括单击工具栏和滚动条)。单击鼠标右键应该会显示MessageBox,但不会。

在跟踪我的程序时,我发现该程序的行为似乎正在运行但没有弹出窗口,也没有显示任何显示的文本。

我重用了编辑窗口,只需调整大小并移动它,(而不是删除它并为每个定义重新创建它),所以我尝试在需要时创建它并在完成后删除它,但没有更改。

我还创建了一个启动时全局字体并在需要时应用它,所以我尝试了没有字体,但没有改变。

当我用CodeBlocks编译时,程序在大约45个请求后停止显示。当我使用DevCpp进行编译时,问题发生在大约20个请求之后。我还监视了GlobalMemoryStatus,但似乎有很多内存,所以我不能把它归结为内存泄漏。这几乎就像我已经用完了一些窗口结构,但我不知道是什么?

这个程序大约是1300行,所以我不知道是否有一个子集可以说明如果我知道可能会有什么帮助,我会张贴选定的代码块。

任何人都有任何建议吗?



我尝试了什么:



删除不需要的字体,重复使用对话框,不需要的画笔,不同的编译器。

I have a Win32 API windows program that displays a txt file that contains a French document. I can click on a word and the program will read a dictionary file, open an edit window and display the English definition, type, and tense. After several requests the program stops displaying the results. In fact, any mouse clicks appear to have no results (including clicking the tool bar and the scroll bar). A right mouse button click should cause a MessageBox to appear but does not.
In tracing my program I see that the program is behaving as though it is working but no windows pop up nor does any displayed text appear.
I reuse the edit window and simply resize it and move it around, (rather than deleting it and recreating it for each definition), so I tried creating it when needed and deleting it when done, but no change.
I also create a global font on startup and apply it when needed so I tried it without the font but again no change.
When I compile with CodeBlocks the program stops displaying after about 45 requests. When I compile with DevCpp the problem occurs after about 20 requests. I’ve also monitored the GlobalMemoryStatus but there appears to be lots of memory so I can’t put it down to a memory leak. It’s almost as if I’ve run out of some windows structure but I don’t know what?
The program is ~1300 lines so I don’t know if there is a subset that might illustrate the cause but will post selected code blocks if I know what might help.
Anyone have any suggestions?

What I have tried:

removing unneeded fonts, reuse of dialogs, unneeded brushes, different compilers.

推荐答案

首先:如果您创建系统资源,如文件或字体句柄,则必须在使用后释放它。对于HFONT,您必须调用 DeleteObject



工具 Process Explorer 可以帮助您找到问题所在。当我读到你的文字时,我想,也许有些文件不会被关闭,你最终得到许多文件句柄或一些阻止文件API。



如果不是这样的话理查德完全正确,你将不得不使用调试器。首先,您必须了解程序的工作流程并添加一些日志消息,并且可能有助于切换一些代码路径以找到错误。
First: if you create a system resource, like a file or a font handle you must free it after use. For a HFONT you must call DeleteObject.

The tool Process Explorer from Microsoft could help you to find the problem. As I read your text I guess, that maybe some files wont be closed and you end up with to many file handles or some blocking file API.

If it isnt so easy than is Richard completly right, that you will have to work with the debugger. At first you must understand the workflow of the program and add some logging messages, and maybe it helps to switch out some code pathes to find the bug.


我发现了一个已定义的HBRUSH,从WM_CTLCOLORDLG返回但从未选择,{SelectObject(hdc,ywBrush)}也没有删除{DeleteObject(ywBrush)}。仔细阅读WM_CTLCOLORDLG表示我需要在不再需要时删除该对象。我让HBRUSH成为一个全局变量(mea culpa),问题就消失了。感谢所有帮助

Steve King
I found an HBRUSH that was defined and returned from a WM_CTLCOLORDLG but never selected , {SelectObject(hdc, ywBrush)} nor deleted {DeleteObject(ywBrush)}. A careful reading of WM_CTLCOLORDLG indicated I needed to delete that object when no longer needed. I made the HBRUSH a global variable (mea culpa) and the problem went away. Thanks for all the help
Steve King


这篇关于为什么win32 api停止显示窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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