Thread: Launching a threaded Dialog but it doesn't allow me access to the parent window

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53

    Launching a threaded Dialog but it doesn't allow me access to the parent window

    using: Microsoft VC++ and MFC

    I am trying to thread off a Dialog when I click on a button, that way I launch several dialogs from a particular Dialog.

    example:


    void CTestthreadDlg::OnButton1()
    {
    //does not allow acess to this dialog that is calling
    AfxBeginThread(ThreadFunction, tm);
    }

    void CTestthreadDlg::OnButton2()
    {
    //this dialog will allow me access to this dialog that is calling after I click my messagboxes.
    AfxMessageBox("START");
    AfxBeginThread(ThreadFunction, tm);
    AfxMessageBox("AFTER");
    }

    ///////////////////////////////////////////////////////////////////////

    UINT ThreadFunction(LPVOID pParm)
    {
    //AfxMessageBox("HELLO");
    threadManager tm;
    tm.DoModal();
    return 0;
    }

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm not too familiar with MFC but I am a little familiar with multithread apps. By default a child thread can't access the parent. You can change the SECURITY_ATTRIBUTES so that the child has access but this is assuming you are working with the NT kernel since win32 doesn't care too much about security. Also why do you need the child to have access to the parent? The child should be doing something independant of the parent thread.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Geez I hate MFC...anyway, passing info between threads isn't trivial, rather, it can be a little complicated. The simplest way to do it is to make the data global. I am not kidding! Next, you could look int CreateNamedPipe(), CreateFileMapping() and similar, which I will leave up to you to research. Finally, you can pass a pointer to the data as a message to the interested thread! However, YOU MUST SEND IT USING THE WM_COPYDATA message. Unfortunately, I do not remember how exactly to implement that, but suffice it to say: threads are not intended for "weekend programming", and if you REALLY want to use them, you do a little/lotta research
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM