我试图在单行编辑控件中按下ENTER和ESC键。
当用户按下ENTER或ESC时,我想从编辑控件中取出键盘焦点并将其设置为listview控件。 Listview控件是编辑控件的兄弟。
我的目标是编写单个子类过程,可用于在主窗口和对话框中对编辑控件进行子类化。
我发现this MSDN article因为它的第二个解决方案而被认为是有用的。以下是我对代码的改编。
// subclass procedure for edit control
LRESULT CALLBACK InPlaceEditControl_SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam,
UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (message)
{
case WM_GETDLGCODE:
return (DLGC_WANTALLKEYS | DefSubclassProc(hwnd, message, wParam, lParam));
case WM_CHAR:
//Process this message to avoid message beeps.
switch (wParam)
{
case VK_RETURN:
// change focus to listview
SetFocus(hwndListView);
return 0L;
case VK_ESCAPE:
// change focus to listview
SetFocus(hwndListView);
return 0L;
default:
return ::DefSubclassProc(hwnd, message, wParam, lParam);
}
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_RETURN:
// change focus to listview
SetFocus(hwndListView);
return 0L;
case VK_ESCAPE:
// change focus to listview
SetFocus(hwndListView);
return 0L;
default:
return ::DefSubclassProc(hwnd, message, wParam, lParam);
}
break;
case WM_NCDESTROY:
::RemoveWindowSubclass(hwnd, InPlaceEditControl_SubclassProc, uIdSubclass);
return DefSubclassProc(hwnd, message, wParam, lParam);
}
return ::DefSubclassProc(hwnd, message, wParam, lParam);
}
我的改编是正确的还是我遗漏了某些东西(可能代替SetFocus
我应该WM_NEXTDLGCTL
使用Raymond Chen指出的那些?)