Moving Window While Working

So I'm working on a hobby program to create specific backups for personal use. I ran into the problem, though, that whenever I attempt to back up particularly large amounts of data, my Window can never receive any messages due to being in a while loop copying files. Generally when I see Windows programs working, the functionality of the window itself still exists even if it doesn't let you do anything until the process finishes. How can I do this with my own window?

I have tried adding a message if statement during the while loop, but this causes some strange flickering problems with WM_PAINT being called repeatedly. Thanks again in advance!
Have you tried making your program launch the copy feature in another thread? EDIT: This would allow it to keep processing messages while the copy process is occurring.
Last edited on
You have opened a whole new level of learning for me. This... I don't even. Thank you! Very basic knowledge of C++ and Windows API has not prepared me enough to know what using other threads is. Anything I should know about compatibility with this? Anything about memory leaks? This should certainly solve many problems involving my program.
Threads can get messy, you have to know you pointers and what they actually represent. If you take this route I would suggest using CopyFileEx to do your backup because this will let you abort your "copy thread" through the callback function if the need arises.

- CopyFileEx():

- CopyProgressRoutine():
Multithreading is a lot trickier than you might expect. You have to be very careful about how you share data between threads. Generally, the fewer information that is shared between threads the better.

Just remember to put accesses to any shared data behind some sort of Mutex.
Disch brings up a good point, encapsulation should be your focus here. After a quick sketch in my head the only shared data between your main processing thread and it's child should be the "cbCancel" flag that the CopyFileEx function uses. You can either pass its address to your child thread in the fourth parameter (lpParameter) of the CreateThread function1 or you make it global (although I feel like a terrible human being for that second suggestion; for simplicity sake let's call it an option).

1: If you do this remember to make it static.
By abort my copy thread, you mean the user hitting cancel, correct? If the program terminates prematurely, does it still finish the copy if it was in another thread? Does the thread not being "closed" cause problems after the program finishes in the case of a crash?

Edit: Tested and found no to both. Also computergeek01's second post appeared.

I do think I will make it global for the time being as my program is mostly for my own sake and I've already made use of global variables only to learn how Windows API works (global handles made things easier before I learned about how to get them from a window id). It really took a lot for me to actually go through with the first global variable. I've been conditioned to never even consider using them almost as much as goto.
Last edited on
Topic archived. No new replies allowed.