简体   繁体   English

按Enter按钮时如何使用C ++ Win32 API调用按钮?

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

i have created a dialogbox using c++ win32 API... there are 3 text box,1 combo box and 3 buttons... 我使用c ++ win32 API创建了一个对话框...有3个文本框,1个组合框和3个按钮......

now i have 2 problems... 现在我有2个问题......

1.when i press the ENTER button,it invoke second button(ID_OK) function,but i want to invoke first button(ID_MYBUTTON)... 1.当我按下ENTER按钮时,它会调用第二个按钮(ID_OK)功能,但我想调用第一个按钮(ID_MYBUTTON)...

2.i am using the code to focus a textbox is, 2.我正在使用代码来关注文本框,

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? 谁能解决它?

This may answer both your questions: http://blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx : 这可以回答你的两个问题: 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 使用DM_SETDEFID消息在对话框中设置默认按钮

Use the WM_NEXTDLGCTL message instead of SetFocus() 使用WM_NEXTDLGCTL消息而不是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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM