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. MFC threading issue...

MFC threading issue...

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpphpcomregex
2 Posts 1 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.
  • T Offline
    T Offline
    the_augy
    wrote on last edited by
    #1

    I am trying to pop up a dialog to loop a gif image while my program does processing work. The problem is, the thread I'm creating doesn't pop up as soon as it's created, and placing breakpoints in InitInstance and ExitInstance reveals that they aren't being called when I call my CWinThread-drived class's CreateThread() method. What explanations exist for this behavior? I have tried versions of my CWinThread class which do and don't override the Run() method. It's a very simple problem which hopefully has a very simple solution =] I found an article[^] on code guru that deals with my exact issue. I've tried to imitate the behavior of my code to match the article's code as much as possible, but I still cannot get the thread to work. Here is the .cpp file of my CWinThread class, CInterface IMPLEMENT_DYNCREATE(CInterface, CWinThread) int CInterface::ExitInstance() { return CWinThread::ExitInstance(); } BOOL CInterface::InitInstance() { return TRUE; } void CInterface::KillInterface() { if (m_pD.m_hWnd) { m_pD.PostMessage(WM_COMMAND, IDCANCEL); } } int CInterface::Run() { m_pD.DoModal(); if (m_pParent) m_pParent->PostMessage(WM_KILLINTERFACING); return 0; } Any ideas? Thanks alot, augy

    T 1 Reply Last reply
    0
    • T the_augy

      I am trying to pop up a dialog to loop a gif image while my program does processing work. The problem is, the thread I'm creating doesn't pop up as soon as it's created, and placing breakpoints in InitInstance and ExitInstance reveals that they aren't being called when I call my CWinThread-drived class's CreateThread() method. What explanations exist for this behavior? I have tried versions of my CWinThread class which do and don't override the Run() method. It's a very simple problem which hopefully has a very simple solution =] I found an article[^] on code guru that deals with my exact issue. I've tried to imitate the behavior of my code to match the article's code as much as possible, but I still cannot get the thread to work. Here is the .cpp file of my CWinThread class, CInterface IMPLEMENT_DYNCREATE(CInterface, CWinThread) int CInterface::ExitInstance() { return CWinThread::ExitInstance(); } BOOL CInterface::InitInstance() { return TRUE; } void CInterface::KillInterface() { if (m_pD.m_hWnd) { m_pD.PostMessage(WM_COMMAND, IDCANCEL); } } int CInterface::Run() { m_pD.DoModal(); if (m_pParent) m_pParent->PostMessage(WM_KILLINTERFACING); return 0; } Any ideas? Thanks alot, augy

      T Offline
      T Offline
      the_augy
      wrote on last edited by
      #2

      I've stepped through my code very carefully, and I'll describe exactly what happens. Here is the high level of the code that I'm debugging. BeginInterfacing() is the function that creates the child thread which plays the animated gif file, and EndInterfacing destroys it. This code is all happening within an event handler from a dialog. m_pParent->BeginInterfacing(); m_pID->GetWindowText(m_pParent->m_strName); m_pPass->GetWindowText(m_pParent->m_strPass); m_pParent->m_strName.Remove(' '); m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName); if (!m_pParent->m_pSub->VerifyPassword(m_pParent->m_strPass)) { m_pParent->EndInterfacing(); MessageBox("Invalid Password", "Invalid Password", MB_OK|MB_ICONSTOP); delete m_pParent->m_pSub; m_pParent->m_pSub = NULL; return -1; } m_pParent->EndInterfacing(); If I step over BeginInterfacing, no dialog box comes up and none of my breakpoints are triggered (I have them in Run(), EndInterfacing(), and DoModal() of the dialog box that the child thread creates). I can step through until the line m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName); When I try to F10 over this line, my breakpoint in Run() of my CWinThread class is triggered: int CInterface::Run() { m_pD.DoModal(); if (m_pParent) m_pParent->PostMessage(WM_KILLINTERFACING); return 0; } m_pD is the dialog that will loop the gif file. Next, I step into DoModal.... if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } TRY { // create modeless dialog AfxHookWindowCreate(this); At the line ::EnableWindow(hWndParent, FALSE), execution seems to switch back to where it left off in the top level function, and m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName); gets executed next. In fact, execution never returns to where it left off in DoModal() (or any other part of the child thread) until much later, where it goes right back to bEnableParent = TRUE and then creates the modal dialog box normally, but of course it does this at a time I can't pin down and so I have this modal dialog box looping a gif without any way to stop it, so I have to CTRL+ALT+DEL the program, or stop debugging. The thing I would really like to figure out is why the thread stopped where it did (in the middle of DoModal) and then decided to start back up again when the main thread isn't doing any process

      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