如何使用WIN32 API(C/C++)在组合框中捕获"输入密钥"?

0 api winapi combobox enter key

当用户在组合框中按Enter键时,我想要捕获事件.怎么抓住你 例如:我在组合框中键入"Nguyen Phong Sac".按Enter键后,会显示一条消息:"Nguyen Phong Sac".谢谢你的帮助,

iam*_*epy 6

我还想知道你在写什么样的节目,但我会问你一个例子:

//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); 
} 
Run Code Online (Sandbox Code Playgroud)