绑定wxEVT_CHAR_HOOK在 wxWidgets 3.1.2 中不起作用
Binding wxEVT_CHAR_HOOK not working in wxWidgets 3.1.2
我试图在每次按下键时调用一个函数。由于某种原因,我无法将wxEVT_CHAR_HOOK事件绑定到函数。 创建按钮并在按下按钮时将按钮绑定到函数没有问题。 我正在使用Visual Studio 2017和wxWidgets 3.1.2
我已经尝试与wxEVT_KEY_DOWN交换wxEVT_CHAR_HOOK,但这不起作用。 但是,将同一函数与另一个事件(如wxEVT_BUTTON)绑定确实有效。
enum
{
ID_Hello = wxID_HIGHEST + 1,
ID_Button1 = wxID_HIGHEST + 2,
ID_Panel1 = wxID_HIGHEST + 3
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "Hello World")
{
panel1 = new wxPanel(this, ID_Panel1, wxDefaultPosition, wxDefaultSize);
wxSize buttonSizeHelloWorld = wxSize(200, 200);
wxPoint buttonPosHelloWorld = wxPoint(50, 50);
HelloWorldButton = new wxButton(panel1, ID_Button1,
"Hello", buttonPosHelloWorld, buttonSizeHelloWorld);
//These work fine
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
Bind(wxEVT_BUTTON, &MyFrame::OnExit, this, ID_Button1);
//This is what fails
Bind(wxEVT_CHAR_HOOK, &MyFrame::ProcessKeypress, this);
}
void MyFrame::ProcessKeypress(wxCommandEvent& event) {
wxLogMessage("A key was pressed");
}
void MyFrame::OnHello(wxCommandEvent& event)
{
wxLogMessage("Hello world from wxWidgets!");
}
void MyFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
错误消息(我搜索了它,但没有找到有用的东西):
C2664 "void wxEventFunctorMethod::CheckHandlerArgument(EventArg *)" : 无法将"wxKeyEvent *"的参数 1 转换为 "EventArg *" (event.h -> 行: 374)
wxEVT_CHAR_HOOK
的处理程序必须接受wxKeyEvent&
参数而不是wxCommandEvent&
,错误消息告诉您这正是这一点(您还应该看到编译器输出中wxCommandEvent
EventArg
)。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- 我正在开发服务器,ip作为参数传递不起作用