在新线程中创建对话框

发布于 2024-12-05 21:01:57 字数 327 浏览 3 评论 0原文

假设我使用 CreateThread 创建一个线程,并且我想要在该线程中使用模式或非模式对话框。我是否需要像我这里一样使用单独的消息循环,

while(GetMessage(&msg, 0, 0, 0)) // Get any window messages
{
    TranslateMessage(&msg); // Translate the message 
    DispatchMessage(&msg); // Dispatch the message
}

但是对于模式对话框,您不使用它,那么为什么当我创建对话框时它不能工作?

Suppose if i create a thread using CreateThread, and I want a modal or modeless dialog in that thread. Do i need to use a seperate message loop for that like I have here,

while(GetMessage(&msg, 0, 0, 0)) // Get any window messages
{
    TranslateMessage(&msg); // Translate the message 
    DispatchMessage(&msg); // Dispatch the message
}

But for modal dialog, you don't use that, so why shouldn't it work when i create a dialog?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-12-12 21:01:57

当您使用模式对话框时,它会创建自己的消息队列,这就是它的工作原理。如果您想使用无模式对话框,那么您必须自己创建一个消息队列。

来自 DialogBox 的文档:

DialogBox 宏使用 CreateWindowEx 函数创建对话框。 (snip) 并启动自己的消息循环来检索和调度对话框的消息。

When you use a modal dialog, it creates its own message queue, that's why it works. If you want to use modeless dialogs then you will have to create a message queue yourself.

From the documentation for DialogBox:

The DialogBox macro uses the CreateWindowEx function to create the dialog box. (snip) and starts its own message loop to retrieve and dispatch messages for the dialog box.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文