...wait_for_button...
-
Hey Leute,
ich möchte in VC++ 2010 ein simples leeres Fenster erzeugen.
Ich nutze FLTK und habe die libs auch korekt eingetragen.
Folgender Code funktioniert demnach einwandfrei:
#include <FL/Fl.H> #include <FL/Fl_Box.H> #include <FL/Fl_Window.H> int main() { Fl_Window window(200,200,"Fenstertitel"); Fl_Box box(0,0,200,200,"Hi Daaa"); window.show(); return Fl::run(); }Nun möchte ich aber mit Hilfe eines Buches mit folgendem Code ein Fenster erzeugen:
#include "../../../Simple_window.h" #include "../../../Graph.h" #include "../../../GUI.h" #include "../../../std_lib_facilities.h" int main() { using namespace Graph_lib; Point tl(100,100); Simple_window win(tl,600,400,"Leinwand"); win.wait_for_button(); }Die 2 angehefteten Quelldateien sehen wie folgt aus:
Graph.cpp:
#include <FL/Fl_GIF_Image.H> #include <FL/Fl_JPEG_Image.H> #include "Graph.h" //------------------------------------------------------------------------------ namespace Graph_lib { //------------------------------------------------------------------------------ Shape::Shape() : lcolor(fl_color()), // Standardfarbe für Linien und Zeichen ls(0), // Standardstil fcolor(Color::invisible) // keine Füllung {} //------------------------------------------------------------------------------ void Shape::add(Point p) // ist als protected deklariert { points.push_back(p); } //------------------------------------------------------------------------------ void Shape::set_point(int i,Point p) // wird nicht verwendet; bisher nicht nötig { points[i] = p; } //------------------------------------------------------------------------------ void Shape::draw_lines() const { if (color().visibility() && 1<points.size()) // einzelnen Pixel zeichnen? for (unsigned int i=1; i<points.size(); ++i) fl_line(points[i-1].x,points[i-1].y,points[i].x,points[i].y); } //------------------------------------------------------------------------------ void Shape::draw() const { Fl_Color oldc = fl_color(); // leider gibt es keinen wirklich guten, portablen Weg den aktuellen Stil wiederherzustellen fl_color(lcolor.as_int()); //Farbe festlegen fl_line_style(ls.style(),ls.width()); // Stil festlegen draw_lines(); fl_color(oldc); // (alte) Farbe wiederherstellen (to previous) fl_line_style(0); // (Standard-)Linienstil wiederherstellen } //------------------------------------------------------------------------------ void Shape::move(int dx, int dy) // verschiebe die Form um +=dx und +=dy { for (int i = 0; i<points.size(); ++i) { points[i].x+=dx; points[i].y+=dy; } } //------------------------------------------------------------------------------ Line::Line(Point p1, Point p2) // erzeuge aus zwei Punkten ein Line-Objekt { add(p1); // füge p1 zu dieser Form hinzu add(p2); // füge p2 zu dieser Form hinzu } //------------------------------------------------------------------------------ void Lines::add(Point p1, Point p2) { Shape::add(p1); Shape::add(p2); } //------------------------------------------------------------------------------ // zeichne Verbindungslinien zwischen Punktepaaren void Lines::draw_lines() const { if (color().visibility()) for (int i=1; i<number_of_points(); i+=2) fl_line(point(i-1).x,point(i-1).y,point(i).x,point(i).y); } //------------------------------------------------------------------------------ //schneiden sich die beiden Linien (p1,p2) und (p3,p4) ? // Wenn ja, liefere den Abstand des Schnittpunkts als Abstand von p1 zurück inline pair<double,double> line_intersect(Point p1, Point p2, Point p3, Point p4, bool& parallel) { double x1 = p1.x; double x2 = p2.x; double x3 = p3.x; double x4 = p4.x; double y1 = p1.y; double y2 = p2.y; double y3 = p3.y; double y4 = p4.y; double denom = ((y4 - y3)*(x2-x1) - (x4-x3)*(y2-y1)); if (denom == 0){ parallel= true; return pair<double,double>(0,0); } parallel = false; return pair<double,double>( ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3))/denom, ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3))/denom); } //------------------------------------------------------------------------------ //Schnitt zwischen zwei Liniensegmenten //Liefert true, wenn sich die beiden Liniensegmente schneiden, //in diesem Fall wird der Schnittpunkt in intersection gespeichert bool line_segment_intersect(Point p1, Point p2, Point p3, Point p4, Point& intersection){ bool parallel; pair<double,double> u = line_intersect(p1,p2,p3,p4,parallel); if (parallel || u.first < 0 || u.first > 1 || u.second < 0 || u.second > 1) return false; intersection.x = p1.x + u.first*(p2.x - p1.x); intersection.y = p1.y + u.first*(p2.y - p1.y); return true; } //------------------------------------------------------------------------------ void Polygon::add(Point p) { int np = number_of_points(); if (1<np) { // sicherstellen, dass die neue Linie nicht parallel zu einer anderen Linie ist if (p==point(np-1)) error("Polygonpunkt ist identisch zu letztem Punkt"); bool parallel; line_intersect(point(np-1),p,point(np-2),point(np-1),parallel); if (parallel) error("Zwei Polygonpunkte liegen auf einer Linie"); } for (int i = 1; i<np-1; ++i) { // sicherstellen, dass sich das neue Segment nicht mit einer bestehenden Linie schneidet Point ignore(0,0); if (line_segment_intersect(point(np-1),p,point(i-1),point(i),ignore)) error("Poylgonlinien schneiden sich"); } Closed_polyline::add(p); } //------------------------------------------------------------------------------ void Polygon::draw_lines() const { if (number_of_points() < 3) error("weniger als 3 Punkte in Polygon"); Closed_polyline::draw_lines(); } //------------------------------------------------------------------------------ void Open_polyline::draw_lines() const { if (fill_color().visibility()) { fl_color(fill_color().as_int()); fl_begin_complex_polygon(); for(int i=0; i<number_of_points(); ++i){ fl_vertex(point(i).x, point(i).y); } fl_end_complex_polygon(); fl_color(color().as_int()); // Farbe zurücksetzen } if (color().visibility()) Shape::draw_lines(); } //------------------------------------------------------------------------------ void Closed_polyline::draw_lines() const { Open_polyline::draw_lines(); // zeichne zuerst den "offenen" Teil des Linienzugs // dann zeichne die schließende Linie: if (color().visibility()) fl_line(point(number_of_points()-1).x, point(number_of_points()-1).y, point(0).x, point(0).y); } //------------------------------------------------------------------------------ void draw_mark(Point xy, char c) { static const int dx = 4; static const int dy = 4; string m(1,c); fl_draw(m.c_str(),xy.x-dx,xy.y+dy); } //------------------------------------------------------------------------------ void Marked_polyline::draw_lines() const { Open_polyline::draw_lines(); for (int i=0; i<number_of_points(); ++i) draw_mark(point(i),mark[i%mark.size()]); } //------------------------------------------------------------------------------ void Rectangle::draw_lines() const { if (fill_color().visibility()) { //füllen fl_color(fill_color().as_int()); fl_rectf(point(0).x,point(0).y,w,h); } if (color().visibility()) { // Linien über Füllung anzeigen fl_color(color().as_int()); fl_rect(point(0).x,point(0).y,w,h); } } //------------------------------------------------------------------------------ Circle::Circle(Point p, int rr) // Mittelpunkt und Radius :r(rr) { add(Point(p.x-r,p.y-r)); // speichere die linke obere Ecke } //------------------------------------------------------------------------------ Point Circle::center() const { return Point(point(0).x+r, point(0).y+r); } //------------------------------------------------------------------------------ void Circle::draw_lines() const { if (color().visibility()) fl_arc(point(0).x,point(0).y,r+r,r+r,0,360); } //------------------------------------------------------------------------------ void Ellipse::draw_lines() const { if (color().visibility()) fl_arc(point(0).x,point(0).y,w+w,h+h,0,360); } //------------------------------------------------------------------------------ void Text::draw_lines() const { int ofnt = fl_font(); int osz = fl_size(); fl_font(fnt.as_int(),fnt_sz); fl_draw(lab.c_str(),point(0).x,point(0).y); fl_font(ofnt,osz); } //------------------------------------------------------------------------------ Axis::Axis(Orientation d, Point xy, int length, int n, string lab) : label(Point(0,0),lab) { if (length<0) error("ungueltige Achsenlaenge"); switch (d){ case Axis::x: { Shape::add(xy); // Achsenlinie Shape::add(Point(xy.x+length,xy.y)); if (1<n) { // Skalenstriche hinzufügen int dist = length/n; int x = xy.x+dist; for (int i = 0; i<n; ++i) { notches.add(Point(x,xy.y),Point(x,xy.y-5)); x += dist; } } // Beschriftung unter der Linie label.move(length/3,xy.y+20); break; } case Axis::y: { Shape::add(xy); //die y-Achse steht senkrecht Shape::add(Point(xy.x,xy.y-length)); if (1<n) { // Skalenstriche hinzufügen int dist = length/n; int y = xy.y-dist; for (int i = 0; i<n; ++i) { notches.add(Point(xy.x,y),Point(xy.x+5,y)); y -= dist; } } // Beschriftung am oberen Ende label.move(xy.x-10,xy.y-length-10); break; } case Axis::z: error("z-Achse ist nicht implementiert"); } } //------------------------------------------------------------------------------ void Axis::draw_lines() const { Shape::draw_lines(); notches.draw(); // die Skalenstriche können eine eigene Farbe verwenden label.draw(); // die Beschriftung kann eine eigene Farbe verwenden } //------------------------------------------------------------------------------ void Axis::set_color(Color c) { Shape::set_color(c); notches.set_color(c); label.set_color(c); } //------------------------------------------------------------------------------ void Axis::move(int dx, int dy) { Shape::move(dx,dy); notches.move(dx,dy); label.move(dx,dy); } //------------------------------------------------------------------------------ Function::Function(Fct f, double r1, double r2, Point xy, int count, double xscale, double yscale) // erzeugt Graph f(x) für x in [r1:r2) mithilfe von count Liniensegmenten. // (0,0) liegt auf dem Punkt xy // x-Koordinaten werden mit xscale, y-Koordinaten mit yscale skaliert { if (r2-r1<=0) error("ungueltiger Bereich fuer Graphen"); if (count <=0) error("Anzahl Liniensegmente null oder negativ"); double dist = (r2-r1)/count; double r = r1; for (int i = 0; i<count; ++i) { add(Point(xy.x+int(r*xscale),xy.y-int(f(r)*yscale))); r += dist; } } //------------------------------------------------------------------------------ bool can_open(const string& s) // prüfe, ob eine Datei namens s existiert und zum Lesen geöffnet werden kann { ifstream ff(s.c_str()); return ff; } //------------------------------------------------------------------------------ #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) Suffix::Encoding get_encoding(const string& s) { struct SuffixMap { const char* extension; Suffix::Encoding suffix; }; static SuffixMap smap[] = { {".jpg", Suffix::jpg}, {".jpeg", Suffix::jpg}, {".gif", Suffix::gif}, }; for (int i = 0, n = ARRAY_SIZE(smap); i < n; i++) { int len = strlen(smap[i].extension); if (s.length() >= len && s.substr(s.length()-len, len) == smap[i].extension) return smap[i].suffix; } return Suffix::none; } //------------------------------------------------------------------------------ // besonders sorgfältig ausgearbeiteter Konstruktor (aber Fehler in // Verbindung mit Bilddateien können so schwierig zu debuggen sein) Image::Image(Point xy, string s, Suffix::Encoding e) :w(0), h(0), fn(xy,"") { add(xy); if (!can_open(s)) { // können wir s öffnen? fn.set_label("nicht zu öffnen: \""+s+'\"'); p = new Bad_image(30,20); // das "Fehler"-Bild return; } if (e == Suffix::none) e = get_encoding(s); switch(e) { // liegt eine bekannte Codierung vor? case Suffix::jpg: p = new Fl_JPEG_Image(s.c_str()); break; case Suffix::gif: p = new Fl_GIF_Image(s.c_str()); break; default: // nicht unterstützte Bild-Codierung fn.set_label("nicht unterstützter Dateityp \""+s+'\"'); p = new Bad_image(30,20); // das "Fehler"-Bild } } //------------------------------------------------------------------------------ void Image::draw_lines() const { if (fn.label()!="") fn.draw_lines(); if (w&&h) p->draw(point(0).x,point(0).y,w,h,cx,cy); else p->draw(point(0).x,point(0).y); } //------------------------------------------------------------------------------ } //von Namensbereich Graph_libWindow.cpp:
#include "Window.h" #include "Graph.h" #include "GUI.h" //------------------------------------------------------------------------------ namespace Graph_lib { Window::Window(int ww, int hh, const string& title) :Fl_Window(ww,hh,title.c_str()),w(ww),h(hh) { init(); } //------------------------------------------------------------------------------ Window::Window(Point xy, int ww, int hh, const string& title) :Fl_Window(xy.x,xy.y,ww,hh,title.c_str()),w(ww),h(hh) { init(); } //------------------------------------------------------------------------------ void Window::init() { resizable(this); show(); } //------------------------------------------------------------------------------ void Window::draw() { Fl_Window::draw(); for (unsigned int i=0; i<shapes.size(); ++i) shapes[i]->draw(); } //------------------------------------------------------------------------------ void Window::attach(Widget& w) { begin(); // FTLK: beginne damit neue Fl_Wigets mit diesem Fenster zu verbinden w.attach(*this); // lass das Fenster seine Fl_Wigits erzeugen end(); // FTLK: das Verbinden neuer Fl_Wigets mit diesem Fenster beenden } //------------------------------------------------------------------------------ void Window::detach(Widget& b) { b.hide(); } //------------------------------------------------------------------------------ void Window::detach(Shape& s) // die zuletzt verbundene Form wird als Erstes freigegeben { for (unsigned int i = shapes.size(); 0<i; --i) if (shapes[i-1]==&s) shapes.erase(shapes.begin()+(i-1)); } //------------------------------------------------------------------------------ void Window::put_on_top(Shape& p) { for (int i=0; i<shapes.size(); ++i) { if (&p==shapes[i]) { for (++i; i<shapes.size(); ++i) shapes[i-1] = shapes[i]; shapes[shapes.size()-1] = &p; return; } } } //------------------------------------------------------------------------------ int gui_main() { return Fl::run(); } //------------------------------------------------------------------------------ }; //von Namensbereich Graph_libIch bekomme 3 Fehler:
Fehler 10 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall Simple_window::wait_for_button(void)" (?wait_for_button@Simple_window@@QAE_NXZ)" in Funktion "_main". C:\Users\Alexander\Documents\Visual Studio 2010\Projects\Buch\Buch\Main.obj
Fehler 11 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall Simple_window::Simple_window(struct Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Simple_window@@QAE@UPoint@@HHABV?char_traits@D@std@@V?$allocator@D@2@@std@@@Z)" in Funktion "_main". C:\Users\Alexander\Documents\Visual Studio 2010\Projects\Buch\Buch\Main.obj
Fehler 12 error LNK1120: 2 nicht aufgelöste externe Verweise. C:\Users\Alexander\Documents\Visual Studio 2010\Projects\Buch\Debug\Buch.exeDas "win.wait_for_button()" macht i-wie Probleme meiner Meinung nach
Wie ist das zu lösen?
Danke schonmal im Vorraus
mfg
-
Dir fehlt aber noch die Klasse für Simple_Window. In Window.cpp ist nur die Klasse Window drin (anscheinend die Basisklasse von Simple_Window).
Such mal nach Simple_Window.cpp und binde diese ebenfalls in dein Projekt ein.
-
Danke, hab ich gemacht, jetzt kommt nur noch folgender Fehler:
Fehler 18 error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void __thiscall Graph_lib::Button::attach(class Graph_lib::Window &)" (?attach@Button@Graph_lib@@UAEXAAVWindow@2@@Z)". C:\Users\Alexander\Documents\Visual Studio 2010\Projects\Buch\Buch\Simple_window.obj
Woran kann das liegen?
-
Sonst klappt alles nur der letzte Fehler noch, das wärs dann

-
Ich brauche eure Hilfe wirklich

-
Noob_der_Ersten_Stunde schrieb:
Ich brauche eure Hilfe wirklich

komisch.. du bist im falschen forum und hast nach fast 3 stunden noch immer keine antwort bekommen... wirst du wohl noch einmal schreiben müssen, dass du hilfe braucht; hier ist 3 'ne unglückszahl. da wird niemand drauf antworten !
edit: zeig mal simple_window
header und source
-
Wenn du schon im falschen Forum schreibst, dann habe wenigstens die Geduld, bis ein Mod es sieht und dich verschiebt, anstatt rumzuspammen. So provozierst du bloß die Moderatoren. Zum Beispiel mich, der ich Gespamme und Genörgel gar nicht mag. /closed