如何捕获使用Win32 API(C / C ++)的组合框“回车键”? [英] How to capture “Enter key” in combobox using WIN32 API (C/C++)?
本文介绍了如何捕获使用Win32 API(C / C ++)的组合框“回车键”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要赶上事件,当用户preSS在组合框中输入。如何抓住你。例如:
我在组合框中键入阮海防囊。之后pressing回车键,就显示一条消息:阮海防囊。
感谢你的帮助,
I want catch event when user press Enter in combobox. How to catch you. For Example: I type " Nguyen Phong Sac" in my combobox. After pressing Enter key, there is a message is displayed: " Nguyen Phong Sac". Thanks yours helps,
推荐答案
我还是想知道你在写什么样的节目,但我会给你一个例子,你问:
I still want to know what kind of program are you writing, but I will give you an example as you asked:
//Tested with Windows 7 x64, VS2012
//When Creating:
hWndComboBox = CreateWindow(WC_COMBOBOX, TEXT(""),
CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
xpos, ypos, nwidth, nheight, hwndParent, NULL, HINST_THISCOMPONENT,
NULL);
hWndEditBox = CreateWindow(WC_EDIT, TEXT(""),
CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
xpos, ypos-30, nwidth, 30, hwndParent, NULL, HINST_THISCOMPONENT,
NULL);
//Get hwnd of edit control in combobox created earlier.
HWND hwndEdit = GetWindow(hWndComboBox, GW_CHILD);
//Use SetWindowLong to create subclass, lpfnEditWndProc is original proc
lpfnEditWndProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (DWORD) SubClassProc);
//In Subclass Proc
LRESULT CALLBACK SubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_RETURN:
//Get Text&Set Text
LPTSTR buffer = new TCHAR[255];
GetWindowText(hwnd, buffer, 255);
SetWindowText(hWndEditBox, buffer);
break;
}
break;
}
return CallWindowProc(lpfnEditWndProc, hwnd, msg, wParam, lParam);
}
这篇关于如何捕获使用Win32 API(C / C ++)的组合框“回车键”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文