Paul N
unread,Jan 4, 2012, 4:44:05 PM1/4/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I have a program to search through files. It can take quite a while
and so I have it call the following routine before each file, to give
a cancel button:
int checkbreak(HWND hWnd, int& st) {
MSG msg;
/*
while(PeekMessage(&msg, hWnd, WM_COMMAND, WM_COMMAND, PM_REMOVE))
if (LOWORD(msg.wParam) == IDD_CANCELBUTTON) return TRUE; */
while(PeekMessage(&msg, NULL, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE))
if (LOWORD(msg.wParam) == VK_ESCAPE) { st = TRUE; return TRUE; }
if (PeekMessage(&msg, hCancel, WM_LBUTTONDOWN, WM_LBUTTONDOWN,
PM_REMOVE)) { st = TRUE; return TRUE; }
if (PeekMessage(&msg, hCancel, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
SetCursor(ArrowCursor);
else if (PeekMessage(&msg, hWnd, WM_MOUSEMOVE, WM_MOUSEMOVE,
PM_REMOVE)) SetCursor(WaitCursor);
return FALSE;
}
(hWnd is the application main window, and hCancel is a handle to a
push button with Id IDD_CANCELBUTTON.)
This seems to do what I want - it allows the user to click on the
button or to press the ESC key to cancel. And the cursor changes to an
arrow over the button, as you can press it, whereas it is an hourglass
everywhere else, to show the program is busy.
It doesn't seem right, however. I would have expected the correct test
to be for a WM_COMMAND showing BN_CLICKED, but my original attempt
(commented out above) didn't seem to respond to the button being
clicked. WM_CHAR seems the correct message to respond to, rather than
WM_KEYDOWN. And when, on one attempt, I had the last two lines as:
if (PeekMessage(&msg, hWnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
SetCursor(WaitCursor);
if (PeekMessage(&msg, hCancel, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
SetCursor(ArrowCursor);
(ie opposite order and no else) the arrow cursor did not seem to
appear at all, despite that test being later.
So I would welcome any advice on how I ought to be doing it.
Many thanks.
Paul.