Alex Sokolek
Member
- Joined
- Apr 5, 2024
- Messages
- 44
- Thread Author
- #1
I have solved the problem! See the original post, "A strange problem with modeless dialog boxes", for details.
This is a repost, incorporating the latest simplifications of the problem statement, and a minimal reproducible example of the code...
I'm having a problem with modeless dialog boxes. I have one in a loop that scans files in a directory, adding the files to a linked list class for later processing, using the modeless dialog box as a progress box. When I run with the debugger, F5, it works fine. When I run without the debugger, Ctrl-F5, the box stops updating after five seconds, the mouse cursor changes to an hourglass, and the "X" button in the upper right hand corner of the windows turns dim red. This condition persists until the loop is done, at which point the program continues normally.
I have consolidated the code into a minimalist example of what is going on, using only the dialog box and the loop, which simply counts to 100, with 100 millisecond delays between iterations.
Here are my Global Variables...
and here is the Windows Proc...
I've scoured the documentation for modeless dialog boxes, and I can't find an explanation. The strange part of this is that the code works correctly when I run with the debugger, and it freezes after five seconds when I run without the debugger. Please take a look and see if I have missed something. Thank you.
This is a repost, incorporating the latest simplifications of the problem statement, and a minimal reproducible example of the code...
I'm having a problem with modeless dialog boxes. I have one in a loop that scans files in a directory, adding the files to a linked list class for later processing, using the modeless dialog box as a progress box. When I run with the debugger, F5, it works fine. When I run without the debugger, Ctrl-F5, the box stops updating after five seconds, the mouse cursor changes to an hourglass, and the "X" button in the upper right hand corner of the windows turns dim red. This condition persists until the loop is done, at which point the program continues normally.
I have consolidated the code into a minimalist example of what is going on, using only the dialog box and the loop, which simply counts to 100, with 100 millisecond delays between iterations.
Here are my Global Variables...
Code:
HWND hwndDialog1;
HDC dc;
UINT_PTR upTimer;
int wmId;
HDC hdc;
and here is the Windows Proc...
Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
hwndDialog1 = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, NULL);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case ID_TEST_FIRE:
dc = GetDC(hwndDialog1);
ShowWindow(hwndDialog1, SW_SHOW);
TCHAR sz[5];
for (int i = 1; i <= 100; ++i)
{
StringCchPrintf(sz, 5, _T("%d"), i);
SetBkColor(dc, RGB(240, 240, 240));
TextOut(dc, 50, 50, sz, lstrlen(sz));
Sleep(100);
}
upTimer = SetTimer(hWnd, 1, 2000, NULL);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_TIMER:
KillTimer(hWnd, upTimer);
ShowWindow(hwndDialog1, SW_HIDE);
break;
case WM_DESTROY:
DestroyWindow(hwndDialog1);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
I've scoured the documentation for modeless dialog boxes, and I can't find an explanation. The strange part of this is that the code works correctly when I run with the debugger, and it freezes after five seconds when I run without the debugger. Please take a look and see if I have missed something. Thank you.