Gtkmm Win32 Systray Menü



  • Sehr geehrte Community

    Ich habe schon mehrere Versuche gestartet bei meinem Programm ein Systray mit Menü zu kriegen.

    Main

    int main(int argc, char** argv)
    {
    	//
    	try
    	{
    
    		Gtk::Main m(argc, argv);
    		TrayMenue t("icons\\warning.png");
    		Glib::RefPtr<Gtk::StatusIcon> pIcon = Gtk::StatusIcon::create(Gtk::Stock::CDROM);
    		pIcon->popup_menu_at_position(t.ret(), GDK_BUTTON3_MASK, NULL);
    		MainWindow w(argc, argv);
    		m.run(w);
    	}
    	catch(std::string e)
    	{
    
    	}
    	return 0;
    }
    

    Wenn ich den StatusIcon in der Main mache, kann er das Symbol laden. Ich habe versucht das StatusIcon in die Klasse TrayMenue zu packen, aber da kam immer eine Zugriffsverletzung, jetzt mache ich in der Klasse nur den Menuaufbau.

    TrayMenue.hpp

    #ifndef _TRAYMENUE_HPP
    #define _TRAYMENUE_HPP
    
    #include<gtkmm.h>
    
    class TrayMenue 
    {
    private:
    	Glib::RefPtr<Gtk::ActionGroup> act;
    	Glib::RefPtr<Gtk::UIManager> ui;
    	Gtk::EventBox mEvent;
    	Gtk::Menu *mPopUp;
    	Gtk::Label lbl;
    	Glib::ustring ui_string;
    	//Glib::RefPtr<Gtk::StatusIcon> pIcon;
    protected:
    	void on_Exit_Click();
    	void on_About_Click();
    	void on_Open_Click();
    	bool on_Button_Press(GdkEventButton* event);
    	//inline
    	inline void set_ui_string();
    public:
    	TrayMenue(Glib::ustring filename);
    	~TrayMenue(){}
    	Gtk::Menu & ret(){
    		return (*mPopUp);
    	}
    };
    
    #endif
    

    TrayMenue.cpp

    #include"TrayMenue.hpp"
    #include<iostream>
    
    void TrayMenue::set_ui_string()
    {
    	this->ui_string =
    		"<ui>"
    		"  <popup name='PopupMenu'>"
    		"    <menuitem action='ContextOpen'/>"
    		"    <menuitem action='ContextAbout'/>"
    		"    <menuitem action='ContextExit'/>"
    		"  </popup>"
    		"</ui>";
    }
    
    TrayMenue::TrayMenue(Glib::ustring filename) : lbl("ROS POS")
    {
    
    	//pIcon = Gtk::StatusIcon::create(Gtk::Stock::CDROM);
    	this->set_ui_string();
    	this->mEvent.signal_button_press_event().connect(sigc::mem_fun(*this, &TrayMenue::on_Button_Press));
    	this->mEvent.add(lbl);
    
    	//Fill Menue;
    	this->act = Gtk::ActionGroup::create();
    	this->act->add(Gtk::Action::create("ContextMenu", "Conext Menu"));
    	this->act->add(Gtk::Action::create("ContextOpen", "Open"), sigc::mem_fun(*this, &TrayMenue::on_Open_Click));
    	this->act->add(Gtk::Action::create("ContextAbout", "About"), sigc::mem_fun(*this, &TrayMenue::on_About_Click));
    	this->act->add(Gtk::Action::create("ContextExit", "Exit"), sigc::mem_fun(*this, &TrayMenue::on_Exit_Click));
    	this->ui = Gtk::UIManager::create();
    	this->ui->insert_action_group(this->act);
    	this->ui->add_ui_from_string(this->ui_string);
    	//pIcon->set_visible(true);
    	this->mPopUp = dynamic_cast<Gtk::Menu*>(this->ui->get_widget("/PopupMenu"));
    	//pIcon->popup_menu_at_position(*this->mPopUp, GDK_BUTTON2_MASK, NULL);
    	if (!mPopUp)
    	{
    		std::cout << "ERROR" << std::endl;
    		exit(1);
    	}
    }
    
    void TrayMenue::on_Exit_Click()
    {
    	Gtk::Main::quit();
    }
    
    void TrayMenue::on_About_Click(){ std::cout << "ABOUT click" << std::endl; }
    void TrayMenue::on_Open_Click(){ std::cout << "Open Click" << std::endl; }
    bool TrayMenue::on_Button_Press(GdkEventButton* event)
    {
    	if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3))
    		this->mPopUp->popup(event->button, event->time);
    	else
    		return false;
    }
    

    Was mache ich hier falsch? Warum wird das Menü nicht angezeigt?

    Ich bedanke mich schonmal

    Mit freundlichen Grüßen
    Sepultura


Log in to reply