2017-04-24 114 views
0

我正尝试使用列表中的图像创建按钮。我想要按钮居中。我的代码如下。我一直在'image'中得到错误“请求成员'W',它是非类类型'Fl_GIF_Image(const char *)”。我不知道我该怎么做。我认为这会给图像的宽度。有任何想法吗?带图像的FLTK按钮

// 
// source.cpp 
// labapril20 
// 
// Created by Kate Godfrey on 4/20/17. 
// Copyright (c) 2017 Kate Godfrey. All rights reserved. 
// 

#include <FL/Fl.H> 
#include <FL/Fl_Window.H> 
#include <FL/Fl_Button.H> 
#include <FL/Fl_GIF_Image.H> 
#include <iostream> 
#include <time.h> 
#include <vector> 
#include <cstdio> 

using namespace std; 

int main(int argc, char **argv) { 
    srand(time(NULL)); // set random seed based on current time 
    vector<string> filenames {"cloudy.gif","fog.gif","lightning.gif","partsunny.gif","rain.gif","sunny.gif"}; 

    string filename = filenames.at(rand() % filenames.size()); // get randome filename 
    cout << "Image File: " << filename << endl; // for debugging 

    // Start add code for image on button 
    Fl_GIF_Image image(const char* filename); 

    Fl_Window *window = new Fl_Window(image.W(), image.H()); 

    Fl_Button *button = new Fl_Button(0, 0, image.W(), image.H(), filename); 
    //button->image(); 

    //cout << image.w() << "X" << image.h() << endl; // for debugging 

    // End code for image on button 
    window->end(); 
    window->show(argc, argv); 
    return Fl::run(); 



} 
+0

我对FLTK一无所知,但为什么要使用原始拥有指针?为什么你也使用过时的rand()函数? –

+0

我有一组图像保存在一个文件夹中,我希望它随机选择其中一个图像用作按钮图像 –

+0

然后查看库。 –

回答

0

这是不容易找到谁也需要Dr.Moore的类哈哈 试试这个

Fl_Window* w = new Fl_Window(340, 180); 
Fl_GIF_Image* gif = new Fl_GIF_Image("fog.gif"); 
Fl_Button* Btn01 = new Fl_Button(20,40,gif->w(),gif->h()); 
Btn01->image(gif); 

希望工程!