CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Andrew Truckle Guest

    [RESOLVED] Accessing Main Dialog within a Thread

    I have a Main Dialog with several data members.

    The situation is that I have a popup progress dialog with a cancel button and a worker thread performing the conversion.

    I need to get this worker thread to read some of the data members of the overall main dialog window.

    What is the simplest way of doing this?


  2. #2
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: Accessing Main Dialog within a Thread

    You may share them with the structure used with the worker thread, and protect access with a mutex for example;
    An other way may be to share only the handle of your main dialog, and use CWnd::FromHandle to get a pointer on it.

    HTH.

    K.

    Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

  3. #3
    Andrew Truckle Guest

    Re: Accessing Main Dialog within a Thread

    Hi Karl

    I've ended up using 2 CEvents to check for start and stopping.
    The function which calls AfxBeginThread also sets a global pointer:

    m_MainWnd = (CDxfRenDlg *)AfxGenMainWnd();

    m_MainWnd is declared at the top of the file as:

    CDxfRenDlg *m_MainWnd;

    I've tested it out and it all seems to work.



  4. #4
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: Accessing Main Dialog within a Thread

    Yes, I think you're right; I've seen this in the doc:

    "CWinThread::m_pMainWnd (value returned by AfxGetMainWnd when the app is not an OLE server)
    Remarks:
    Use this data member to store a pointer to your thread's main window object. ...In a worker thread, the value of this data member is inherited from its parent thread.

    Thanks for the precision.

    K.


    Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured