dimanche 2 août 2015

Gtkmm - always same image when taking screenshot

I have a small c++ (c++11) program that screenshots the whole screen and save it in a file when a button is clicked

Here is my code:

#include <iostream>
#include <gtkmm.h>
using namespace Gtk;

class MainWindow : public Window
{
public:
    MainWindow(): m_button("Take Screen Shot")
    {

        add(m_button);

        m_button.signal_clicked().connect(std::bind(&MainWindow::on_mouse_clicked, this));
        m_button.show();
    }

    virtual ~MainWindow() {};
protected:
    void on_mouse_clicked()
    {
        auto root = Gdk::Window::get_default_root_window();
        int height = root->get_height();
        int width = root->get_width();
        auto pixels = Gdk::Pixbuf::create(root, 0, 0, width, height);
        pixels->save("s.png", "png");
    }

    Button m_button;
};



int main(int argc, char *argv[])
{
    auto app = Gtk::Application::create(argc, argv);
    MainWindow mainapp;

    return app->run(mainapp);
}

The problem is: i get always the same image! the state of the screen when the app is launched. I want to get always the current state of the screen

Sorry for my bad english.

Aucun commentaire:

Enregistrer un commentaire