@SJ1711 There is a pretty good description of what is happening when Windows determines that an application is "Not responding" at Preventing Hangs in Windows Applications.
When your application uses SendMessage and UpdateWindow it is calling directly into the window procedure of the progress bar control and bypassing the message queue. So the long running calculation causes the application to stop pumping messages even though the progress bar may be updating.
When another application is opened Windows will send messages to your application (e.g., WM_ACTIVATEAPP, WM_ACTIVATE, etc.). Now your application has messages that are sitting in the message queue but are not being dispatched. Windows detects this and flags the application as "Not responding" and the ghost window is displayed.
Windows knows when a process is executing under a debugger and does not use the ghost window. It only appears that your application is working normally under the debugger but the same problems exist.