如何把功能键绑定到按钮上。 Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
zlhgo
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Nov 12, 2008 7:05 am
Location: china

如何把功能键绑定到按钮上。

Post by zlhgo » Wed Nov 12, 2008 7:12 am

请问如何把功能键绑定到按钮上,F1-F12。
我试过gtkmm的加速键,能把单个功能键绑定到按钮上,windows 和 linux都可以的。那wxWidgets如何实现呢?
谢谢!

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Tue Dec 09, 2008 3:14 am

不好意思这么久才看到你这个帖子,不知道你还在不在。

我以前是这么做的(在MainFrame的构造函数中):

Code: Select all

    wxAcceleratorEntry entries[1];

    this->Connect( wxID_SendMessage,
                    wxEVT_COMMAND_BUTTON_CLICKED,
                    wxCommandEventHandler( MainFrame::OnSendMessage));
    entries[0] = wxAcceleratorEntry( wxACCEL_CTRL, WXK_RETURN, wxID_SendMessage);
大意是,先把一个ID跟一个事件及其回调函数相联系,然后将该快捷键与该ID相联系。

上面这段代码中,我将Ctrl+回车与MainFrame::OnSendMessage相联系了。

更多细节可参见wxAcceleratorEntry 的文档。

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

kingkamg
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Tue Apr 08, 2008 1:45 pm

Post by kingkamg » Tue Dec 09, 2008 7:32 am

:D 不错,还真没注意到有这个用法

zlhgo
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Nov 12, 2008 7:05 am
Location: china

Post by zlhgo » Sat Jan 17, 2009 6:49 am

Utensil,您好,感谢您的回复.

我试过

Code: Select all

    EVT_BUTTON( ID_BUTTON, mainwindow::OnButtonClick_ID1 )

    wxAcceleratorEntry entries[2]; 
    entries[0].Set(wxACCEL_NORMAL, WXK_F5, ID_MENU); 
    entries[1].Set(wxACCEL_CTRL, (int)'D', ID_BUTTON); 
    wxAcceleratorTable accel(2, entries); 
    SetAcceleratorTable(accel); 

Code: Select all

    wxAcceleratorEntry entries[1]; 

    this->Connect( ID_BUTTON1, 
                    wxEVT_COMMAND_BUTTON_CLICKED, 
                    wxCommandEventHandler( mainwindow::OnSendMessage)); 
    entries[0] = wxAcceleratorEntry( wxACCEL_CTRL, WXK_UP, ID_BUTTON1);
    wxAcceleratorTable accel(1, entries); 
    SetAcceleratorTable(accel); 
我试过这两种方法,不过好像这两种本质上是没有区别,呵呵.

这样好像都不能绑定到按钮上.Ctrl+Up和Ctrl+D都不行..
绑定到菜单上是可以的.

Post Reply