无法使wxTaskBarIcon :: CreatePopupMenu()工作

时间:2015-10-27 16:07:09

标签: c++ wxwidgets

根据this documentation,您应该能够覆盖wxTaskBarIcon::CreatePopupMenu(),以便当用户右键单击该图标时,会弹出一个菜单。

然而,无论我做什么,我似乎无法强迫wxWidgets实际执行该死的方法!在这一点上,我不确定这是因为我做错了C ++继承,还是我使用wxWidgets是错误的。但它确实让我发疯了!

#include <wx/taskbar.h>
#include <wx/menu.h>
#include <wx/string.h>

class TaskBarIcon : public wxTaskBarIcon
{
private:
    wxIcon _icon;

public:
    void SetTooltip(const std::string tooltip);

protected:
    virtual wxMenu * CreatePopupMenu();
};

void TaskBarIcon::SetTooltip(const std::string tooltip)
{
    wxString wx_tooltip(tooltip.c_str(), wxConvUTF8);
    this->SetIcon(_icon, wx_tooltip);
}

wxMenu * TaskBarIcon::CreatePopupMenu()
{
    wxMenu * menu = new wxMenu();
    menu->Append(wxID_CLOSE, wxT("Exit"));
    return menu;
}

图标显示得很好,工具提示是正确的,但实际上没有任何点击它 任何东西。

1 个答案:

答案 0 :(得分:0)

我的代码中没有看到任何错误,但您没有显示如何创建图标 - 对于一个愚蠢的问题感到抱歉,但您实际上是否创建了派生的TaskBarIcon对象?

另外,我强烈建议您检查任务栏样本overrides this method。如果样本不适合你,那将是wxWidgets中的一个错误,但如果确实如此,那么希望你能找到它和你的代码之间的区别并解决后者的问题。