Question

I am working on an MDI-application, where updating a toolbar button is messing up the drawing of a drag-rectangle.

In ON_WM_LBUTTONDOWN SetCapture() is called, in ON_WM_MOUSEMOVE the drag rectangle is updated and in ON_WM_LBUTTONUP the rectangle is erased and ReleaseCapture() is called.

Most of the time this procedure works well, but when it happens that during this dragging operation a particular toolbar button switches its state from enabled to disabled, then the initial window looses focus and does not receive the WM_LBUTTONUP.

Here is a part of the callstack

MyApp.exe!MyWindow::OnCaptureChanged(CWnd * pWnd=0x00000000)
...
mfc90d.dll!CWnd::EnableWindow(int bEnable=0x00000000)  Line 352 + 0x11 bytes C++
mfc90d.dll!CMFCToolBarEditBoxButton::SetStyle(unsigned int nStyle=0x00040000)  Line 470 C++
mfc90d.dll!CMFCToolBar::SetButtonStyle(int nIndex=0x00000001, unsigned int nStyle=0x00040000)  Line 1268 C++
mfc90d.dll!CMFCToolBarCmdUI::Enable(int bOn=0x00000000)  Line 2560 C++
MyApp.exe!MyToolbar::OnUpdateButton(CCmdUI * pCmd=0x0012faa8)
...
mfc90d.dll!CWinApp::OnIdle(long lCount=0x00000000)

Since the code has been working before the software was moved to the mfc feature pack, I could imagine that the reason is a wrongly set up toolbar button (e.g. wrong window style)?

Or should I block out the call to OnIdle while I am drawing the drag-rectangle (if so, is there some standard way to achieve this?).

Était-ce utile?

La solution

Toolbars don't gain focus as far as I know. I would suspect that your update handler itself calls EnableWindow on one of your windows. Mayber you put a custom HWND in your toolbar?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top