Automate actions on a modal form

Posted on 2005-05-12
Last Modified: 2013-11-20
I have a dialog-based application that works just fine.  Thanks to some of the folks here at Experts-Exchange I can read command line and start this app from another application.

The application opens a modal dialog.  Once the dialog is open, I want to have it perform some tasks automatically that would normally require a user to initiate from a button click.  My problem is that I don't know when the dialog is ready to begin processing, which I am defining as fully displayed and waiting for user action.

Any ideas on how I can approach this?
Question by:danhotb1
    LVL 86

    Expert Comment

    You can use 'WaitForInputIdle()' after launching the process, e.g.



    CreateProcess (..., &pi);

    WaitForInputIdle ( pi.hProcess, INFINITE);

    // do tasks

    Author Comment

    Sorry, I don't understand.  The dialog has already been opened like this:

       CMyDialog dlg;
       m_pMainForm = &dlg;
       int iResponse = dlg.DoModal();

    That is the code that Visual Studio built.  Now I need to do something inside the modal dialog after it is opened.  What process would I be waiting for and where would I put the code you describe?
    LVL 86

    Expert Comment

    Hmm - I thought you wanted to do that from the application that starts your dialog app. Am I wrong here?

    Author Comment

    No, from inside the app itself.  Here's what needs to happen:
    1.  App 1 starts App2, with command line arguments.
    2.  App2 reads the command line arguments and automatically starts a process that would usually be done by a user clicking a button.
    3.  App2 exits with a return value to App1.

    Step 2 is the problem.  Now, the process that starts is a series of steps that a user needs to respond to on the modal form, sort of like a wizard, but the process needs to start without a user clicking a button.  I just don't know when to initiate this process because I don't know when the form is open and ready for the user to click the button.


    Author Comment

    I figured it out.  Just using ::PostMessage() function in OnInitDialog().
    LVL 3

    Expert Comment

    Hi you can automate the tasks like button click on
    OnInitDialog. of Dialbox Class.

    What kind of oprations you want? or you want to wait for few seconds before anthing.

    You can also use WM_TIMER message

    Accepted Solution

    PAQed with points refunded (250)

    Community Support Moderator

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    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…
    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.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now