Dialog based application MFC Programming - Modeless Dialog

Posted on 2007-10-16
Last Modified: 2013-12-14

I am working on a dialog based application. I have created a Modeless dialog box and have placed a static text control to display some text. In the main dailog application i have a button placed. On clicking this button i am creating the modeless dialog using create function and using show window function i am displaying the dialog window.The problem i am facing is the static text is not getting displayed on the modeless dialog. It just simply dislays the dialog window. Can anybody suggest what is the problem and how to handle this.

Thanks in advance.
Question by:umaiyer
    LVL 22

    Expert Comment

    where and how are you displaying static text on your dialog box ?

    It may be reason your dialog window is not fully created at the time you place static text control.Make sure your dialog window is fully created and available at the time you place static text control.


    Author Comment

    using resource i have created a new dialog with IDD_MODELESS
    I have placed a static control to display a message.

    i am adding the code snippet for On button press
    CModaless *dlg;
    dlg = new  CModaless;
    dlg->Create(IDD_MODELESS , GetDesktopWindow());
    Sleep(5000); // show the window for sometime

    Please let me know if there is any problem.
    LVL 43

    Expert Comment

    It makes clearer code if you use predefined values eg.

    Just give this a try - instead of the Sleep(5000) - this isn't good code

    CModaless *dlg;
    dlg = new  CModaless;
    dlg->Create(IDD_MODELESS , GetDesktopWindow());
    //Sleep(5000); // show the window for sometime
    DWORD dw = GetTickCount() + 5000000;
    while(GetTickCount() < dw)
    LVL 43

    Accepted Solution

    >>>Just give this a try - instead of the Sleep(5000) - this isn't good code

    The 'this isn't good code' refers to the changes I made for testing purposes, NOT to the Sleep(5000) in the original code.
    LVL 49

    Assisted Solution

    Agreed:  It is very impotant not to do a long "sleep" because nothing happens -- including screen updates or recognition of user keystrokes or mouse operations.

    When are you setting the value to display?  The normal procedure is like:

      dlg = new  CModaless;
      dlg->m_sStaticMsg="this is the text for the message";
      dlg->Create(IDD_MODELESS , GetDesktopWindow());

    When using the resource editor, click the static control, Press Ctrl=W to bring up the ClassWizard and select "Member variables"  and associate a variable (e.g., m_sStaticMsg) with the static.  You must also provide an ID for the control (other than IID_STATIC).

    Then, when the dialog is created, the nomal DDX is executed and it transfers the value from the memory variable onto the sceen automatically.

    -- Dan
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    ORA-01403: no data found 43 75
    Visual Studio C# project complains it can't run a dll 5 72
    changeXy challenge 13 40
    Path of Workbook 3 30
    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    731 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

    18 Experts available now in Live!

    Get 1:1 Help Now