So my question is: I'm trying to make a "carousel" of images (select image from file, load it and display it using "next_button" or load the previous one using "previous_button"). My problem is that i have no clue how to access the same window, I have defined at main, so I can attach the selected picture. I tried passing my_Window& win but I get an error at cb_next saying that I cannot use this type (struct) Any ideas would be greatly appreciated. Thank you very much for your valuable time: Here is a sample of the code:
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();
}
It's more of a C++ question. Why is cb_next() a static method? If you make it a normal method, you can access the same struct/window you defined in main using the this
pointer. Writing this
is also optional, you already call redraw
in the next() method, which is actually this->redraw();
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.