fltk 通过按钮将图像附加到窗口

时间:2021-04-20 18:13:12

标签: c++ fltk

所以我的问题是:我正在尝试制作图像的“轮播”(从文件中选择图像,加载它并使用“next_button”显示它或使用“previous_button”加载上一个)。我的问题是我不知道如何访问同一个窗口,我在 main 中定义了,所以我可以附加选定的图片。 我尝试通过 my_Window& win 但我在 cb_next 收到一个错误,说我不能使用这种类型(结构) 任何想法将不胜感激。非常感谢您的宝贵时间! 下面是代码示例:

struct my_Window : Graph_lib :: Window
{
    //Defined buttons
    //...
    //Example of how I create and call the next_button(to display the next picture)
    static void cb_next(Address, Address); // callback for next_button
    void next(); 
};

//Here is what I use to make the button work
void my_Window::cb_next(Address, Address pw)
{
    reference_to<my_Window>(pw).next(); //cannot pass my_Window
}
void my_Window::next()
{
    //Load the next picture!
    //This is where I want to attach the image
    //but when I use attach(image) it doesn't know where to attach ( as expected)
    redraw();
}
int main()
{
    my_Window win(Point(100,100),800,600,"Images");  //I want this "win" to be accessed by the next button so I can attach the new picture.
    return gui_main();
}

1 个答案:

答案 0 :(得分:0)

这更像是一个 C++ 问题。 为什么 cb_next() 是静态方法? 如果将其设为普通方法,则可以使用 this 指针访问在 main 中定义的相同结构/窗口。编写 this 也是可选的,您已经在 next() 方法中调用了 redraw,实际上是 this->redraw();

相关问题