When you want to do things like this, what you need is, (probably), multithreading.

I say probably, because there are some fiddles you can do with sertain types of processor hogging tasks. One thing that you may be able to do is a "state machine" type solution. Here, you start your process, and let it run to a certain point when you store where you are then return control to the system, if there is nothing for the system to do, you restart from the last hold point. You may well be able to do this in your main with periodic Peeks as you suggest.

To multithread it, what you do is when your trigger event occursm rather than running the process in the windows loop, (ALWAYS a bad idea), you spin a worker thread. Your Windows loop is then free to process messages as before. Your thread can communicate it's status to the main windows loop by using PostMessage(), (in this case better than SendMessage()).

Use beginthread() to start a worker thread, (beginthreadex() if you need more control - but I doubt that). Avoid CreateThread if you are using routines in the C standard library as some of them are, or at least were not thread safe as they use local storage which is destroyed/corrupted by multiple threads, it can also leak memory.

Look up beginthread() and see if you can get a simple app to work. Be careful to have the worker thread use only it's own data. If you r main thread and worker thread are using shared data, you will need to start adding synchronisation to prevent collisions.

I had a great big tutorial on multithreading on my old web site but sadly, it is not converted to my new site yet. If I get a minute, I'll post a very simple program, (I have to dig it out of some archives which I do not have online).