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??
SGyvesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
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.
0
AndyAinscowFreelance programmer / ConsultantCommented:
You say you have the dialog modeless.  Just check again to make certain you don't start it with DoModal by mistake.
0
AndyAinscowFreelance programmer / ConsultantCommented:
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);  
      }
    }
}
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

AlexFMCommented:
IsDialogMessage is used for modeless dialogs.
0
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
Roshan DavisCommented:
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 :)
0
SGyvesAuthor Commented:
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.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Spawn one thread per download from your doc?  Or only start the second and subsequent downloads when the first is finished?
0
SGyvesAuthor Commented:
I can have as many downloads as a user wants. All at the same time.
0
SGyvesAuthor Commented:
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.
0
DanRollinsCommented:
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
0
AlexFMCommented:
Keep all created thread handles in the list or vector. Every worker thread posts user-defined message to main thread in some loop (progress) and just before finish. Main thread updates download information and removes worker thread handle from the list keeping it up-to-date. You need this list, for example, to stop all worker threads before exit or when user asks this.

Sample design:

struct THREAD_INFO
{
    HANDLE hThread;        // or CWinThread*
    int nProgress;             // 0-100
}

vector<THREAD_INFO*> m_RunningThreads;  // every started thread is added to it

User-defined message:
WM_PROGRESS_MESSAGE  
wParam - thread handle for seach in m_RunningThreads
lParam - progress indication. 100 - thread finished and may be removed from m_RunningThreads.
< 100 - update nProgress.

WM_PROGRESS_MESSAGE  is posted to main frame. If m_RunningThreads is not empty, there is some indication "Download in progress" (like icon in status bar). Double-click on such icon opens modal dialog with full list of download threads and their current state. Notice that dialog is modal: I beleive that modeless dialogs are evil and should be avoided.



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexFMCommented:
Correction: replace hThread with DWORD nThreadID in THREAD_INFO.
0
SGyvesAuthor Commented:
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.
0
SGyvesAuthor Commented:
Basically...I would love to hear more about how to achieve the idea in your last paragraph...
0
AlexFMCommented:
Don't search for hard ways, use list control or list box.
0
SGyvesAuthor Commented:
can a progrss control be a member of a list???
0
SGyvesAuthor Commented:
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.   :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.