Dialog box shows not responding

Hi Experts,

I have a dialog based application(parent).  One of the function is to copy some files to a target directory
upon requested.  I have a small dialog(child) appears when the coping in progress.
      
m_copyDisk.Create(AmcCreateDisk::IDD, NULL);
m_copyDisk.CenterWindow(NULL);
m_copyDisk.ShowWindow(SW_SHOW);
m_copyDisk.UpdateWindow();
// do the coping here........
m_copyDisk.DestroyWindow();

The problem is when the coping process takes long time( ~1min ).  When this happens, the parent dialog and the child displays "Not Responding" in the title bar.  How can I prevent this from happening.  
LVL 1
thaneshAsked:
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.

thaneshAuthor Commented:
May be I should be handling the coping in another thread?
0
List244Commented:
Changing a loop from:
      for(;;)
      {
      }
to:
      for(;;)
      {
            MSG Msg;
            while(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
            {
                  if (Msg.message == WM_QUIT)break;
                  TranslateMessage(&Msg);
                  DispatchMessage(&Msg);
            }
      }

Should solve your issue, you just need to continue handling the windows messages during your process, or Windows
will display that you are , "not responding"
0
List244Commented:
That is if your process can be broken up to allow message handling inside.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

AlexFMCommented:
Using worker thread is the best option, though it requires some additional programming. Without worker thread, you can periodically call DoEvents function which handles pending messages:

void DoEvents()
{
      MSG oMSG;
      while(::PeekMessage(&oMSG, NULL, 0, 0, PM_NOREMOVE))
      {
            if(::GetMessage(&oMSG, NULL, 0, 0))
            {
                  ::TranslateMessage(&oMSG);
                  ::DispatchMessage(&oMSG);
            }
            else
            {
                  break;
            }
      }
}

You can call DoEvents after every file.

Possibly simplest way is using SHFileOperation function which shows animated progress window exactly like Windows Explorer does.
0
List244Commented:
I can see a problem with copying in another thread.  You have to remember that if you do this, your program will continue.
So you need to be sure that with the copying being background, your programs continuation is not going to disrupt or disturb
this in anyway.
0
thaneshAuthor Commented:
I should have put it this way.  The coping is done by a function call. There is no
loop in the code.  I am using the SHFileOperation( ) as below.


m_copyDisk.Create(AmcCreateDisk::IDD, NULL);
m_copyDisk.CenterWindow(NULL);
m_copyDisk.ShowWindow(SW_SHOW);
m_copyDisk.UpdateWindow();
SHFileOperation(&sfo);
m_copyDisk.DestroyWindow();

0
List244Commented:
One suggestion I would give is to perhaps hide the window while this operation is being done.
That, or just warn them that it may appear frozen during file-processing.  Other than responding
to Windows' messages, I do not know of a way to stop the (not responding).
0
thaneshAuthor Commented:
I do not want to display the animated progress window when coping.....
0
thaneshAuthor Commented:
Hmmm.  Another question related to this one.  When coping, I noticed it is coping some
files already deleted. That is why it is taking long time to copy.  Those hidden files are not visible but SHFileOperation is actually coping some other stuffs... (like the one
with the long name with lots of numbers, some that have already deleted....)  Why?
0
thaneshAuthor Commented:
It says there is a RECYCLER directory.  I could not find it.....
0
List244Commented:
I don't use SHFileOperation, so I really can't comment on this, but if the file is deleted, it should not be able to copy.

This RECYCLER folder is a system folder.  You can view it (manually) by opening explorer, and
clicking tools >> folder options Go to the view tab then DESELECT hide operating system files.
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
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
C++

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.