MFC中OnInitDialog函数之后是否有调用任何函数?
我想在MFC中创建对话框后创建一个线程。 Windows 是否提供了任何函数,并在 OnInitDialog 之后自动调用,以便我可以在其中创建线程?
I want to create a thread after the creation of a dialog box in MFC. Is there any function that Windows has provided and is automatically called after OnInitDialog
so that I can create my thread inside it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以简单地在 OnInitDialog 函数中创建线程。没有理由通过搜索不同的函数或将初始化代码分成两部分来使事情变得过于复杂。 (也没有任何这样的函数,因为没有发送相应的Windows消息。)
如果您想在创建之前在屏幕上显示对话框线程,您可以使用
ShowWindow
函数手动显示它。例如:另请参阅 Raymond Chen 的这篇文章: 等待在执行某操作之前显示对话框
You can simply create your thread in the
OnInitDialog
function. There's no reason to overcomplicate things by going and searching for a different function, or splitting your initialization code up in two pieces. (There also isn't any such function, because there's no corresponding Windows message that is sent.)If you want to get your dialog box on the screen before you create the thread, you can just show it manually using the
ShowWindow
function. For example:Also see this post by Raymond Chen: Waiting until the dialog box is displayed before doing something
OnInitDialog()
是初始化时调用的主函数(响应于WM_CREATE
)。为什么你不能在那里创建你的线程?
OnInitDialog()
is the main function called upon initialization (in reaction toWM_CREATE
).Why can't you create your thread in there?
我已将线程优先级更改为低于正常优先级,当线程第一次执行时,我将线程设置为正常优先级。这很好用。感谢您的回复。
I have changed the thread priority to below normal and when the thread executes for the first time I set the thread to normal priory. This works fine. Thanks for your response.
多年来,我们对在 MFC 对话框应用程序(最喜欢的游乐场)中绘制第一个视图图形的 OnTimer 解决方案感到不满意,这似乎是一个很好的简单解决方案:-
计时器意味着应用程序在图形发生之前已经存活了一段时间,显然 hscroll 优先发生在 WM_PAINT 消息之后,这会将图片元素擦除到空白状态,删除 initdialog 期间绘制的任何内容。
After many years of feeling unsatisifed with the OnTimer solution to draw first view graphics in an MFC dialog app (a favorite playground), this seemed like a nice simple solution:-
a timer meant that the app was alive for some time before graphics happened, and apparently hscroll is prioritized to happen just after the WM_PAINT message which would erase a picture element to its blank state, deleting anything that was drawn during initdialog.