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

This is a discussion on Launching a threaded Dialog but it doesn't allow me access to the parent window within the Windows Programming forums, part of the Platform Specific Boards category; using: Microsoft VC++ and MFC I am trying to thread off a Dialog when I click on a button, that ...

  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,643
    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:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

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, 02: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, 09:33 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21