简体   繁体   中英

Keep a thread running in a modal dialog c++ mfc

So I open a modal dialog from my main dialog through DoModal() Where should i put my thread function to keep it alive, can i put it in a constructor?. (The created dialog doesnt have any function like OnInitDialog() in my main dialog)

You can use AfxBeginThread to start thread https://docs.microsoft.com/en-us/cpp/mfc/reference/cwinthread-class?view=vs-2019 and put it in oninitdialog like

BOOL CSimpleDlg::OnInitDialog()
{
  CDialog::OnInitDialog();

  // TODO: Add extra initialization here, like AfxBeginThread 
  m_cMyEdit.SetWindowText(_T("My Name")); // Initialize control values
  m_cMyList.ShowWindow(SW_HIDE);          // Show or hide a control, etc.

  return TRUE; // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}

https://docs.microsoft.com/en-us/cpp/mfc/reference/cdialog-class?view=vs-2019#oninitdialog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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