按Enter键时如何使用C ++ Win32 API调用按钮? [英] How to invoke a button using C++ Win32 API when press the enter button?

查看:289
本文介绍了按Enter键时如何使用C ++ Win32 API调用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用c ++ win32 API创建了一个对话框...
有3个文本框,1个组合框和3个按钮...

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

现在我有2个问题...

now i have 2 problems...

1.当我按ENTER按钮时,它调用第二个按钮(ID_OK)功能,但是我想要调用第一个按钮(ID_MYBUTTON) ...

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正在使用代码来集中文本框是

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...

有人可以解决吗?

推荐答案

这可能会回答您的两个问题:
http: //blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx

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


使用DM_SETDEFID消息在对话框中设置默认按钮

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

使用WM_NEXTDLGCTL消息而不是SetFocus()

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);

这篇关于按Enter键时如何使用C ++ Win32 API调用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆