All pastes #907684 Raw Edit

gtk screenshot

public text v1 · immutable
·published 2008-02-17 20:51 UTC
rendered paste body
#include <gtkmm.h>
#include <iostream>

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<Gdk::Drawable> drawable = get_window ();
        Glib::RefPtr<Gdk::Pixbuf> 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;
}