#include #include class MyButton : public Gtk::Button { public: MyButton(const Glib::ustring& label) : Gtk::Button (label) {} private: virtual void on_clicked () { std::cout << "Saving button image" << std::endl; Glib::RefPtr drawable = get_window (); Glib::RefPtr pixbuf = Gdk::Pixbuf::create (drawable, 0, 0, get_width (), get_height ()); pixbuf->save ("button.png", "png"); } }; int main (int argc, char** argv) { Gtk::Main kit (argc, argv); Gtk::Window w; MyButton b ("Take Screenshot"); w.add (b); w.show_all (); Gtk::Main::run (w); return 0; }