我希望按钮的回调方法在每次单击按钮时实例化一个窗口(使用编辑器),这可能导致多个窗口同时显示编辑器。现在我很高兴只出现一个-不会出现。
也欢迎对一般FLTK和C ++编程实践发表评论。
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_Text_Buffer.H>
class MainWin : public Fl_Window {
public:
MainWin(int w, int h, const char *title);
~MainWin();
Fl_Button* gobtn;
Fl_Text_Editor* ed; // first editor included with main window
Fl_Text_Buffer* buf;
private:
static void gomthd(Fl_Widget *, void *); // "go" method
};
class AdditionalWin : public Fl_Window { // more editors if necessary
public:
AdditionalWin(int w, int h, const char *title);
~AdditionalWin();
Fl_Text_Editor *ed;
Fl_Text_Buffer *buf;
};
int main () {
MainWin win(105, 405, "main");
return Fl::run();
}
MainWin::MainWin(int w, int h, const char* title):Fl_Window(w,h,title) {
gobtn = new Fl_Button(8, 38, 35, 20, "go");
gobtn->callback(gomthd, this);
ed = new Fl_Text_Editor(6, 67, 93, 331);
buf = new Fl_Text_Buffer();
ed->buffer(buf);
end();
resizable(this);
show();
}
AdditionalWin::AdditionalWin(int w, int h, const char *title):Fl_Window(w, h, title) {
ed = new Fl_Text_Editor(6, 67, 93, 331);
buf = new Fl_Text_Buffer();
ed->buffer(buf);
end();
resizable(this);
show();
}
void MainWin::gomthd(Fl_Widget* o, void* v) {
AdditionalWin awin(105, 405, "more");
awin.position(1, 1);
awin.show(); // ??? nothing appears
}
MainWin::~MainWin(){}
AdditionalWin::~AdditionalWin(){}
答案 0 :(得分:0)
到晚会很晚,但是仍然:我认为新窗口永远不会显示,因为awin作为一个局部变量,在MainWin :: gomthd()函数返回时就被销毁了。