Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CMDIChildWnd in new thread

CMDIChildWnd in new thread

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dene99970
    wrote on last edited by
    #1

    When trying to create CMDIChildWnd in a worker thread I get an ASSERT fails in winmdi.cpp: if (pParentWnd == NULL) { CWinThread *pThread = AfxGetThread(); ASSERT(pThread); CWnd* pMainWnd = pThread->m_pMainWnd; ASSERT(pMainWnd != NULL); ASSERT_KINDOF(CMDIFrameWnd, pMainWnd);//****this line fails pParentWnd = (CMDIFrameWnd*)pMainWnd; } S I guess the parent window is not being set correctly. How can this be set?

    S 1 Reply Last reply
    0
    • D dene99970

      When trying to create CMDIChildWnd in a worker thread I get an ASSERT fails in winmdi.cpp: if (pParentWnd == NULL) { CWinThread *pThread = AfxGetThread(); ASSERT(pThread); CWnd* pMainWnd = pThread->m_pMainWnd; ASSERT(pMainWnd != NULL); ASSERT_KINDOF(CMDIFrameWnd, pMainWnd);//****this line fails pParentWnd = (CMDIFrameWnd*)pMainWnd; } S I guess the parent window is not being set correctly. How can this be set?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      You *have* to create the child window in the same thread its parent was created on. My usual rule is to keep *all* windowing operations within one thread. If you need to create a window in response to an event in a worker thread, post a message across from the worker thread to the main UI thread (posting messages is allowed from worker threads to the UI thread).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups