ATL CDialogImpl modal implementation of a modeless dialog RRS feed

  • General discussion

  • Hi,

    I have created a progress indicator ATL modeless dialog using CDialogImpl.
    How can I make this dialog act like a modal dialog i.e. to block the user from accessing the parent window, which could be a web page or a standalone app.
    I guess I can start the operation that I am tracking the progress of from OnInitDialog but it requires too much knowledge about the parent class.
    Any suggestions?
    Monday, January 19, 2009 10:52 PM

All replies

  • Using the Windows API, you create a modal dialog box with the function DialogBox(), and a modeless dialog box with the function CreateDialog().
    Monday, January 19, 2009 11:53 PM
  • It's already built right into CDialogImpl<>. Instead of calling CDialogImpl<>::Create(), call CDialogImpl<>::DoModal().

    Tuesday, January 20, 2009 12:13 AM
  • I know that. I need a modeless dialog because DoModal blocks until the user has dismissed the dialog by either selecting OK or Cancel (if avaiable). There is a lengthy operation going in the app thread that I need the progress indicator for. So if I do the following:
    CMyProgress dlg;  
    UINT_PTR nRet = dlg.DoModal();  
    //cannot start lengthy operation because the app is waiting for the result of DoModal 
    So instead I amdoing the following.
    CMyProgress dlg;  
    dlg.Create(hWnd, 0); 
    The progress bar in the dialog is being updated externally by parsing the object behind the lengthy_operation.

    I hope this helps.

    Tuesday, January 20, 2009 2:09 PM
  • Instead of using the dialog, why not just use the IDC_WAIT cursor, while your app is doing the lengthy operation. It's much simpler.
    Tuesday, January 20, 2009 3:02 PM
  • You can simulate modality by calling EnableWindow(FALSE) on the parent/main window.


    Tuesday, January 20, 2009 3:16 PM
  • The parent Dialog will always a Modeless Dialog and Call ,and your progress Dialog will be a Modal Dialog .Invoke your Modeless Dialog from your Parent Dialog . A Simple Approach is

    1) Create a Modal Dialog (Parent).
    2)Create a Progress Dialog()

    3) Write down some user defined function in your progress Dialog to update your progress Dialog or whatever you want.
    4) Now Create a object of your progress Dialog inside your parent dialog
    5) in your parent Dialog if you want that Progress Dialog will run on Some click then simply Create a Button and on that button simply call your DoModal() function with the help of object of progress Dialog .Now Simply Create a thread not create a thread before calling your modal progress Dialog and in thread simply call user defined function of progress Dialog by using SendMessage() or PostMessage() once you had done with your work then inside your thread Simply Send WM_CLOSE message to your progress Dialog to terminate your progress Dialog. that's all you have to do ,if you still have any problem let m know.

    Rupesh Shukla
    Tuesday, January 20, 2009 3:22 PM
  • That's a nifty workaround but it's a hack, so I don't think I'll use it.
    I will try using SetActiveWindow and then processing the messages that otherwise would have been passed to other windows.
    Thanks anyway.

    Any other ideas?
    Tuesday, January 20, 2009 4:13 PM
  •  SetActiveWindow did not do a thing to help me.
    I googled this out though.
    I will try it and report the results.
    Any other ideas are greatly appreciated.
    Tuesday, January 20, 2009 6:01 PM
  • Create a popup window that's not a dialog box, and whose owner is your main application window. This window will return control to your app, as soon as it gets created. For sure, it will get the focus, but your main app will continue executing.

    Better yet, you can also disable your main app window, while the popup is shown on top of it.
    Tuesday, January 20, 2009 7:40 PM
  • I was able to do it by following these steps:
    1. Create a modal dialog based on CDialogImpl using DoModal for instantiation.
    2. In OnInitDialog create a thread that as its callback has a method in the parent class that calls the lengthy_operation.
    3. Update the progress bar by querying the object that owns lengthy_operation in OnTimer.

    Hope that helps somebody in the future.
    Tuesday, January 20, 2009 9:52 PM