2

If I click anywhere on the dialog window, like in the "background", or on a Static Text, the function OnLButtonDown() is fired. But if I click a ListBox/EditBox/Combo/Calendar/Checkbox etc is not fired. I thought that because these have control variables atached to it, and the Static Text don't. But adding a new Listbox to my Dialog and testing, I see that it doesn't fire either, so now I am confused...

I added OnLButtonDown() with the Class Wizard, it appears in:

BEGIN_MESSAGE_MAP(CMFCTesting2Dlg, CDialogEx)
    ON_WM_SYSCOMMAND()
// other handlers, etc
    ON_WM_LBUTTONDOWN()
    ON_WM_LBUTTONUP()
END_MESSAGE_MAP()

My function:

void CMFCTesting2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
    AfxMessageBox(CString("BUTTON DOWN"));
    CDialogEx::OnLButtonDown(nFlags, point);
}

I tried calling CDialogEx:: ... before AfxMessageBox... but same result.

The CListBox item, has the Notify option set to True, as I seen some advices in other posts.

I suspect that the WM notification message is captured somehow by the ListBox, and not sent "forward" to my CMFCTesting2Dlg, but I understood that this should happen with the Notify option set to True, on the ListBox, no? (well, obviously, not...)

Sorry, I am new to dealing with WM in MFC.

BTW, I use Visual Studio 2010 Ultimate, and this is a Visual C++ - MFC- MFC Application - Dialog Based project.

How can I capture this mouse down event if clicked on a listbox / combo / etc?

On the LONG STORY, I am actually trying to accomplish this issue: I have two listboxes (lets say), and I want to scroll them synchronously, when user scrolls one of them, others must scroll the same (or update in the next moment). And I thought of using on mouse down to track the position of every Listbox (with the GetTopIndex), and on mouse up, to GetTopIndex again and compare with the previous ones. If a change was made, then a listbox was scrolled and then update all listboxes with SetTopIndex. The unfriendly solution for the user, but simpler for me, would be clicking a button that does this verification / update, but its not elegant at all, and it can only set them at the same level, but can't determine which one was scrolled last time. This automatically scrolling of the listboxes should be made just for displaying, it is not important the selections in the listboxes. I tried using the Message Type in the Add Event Handler for the Listbox, but none that are displayed work for my problem, KillFocus and SetFocus, are not fired if the scroll-bar is dragged, only if an item in the listbox is clicked... and I didn't succeed on the others message type either, from the Add Event Handler.

4

2 回答 2

1

至于让列表控件同步滚动,最好的办法是通过继承 CListCtrl 或 PreTranslateMessage 来拦截 WM_VSCROLL,然后在另一个列表上调用 SetScrollInfo。如果列表中的项目数相同,则应该相当简单。

于 2012-07-27T02:13:38.983 回答
1

一旦一个窗口处理了一条消息,它就会停止发送到它下面的其他窗口。静态窗口不处理鼠标按下,因此它进入对话框。其他控件都以某种方式处理它(至少设置焦点),因此它永远不会进入对话框。

您可以在每个控件中覆盖 OnLButtonDown 处理程序,以便在它们完成基类中的默认处理后执行其他操作。您可能还会在对话框的 PreTranslateMessage 方法中看到消息。

于 2012-07-26T22:46:34.170 回答