windows MFC中的OnInitDialog函数之后有没有调用的函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5088392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any function called after the OnInitDialog function in MFC?
提问by Suri
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?
我想在MFC中创建一个对话框后创建一个线程。Windows 是否提供了任何功能并在之后自动调用,OnInitDialog
以便我可以在其中创建我的线程?
回答by Cody Gray
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'tany such function, because there's no corresponding Windows message that is sent.)
您可以简单地在OnInitDialog
函数中创建线程。没有理由通过搜索不同的函数或将初始化代码分成两部分来使事情变得过于复杂。(也没有任何此类功能,因为没有发送相应的 Windows 消息。)
If you want to get your dialog box on the screen beforeyou create the thread, you can just show it manually using the ShowWindow
function. For example:
如果您想在创建线程之前在屏幕上显示对话框,您可以使用ShowWindow
函数手动显示它。例如:
ShowWindow(SW_SHOW);
RedrawWindow();
Also see this post by Raymond Chen: Waiting until the dialog box is displayed before doing something
另请参阅 Raymond Chen 的这篇文章:等到对话框显示后再做某事
回答by Serge Wautier
OnInitDialog()
is the main function called upon initialization (in reaction to WM_CREATE
).
OnInitDialog()
是初始化时调用的主要函数(响应WM_CREATE
)。
Why can't you create your thread in there?
为什么你不能在那里创建你的线程?
回答by Suri
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.
我已将线程优先级更改为低于正常优先级,并且当线程第一次执行时,我将线程设置为正常优先级。这工作正常。感谢您的答复。