tags:

views:

29

answers:

0

I'm trying to create a date-picker-like control using ATL which derives from a combobox. The idea being that I trap the CBN_DROPDOWN message and display a dialog containing (among other things) a calendar control. The dialog class is derived from CDialogImpl and just uses a dialog resource, e.g.

IDD_DIALOG1 DIALOGEX 0, 0, 112, 94
STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_BORDER
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    CONTROL "",
            IDC_MONTHCALENDAR1,
            "SysMonthCal32",
            MCS_NOTODAY | MCS_NOTODAYCIRCLE | WS_TABSTOP,
            0,0,112,84,
            WS_EX_TRANSPARENT

    *some other stuff*
END

To prevent the combobox's dropdown from getting in the way, I'm also handling the WM_CTLCOLORLISTBOX message which hides the dropdown window:

LRESULT OnCtlColorListBox(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    HWND hWnd = (HWND)lParam;

    if (hWnd != 0 && hWnd != m_hWnd) 
    {
        ::ShowWindow(hWnd , SW_HIDE);
    }

    return DefWindowProc(WM_CTLCOLORLISTBOX, wParam, lParam);
}

So far, so good. The problem is that the calendar dialog has keyboard input but NOT mouse input. It would appear that the (hidden) listbox has called SetCapture and is hogging the mouse input. Even calling PostMessage(CB_SHOWDROPDOWN, FALSE) on the combobox doesn't seem to pass mouse input to the calendar dialog. The combobox gets sent a WM_CAPTURECHANGED message, but I'm not sure where the mouse input now is.

If I click on the calendar control, then a WM_MOUSEACTIVATE message gets sent to the dialog instance, and the calendar control then gains mouse input, but this is no good since having to click TWICE on the calendar to select a date :(.

Can anyone tell me where I'm going wrong, or what I need to do to get things working as intended?

related questions