Question for Mr. Nickolov or Mr. Tandetnik (or anyone else who can help) - WTL Combobox subclassing and key presses

Tech-Archive recommends: Fix windows errors by optimizing your registry



Gentlemen

I posted this question to Yahoo's WTL group but regrettably I received no response. Hence I must turn here as this is my last resort. :))

I have an application that consists of several modal dialogs. This application will run on a WinCE device has 4 directional buttons (arrow keys) and an enter key. It is preferred that navigation through these screens be done via these buttons.

I understand that each control on the dialog will have the focus and must individually process each key press.

The only controls that this app is concerned with are combo and edit boxes.

I was able to successfully subclass the edit boxes and process the key presses. For example each time a down arrow key is processed, this subclassed editbox sends a message to the parent dialog which in turn will shift the focus to next z-ordered control - much like a tab button.

My problem is with the comboboxes. My first approach was to use the regular CComboBox class and get the handle to its edit box by calling GetWindow(GW_CHILD). Then I attached the previously mentioned subclassed edit box to this handle. As expected on the down arrow key press, a message was forwarded to the parent dialog. Here, when the Enter button was pressed, I sent a F5 key to the combobox so it can display its listbox. So far so good. However, as you can imagine I could not select a choice via the arrow buttons as down arrow key shifted the focus to the next control.

My next approach was to subclass the combobox itself. Please see below for details. Now no keypress messages are processed.

I'm out of ideas. :)) Can one of you gentlemen please guide me to the correct path?

Thanks very much in advance.

-----------

class CMyCombBox : public CWindowImpl<CMyCombBox, CComboBox>
{
	CContainedWindowT<CEdit> m_edit;
	CContainedWindowT<CListBox> m_listBox;
	
public:
	DECLARE_WND_SUPERCLASS(NULL, CComboBox::GetWndClassName())

	CMyCombBox() : m_edit(this, 1), m_listBox(this, 1)
	{
		
	}

	BEGIN_MSG_MAP(CMyCombBox)
		MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode)
		ALT_MSG_MAP(1)
		MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
		MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode)
	END_MSG_MAP()

LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
bHandled = FALSE;


		if (wParam == VK_DOWN)
		{

			::SendMessage( GetParent(), WM_ENTERPRESSED, GetDlgCtrlID(), 0 );

			bHandled = TRUE;
		}

		return (bHandled) ? 0 : 1;
	}

LRESULT OnGetDlgCode(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LRESULT nRet = DefWindowProc();


		if ( lParam != NULL )
		{
			LPMSG pMsg = (LPMSG) lParam;

			// We only want WM_KEYDOWN messages that are for VK_RETURNs.
			if ( ( pMsg->message == WM_KEYDOWN ))
			{
				nRet |= DLGC_WANTMESSAGE;
			}
			else if ( pMsg->message == WM_COMMAND)
			{
				int i = 0;
			}
		}

		return nRet;
	}

	
};
.


Quantcast