I know how to create a working ProgressBar with PBS_MARQUEE style, but I am having trouble implementing it in a situation where I want the marquee animation as long as some long_operation()
runs, without having to call SendMessage(hPB, PBM_STEPIT, 0, 0);
continuously from long_operation()
to advance the animation.
Here is one of my failed attempts:
INT_PTR CALLBACK ProgressDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message) {
case WM_INITDIALOG:
{
HWND hProgressBar = GetDlgItem(hWnd, IDC_PROGRESS1);
LONG_PTR style_flags = GetWindowLongPtr(hProgressBar, GWL_STYLE);
SetWindowLongPtr(hProgressBar, GWL_STYLE, style_flags | PBS_MARQUEE);
SendMessage(hProgressBar, (UINT)PBM_SETMARQUEE, (WPARAM)1, (LPARAM)NULL);
break;
}
}
return FALSE;
}
void long_operation() {
for(int i = 0; i < 9; ++i) {
for(int j = 0; j < 99999999; ++j)
;
Beep(5000, 100);
}
}
void do_operation() {
HWND hDlg = CreateDialog(Dll_globals::g_hInst,
MAKEINTRESOURCE(IDD_DIALOG4), // assume this contains a ProgressBar ctl
Dll_globals::g_hWndMain, ProgressDlgProc);
if(hDlg) {
ShowWindow(hDlg, SW_SHOW);
UpdateWindow(hDlg);
}
long_operation();
}
What I get with the code above is a marquee progress bar without any animation while beeping continues, and then a normal animated marquee when it stops.
As far as I understand, since long_operation()
blocks the thread, message queues are blocked as well, and the default 30ms update message is not sent to/received by the ProgressBar control.
I feel there must be an intuitive way to do this, but I can't figure it out.
What it way to go about this?