简体   繁体   English

MFC表单在单独的线程中

[英]MFC form in separate thread

I have console MFC form application that consists from one form. 我有一个表格组成的控制台MFC表格应用程序。 In MFC application contructor thread with task is started : 在具有任务的MFC应用程序构造器线程中启动:

CfbSrvApp::CfbSrvApp()
{
AfxBeginThread(MTServerThread,0);
}

MTServerThread procedure sometimes needs to show simple text input or yes/no form. MTServerThread过程有时需要显示简单的文本输入或“是/否”形式。

How to create MFC form in separate MTServerThread . 如何在单独的MTServerThread创建MFC表单。

Main form sometimes can be minimised to tray, but input forms should appear to desktop anyway. 有时可以将主窗体最小化到托盘,但是无论如何输入窗体都应该出现在桌面上。

  1. Derive a class from CWinThread. 从CWinThread派生一个类。
  2. Overwrite InitInstance 覆盖InitInstance
  3. Create the Dialog there as known with DoModal 在此处创建对话框,与DoModal相同
  4. Create the new Thread with AfxBeginThread and RUNTIME_CLASS(CYourNewCWiNThreadClass) 使用AfxBeginThread和RUNTIME_CLASS(CYourNewCWiNThreadClass)创建新线程

Main form sometimes can be minimised to tray, but input forms should appear to desktop anyway. 有时可以将主窗体最小化到托盘,但是无论如何输入窗体都应该出现在桌面上。

For what you want to achieve, it is better to create Modeless dialog in the main thread itself. 对于您要实现的目标,最好在主线程本身中创建无模式对话框。 Let the background server thread update the UI of the modeless dialog by sending messages to the main thread. 通过将消息发送到主线程,让后台服务器线程更新无模式对话框的UI。 This way you can minimize the main form in tray but still show modeless dialog. 这样,您可以最小化托盘中的主窗体,但仍显示无模式对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM