c++ - FL_输入到字符串中

标签 c++ visual-studio-2015 fltk

您好,我是 FLTK 的新手,现在我有一个非常简单的程序,如果您运行该程序,单击“创建”,然后单击“机器人”部分,您将看到几个选项,选择一个。将打开一个新窗口,其中包含几个 FL_Input 框和一个输入按钮 我想进行回调,以便当用户按下 Enter 键时,在 FL_Input 框中输入的文本将保存到字符串中,例如有人在 FL_Input 中输入 Space head 并然后将该值分配给一个字符串。我主要不需要回调方面的帮助,只需设置一个等于 FL_Input 的字符串即可。非常感谢您的帮助

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Text_Display.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Window.H>
#include <FL/filename.H>    
#include <FL/Fl_Box.H>
#include <FL/Fl_Slider.H>
#include <string>
#include <FL/Fl_Int_Input.H>
#include <list>
#include <FL/Fl_Color_Chooser.H>
#include <vector>
#include <FL/Fl_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Tabs.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Output.H>
#include <cstdlib>
using namespace std;


void Change_CB(Fl_Widget *w, void *) {
    Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
    Fl_Menu_Item *p;
    // Change submenu name
    p = (Fl_Menu_Item*)menu->find_item("Edit/Submenu");
    if (p) p->label("New Submenu Name");
    // Change item name
    p = (Fl_Menu_Item*)menu->find_item("Edit/New Submenu Name/Aaa");
    if (p) p->label("New Aaa Name");
}
void Quit_CB(Fl_Widget *, void *) {
    exit(0);
}
void head_window(Fl_Widget *, void *) {
    Fl_Window *head = new Fl_Window(300, 200, "Head");
    Fl_Input *input = new Fl_Input(110, 0, 100, 30, "Name");
    Fl_Input *input1 = new Fl_Input(110, 40, 100, 30, "Part-Number");
    Fl_Input *input2 = new Fl_Input(110, 80, 100, 30, "Weight");
    Fl_Input *input3 = new Fl_Input(110, 120, 100, 30, "Cost");
    Fl_Button *enter = new Fl_Button(110, 160, 100, 30, "Enter");
    head->show();
}
void torso_window(Fl_Widget *, void *) {
    Fl_Window *head = new Fl_Window(350, 250, "Torso");
    Fl_Input *input = new Fl_Input(150, 0, 100, 30, "Name");
    Fl_Input *input1 = new Fl_Input(150, 40, 100, 30, "Part-Number");
    Fl_Input *input2 = new Fl_Input(150, 80, 100, 30, "Weight");
    Fl_Input *input3 = new Fl_Input(150, 120, 100, 30, "Cost");
    Fl_Input *input4 = new Fl_Input(150, 160, 100, 30, "Battery Compartments");
    Fl_Button *enter = new Fl_Button(150, 200, 100, 30, "Enter");
    head->show();
}
void locomotor_window(Fl_Widget *, void *) {
    Fl_Window *head = new Fl_Window(350, 300, "Locomotor");
    Fl_Input *input = new Fl_Input(150, 0, 100, 30, "Name");
    Fl_Input *input1 = new Fl_Input(150, 40, 100, 30, "Part-Number");
    Fl_Input *input2 = new Fl_Input(150, 80, 100, 30, "Weight");
    Fl_Input *input3 = new Fl_Input(150, 120, 100, 30, "Cost");
    Fl_Input *input4 = new Fl_Input(150, 160, 100, 30, "Speed(MPH)");
    Fl_Input *input5 = new Fl_Input(150, 200, 100, 30, "Power Consumed(W)");
    Fl_Button *enter = new Fl_Button(150, 240, 100, 30, "Enter");
    head->show();
}
void arm_window(Fl_Widget *, void *) {
    Fl_Window *head = new Fl_Window(350, 250, "Arm");
    Fl_Input *input = new Fl_Input(150, 0, 100, 30, "Name");
    Fl_Input *input1 = new Fl_Input(150, 40, 100, 30, "Part-Number");
    Fl_Input *input2 = new Fl_Input(150, 80, 100, 30, "Weight");
    Fl_Input *input3 = new Fl_Input(150, 120, 100, 30, "Cost");
    Fl_Input *input4 = new Fl_Input(150, 160, 100, 30, "Power Consumed(W)");
    Fl_Button *enter = new Fl_Button(150, 200, 100, 30, "Enter");
    head->show();
}
void battery_window(Fl_Widget *, void *) {
    Fl_Window *head = new Fl_Window(350, 250, "Battery");
    Fl_Input *input = new Fl_Input(150, 0, 100, 30, "Name");
    Fl_Input *input1 = new Fl_Input(150, 40, 100, 30, "Part-Number");
    Fl_Input *input2 = new Fl_Input(150, 80, 100, 30, "Weight");
    Fl_Input *input3 = new Fl_Input(150, 120, 100, 30, "Cost");
    Fl_Input *input4 = new Fl_Input(150, 160, 100, 30, "Energy Stored");
    Fl_Button *enter = new Fl_Button(150, 200, 100, 30, "Enter");
    head->show();
}
void manual_window(Fl_Widget *, void *) {
    Fl_Window *win = new Fl_Window(400, 275);
    Fl_Text_Buffer *buff = new Fl_Text_Buffer();
    Fl_Text_Display *disp = new Fl_Text_Display(20, 20, 350 , 250 , "Manual");
    disp->buffer(buff);
    win->resizable(*disp);
    win->show();
    buff->text("You may click the file button to open a dropdown\nmenu and you will get a button to exit the window\nor press CTRL + v\n"
        "You may click create and you get two options either\nto make a robot part or robot model\n"
        "Clicking on robot part that shows the parts you may\ncreate and their associated shortcuts\n"
        "If you have any questions click help then click on\nmanual to open the manual\n"
            );
        win->show();
}

int main() {
    Fl_Window *win = new Fl_Window(600, 300, "Robot Shop" );
    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, 600, 25);
    menu->add("File/Quit", FL_CTRL + 'v', Quit_CB);
    menu->add("Create/Robot Part/Head" , FL_CTRL + 'h' , head_window );
    menu->add("Create/Robot Part/Torso" , FL_CTRL + 't' , torso_window);
    menu->add("Create/Robot Part/Arm" , FL_CTRL + 'a' , arm_window);
    menu->add("Create/Robot Part/Battery" , FL_CTRL + 'b' , battery_window);
    menu->add("Create/Robot Part/Locomotor" , FL_CTRL + 'l' , locomotor_window);
    menu->add("Create/Robot Model");
    menu->add("Help/Manual", FL_CTRL + 'm' , manual_window);

    win->show();
    return(Fl::run());
}

最佳答案

抱歉,这来晚了,但我认为下面的方法会起作用。

Fl_Input * inp1; //This is a global declaration 
Fl_Button * sav1;
static void sav1_cb(Fl_Button *theButton, void*) // The callback function
{
    string Surname = inp1 -> value();
cout << Surname;
}

inp1 = new Fl_Input (170+100, 50, 200, 20,"Surname"); // The input field which must be in a window
sav1 = new Fl_Button (170+310, 50 + 280, 100, 30,"Save"); // The save button
    sav1->callback((Fl_Callback*)sav1_cb); //Attaching the callback to the save button

需要注意的是,“value()”函数是我用来操作输入字段中存储或写入的数据的函数。这只是一个示例。 希望能帮助到你。

关于c++ - FL_输入到字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40498090/

相关文章:

c++ - Fltk 窗口等待

C++ set 和 shared_ptr

c++ - 如果 Outer 类是我的 friend ,那么 Outer::Inner 类也是吗?

c++ - Wl,--stack,4194304 错误 Visual Studio/CMake

msbuild - DNP 项目的 Sonarqube 分析

c++ - 如何从 MS VS 中的大量 .c 和 .h 文件编译静态库

c++ - Qt 安全删除设备

c++ - 如何使用模板根据数据类型调用函数?

c++ - 错误 : expression must have constant value. 对于一个明显的常量值

c++ - FLTK简单动画