Link to home
Start Free TrialLog in
Avatar of SGyves
SGyves

asked on

Progress Dialog

I have a progress dialog that monitors actions in a thread. The problem is that when it comes up...it takes over the program and allows nothing else to happen while it is monitoring the progress of my download. The UI locks up. The way I am updating the dialog is through messages posted by my worker thread to the main UI thread. Everytime my thread loops to get more data...it updates the dialog. Now I have done this the modeless way. How can I make it so that the user can just minimize this window and continue to do other things. Before I had the dialog..the file downloads were no problem...they were just in the background. Even if I put sleeps in the worker that posts the messages...still no control over the main UI. Can anyone help??
Avatar of AlexFM
AlexFM

Dialog is modeless and UI is unavailable? Can you describe your problem with more details and show some code?
Creating the dialog, handling thread messages, closing the dialog.
Avatar of AndyAinscow
You say you have the dialog modeless.  Just check again to make certain you don't start it with DoModal by mistake.
Maybe you require a function such as the following in your dialog

void CProgressDlg::PumpMessages()
{
    // Must call Create() before using the dialog
    ASSERT(m_hWnd!=NULL);

    MSG msg;
    // Handle dialog messages
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
      if(!IsDialogMessage(&msg))
      {
        TranslateMessage(&msg);
        DispatchMessage(&msg);  
      }
    }
}
IsDialogMessage is used for modeless dialogs.
SGyves is talking about modeless dialogs.  

from the help file
Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box.

Although the behaviour described looks as if it is a modal dialog hence my first post.  This message loop was just a wild thought, quick to try out,  as something seems to be crippling the normal message handling in his app.
In your main UI class add a dialog member as *class member* like

CStatusDlg m_dlgStatus;

You can create the status dialog window at any time like this (but creation should be from the main thread, don't call dialog create function from thread, it will block the message loop of that dialog in a delay process)

if ( !IsWindow(m_dlgStatus.m_hWnd) )
{
      m_dlgStatus.Create(IDD_STATUS_DIALOG, this);
}

In the downloading thread, you would have the pointer of the UI main thread right?

for each status, Post a message to main window

PostMessage(pMain->m_hWnd, WM_USER+101,nPercentage,0);


BEGIN_MESSAGE_MAP(CYourMainWnd, CDialog)
      //{{AFX_MSG_MAP(CYourMainWnd)
      // classwizard added message maps
      //}}AFX_MSG_MAP
      ON_MESSGAE(WM_USER+101, OnProgress)
END_MESSAGE_MAP()

void CYourMainWnd::OnProgress(WPARAM wParam, LPARAM lParam)
{
      if ( !IsWindow(m_dlgStatus.m_hWnd) )
      {
            m_dlgStatus.Create(IDD_STATUS_DIALOG, this);
      }

      m_dlgStatus.SetProgress(wParam);      <---------- THIS IS YOUR FUNCTION IN YOUR DIALOG STATUS CLASS

      m_dlgStatus.ShowWindow(SW_SHOW);
      m_dlgStatus.SetForegroundWindow();
}


Rosh :)
Avatar of SGyves

ASKER

I have something else that is majorly wrong with my program. It looks like the dialog may not be working for another reason. Let me look further into it before anyone else tries to answer this question. Basically, I need to find some way of keeping track of my downloads. Right now...my program just spawns the thread and turns it loose with no way of knowing what it is doing. I have to figure some way of keeping track of all the downloads in the main document. If anyone ahs any ideas there....that would be great. But that is what I have to try to figure out for now.
Spawn one thread per download from your doc?  Or only start the second and subsequent downloads when the first is finished?
Avatar of SGyves

ASKER

I can have as many downloads as a user wants. All at the same time.
Avatar of SGyves

ASKER

SO for every worker thread....there will be one progress dialog. Tha help at all?? Which is why I though that having the progress dialog inside the thread would have been okay.
You should do as I advised in the original thread:  
The progress dialog should not handle progress messages.  It should simply have a timer that checks the current download status, byte count, etc and updates the progrsss control during the timer handler.

-- Dan
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correction: replace hThread with DWORD nThreadID in THREAD_INFO.
Avatar of SGyves

ASKER

Damn good idea for the download progress Alex...I still might like to make it modeless though...because so many people want to be doing something else...and monitoring thier downloads. I just need to figure out how I am going to make the dialog scrollable and be able to add a so called "download" object to the list. I think I would have to have a loop to cycle through all the download info and add a dialog item for each one. So it does create another problem for me. How to make a scrolling dialog and how to make individual "info panels" (precentage, meter, etc.) that can be added to the dialog. But I really like that idea.

Also thanks for the tips on tracking my threads.
Avatar of SGyves

ASKER

Basically...I would love to hear more about how to achieve the idea in your last paragraph...
Don't search for hard ways, use list control or list box.
Avatar of SGyves

ASKER

can a progrss control be a member of a list???
Avatar of SGyves

ASKER

Wow....far beyond cool. Thank you so much for this tip. I mean...why have a window for every download when you can have a list.   :)