Jeg har ændret lidt, ændrede linier er markeret med // changed:
#include "math.h"
#include "wx\\wx.h"
float a = 2, b, c = 2;
class Ligning:
public wxApp {
virtual bool OnInit();
};
class MyFrame:
public wxFrame {
public:
wxString T;
wxPoint P;
wxSize S;
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnRegn(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
wxTextCtrl *NumberB;
DECLARE_EVENT_TABLE()
};
enum {
ID_Quit = 1,
ID_Regn,
ID_About,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_Regn, MyFrame::OnRegn)
EVT_MENU(ID_About, MyFrame::OnAbout)
EVT_BUTTON(ID_Regn, MyFrame::OnRegn)
END_EVENT_TABLE()
IMPLEMENT_APP(Ligning)
bool Ligning::OnInit() {
MyFrame *HeadFrame = new MyFrame("Lignings løser", wxPoint(50, 50), wxSize(800, 600));
HeadFrame->Show(TRUE);
SetTopWindow(HeadFrame);
return TRUE;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size) {
wxMenu *menuFile = new wxMenu;
wxMenu *menuHelp = new wxMenu;
menuFile->Append(ID_Regn, "&Regn");
menuFile->AppendSeparator();
menuFile->Append(ID_Quit, "&Luk");
menuHelp->Append(ID_About, "A&bout");
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&Filer");
menuBar->Append(menuHelp, "&Hjælp");
wxPanel *panel = new wxPanel(this, -1);
wxPoint ButtonPos(100, 10); // Changed
wxSize ButtonSize(80, 32); // Changed
wxButton *RegnBtn = new wxButton(panel, ID_Regn, "&Regn", ButtonPos, ButtonSize); // Changed
wxPoint TextPos(10, 10); // Changed
wxSize TextSize(80, 32); // Changed
NumberB = new wxTextCtrl(panel, ID_Regn, "", TextPos, TextSize); // Changed
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText("This program is licenset to Kasper Nielsen");
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) {
Close(TRUE);
}
void MyFrame::OnRegn(wxCommandEvent& WXUNUSED(event))
{
char fasit[128];
float d, xminus, xplus, tpunkt1, tpunkt2;
wxString s = NumberB->GetValue();
// sprintf(b, "%i", s);
b = strtod(s.c_str(), 0); // Changed
d = pow(b, 2)-(4*a*c);
if(d >= 0) {
xminus = (-b-sqrt(d))/(2*a);
xplus = (-b+sqrt(d))/(2*a);
tpunkt1 = (-b)/(2*a);
tpunkt2 = (-d)/(4*a);
sprintf(fasit, "X = %f & %f", xminus, xplus);
} else {
sprintf(fasit, "Ø");
}
wxMessageBox(fasit, "Fasit", wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) {
wxMessageBox("Her kommer der snart noget", "About", wxOK, this);
}
Jeg har ændret position og størrelse på kontrollerne og ændret sprintf (der bruges til at konvertere til en streng) til en strtod.