I'm looking for basic GUi for noobs. Something like this
Code: Select all
void main (void)
{
double x=wxGetValue("Real number please:");
wxString s=wxGetString("Your name please:);
}
Code: Select all
void main (void)
{
double x=wxGetValue("Real number please:");
wxString s=wxGetString("Your name please:);
}
Code: Select all
#include "wx/wx.h"
#include <wx/numdlg.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
long number = wxGetNumberFromUser("enter number", "your prompt here", "your caption here", 1);
wxString s = wxGetTextFromUser("enter string", "your caption here", "" );
wxLogMessage("your number was %d and the string was '%s'", number, s );
return false;
}
};
IMPLEMENT_APP(MyApp)
Code: Select all
#include "wx/wx.h"
#include <wx/numdlg.h>
#include<iostream>
#include<string>
class GetNumberApp : public wxApp
{
public:
int number;
virtual bool OnInit()
{
number = wxGetNumberFromUser("enter number", "your prompt here", "your caption here", 1);
return false;
}
};
class GetTextApp : public wxApp
{
public:
wxString texte;
virtual bool OnInit()
{
texte = wxGetTextFromUser("enter number", "your prompt here", "");
return false;
}
};
class GetFileNameApp : public wxApp
{
public:
std::string fileName;
virtual bool OnInit()
{
fileName = wxFileSelector("Choose a file to open");
return false;
}
};
std::string GetFileName()
{
std::string x;
GetFileNameApp* pApp = new GetFileNameApp();
wxApp::SetInstance(pApp);
wxEntryStart(0, NULL);
wxTheApp->OnInit();
x = pApp->fileName;
// cleaning up...
wxTheApp->OnExit();
wxEntryCleanup();
return x;
}
template<class T>T GetNumber()
{
T x;
GetNumberApp* pApp = new GetNumberApp();
wxApp::SetInstance(pApp);
wxEntryStart(0, NULL);
wxTheApp->OnInit();
x = pApp->number;
// cleaning up...
wxTheApp->OnExit();
wxEntryCleanup();
return x;
}
template<>double GetNumber<double>()
{
double x;
GetTextApp* pApp = new GetTextApp();
wxApp::SetInstance(pApp);
wxEntryStart(0, NULL);
wxTheApp->OnInit();
pApp->texte.ToCDouble(&x);
// cleaning up...
wxTheApp->OnExit();
wxEntryCleanup();
return x;
}
void main(int argc,char**argv)
{
int l1 = GetNumber<int>();
std::cout << "First number "<<l1 << "\n";
double l2 = GetNumber<double>();
std::cout << "Second number " << l2 << "\n";
std::string s = GetFileName();
std::cout << "File name " << s << "\n";
// cleaning up...
}
Why do you write such thing? it sounds like insultsONEEYEMAN wrote:Hi,
On top of what doublemax said - you can't have 2 wxApp-derived classes in the project. What is the purpose?
Also, based on your responce and the code you wrote it seems you don't understand the notion of the GUI and wxWidgets in general.
I suggest your start with some basic C++ classes, then take some GUI programming classes and then move to some specific framework - i.e. MFC, wxWidgets, GTK, Qt, FLTK, etc.
Thank you.
My students don't know gui loop and have to learn some basics in C++ in console mode.doublemax wrote:This looks unnecessarily complicated. What exactly are you trying to do?
Ok closeONEEYEMAN wrote:Hi,
I didn't want to insult you. If I did - I apologize.
Going back to your question - did you look at the console sample?
Thank you.
Code: Select all
int l1 = GetNumber<int>(); // I can see a window here and press return closed
std::cout << "First number "<<l1 << "\n";
double l2 = GetNumber<double>();
std::cout << "Second number " << l2 << "\n";
std::string s = GetFileName();
std::cout << "File name " << s << "\n";
It sounds as if your solution already works?My question is then how can I write a programm using in console mode to get a result same as my video?
Code: Select all
#include "wx/wx.h"
#include <wx/numdlg.h>
#include <iostream>
int main(int argc, char **argv)
{
wxInitializer init(argc, argv);
if ( !init.IsOk() ) {
wxPrintf("Failed to initialize wxWidgets.\n");
return 1;
}
wxApp::SetInstance( new wxApp() );
long number = wxGetNumberFromUser("enter number", "your prompt here", "your caption here", 1);
wxString s = wxGetTextFromUser("enter string", "your caption here", "" );
#if 0
wxLogMessage("your number was %d and the string was '%s'", number, s );
#else
std::cout << "number "<< number << "\n";
std::cout << "string "<< s.ToAscii() << "\n";
#endif
return 0;
}