Update dialog box from thread outside class

Posted on 2009-02-13
Last Modified: 2013-11-20

I need to access a dialog box from a thread outside of the dialog box class.

in portai.cpp, the thread is called like this:
m_pReaderThread = AfxBeginThread(ReaderThread, (LPVOID)this);

m_pReaderThread is declared like this in portai.h  CWinThread* m_pReaderThread;      
and the thread is declared as UINT CiPortAI::ReaderThread(LPVOID pThis)

I want to be able to update text boxes on my main dialog box from within the thread. How do I do this?
Question by:apostrophe27
    LVL 5

    Expert Comment

    cast LPVOID pThis to the class from which it was called ()pThis
    LVL 19

    Accepted Solution

    I think the best solution is to pass the handle of the dialog to the thread. Then you can post some application defined message to the dialog in order to update the user interface.

    Author Closing Comment


    It worked, and I learned about worker threads. Thanks.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Powershell based monitoring system 2 118
    post4 challenge 28 70
    zeroMAx challenge 20 66
    firstChar challenge 13 57
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now