How to invoke a button using C++ Win32 API when press the enter button?

∥☆過路亽.° 提交于 2020-01-06 07:45:28

问题


i have created a dialogbox using c++ win32 API... there are 3 text box,1 combo box and 3 buttons...

now i have 2 problems...

1.when i press the ENTER button,it invoke second button(ID_OK) function,but i want to invoke first button(ID_MYBUTTON)...

2.i am using the code to focus a textbox is,

SetFocus(GetDlgItem(_hwnd, IDC_NAME));

But it cant focus that dialogbox,i mean cursor position is there,but cant get any value,when i typed...

Can anyone resolve it?


回答1:


This may answer both your questions: http://blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx:

Use the DM_SETDEFID message to set the default button in a dialog

Use the WM_NEXTDLGCTL message instead of SetFocus()

// set default button
SendMessage(_hwnd, DM_SETDEFID, (WPARAM)ID_MYBUTTON, 0);
//TODO: if the former default button's style remains, update with BM_SETSTYLE

// set focus
SendMessage(_hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(_hwnd, IDC_NAME), TRUE);


来源:https://stackoverflow.com/questions/13007869/how-to-invoke-a-button-using-c-win32-api-when-press-the-enter-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!