need help in c++/wxwidgets project Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Okay, there is some misunderstanding here. Nothing does not prevent you from having a main.cpp file - I have one in my wx project. I suspect you are talking about the 'int maint()' function rather than the main.cpp file. Well, simply use wxApp::OnInit() as your main() - it works the same.
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

I've read the whole thread. I think you're drowning in a glass of water (nda: french idioma). wxWidgets is nothing more than a C++ framework (in fact, C++/Python/C#/Perl).
It provides a set of classes, and an obvious part of them is aimed to design GUI.
So, the framework is built and works upon this principle : GUI application. So, no main(), but a wxApp class which has merely the same purpose.
Generally, a main() is only made of functions/methods calls. Relevant code is inside functions and methods.
That's the same thing here : wxApp class creates a wxFrame object and keeps on running into an invisible loop (the "return TRUE" at the end of wxApp code). As a GUI application is designed to wait for user commands, relevant code is in wxFrame object (and objects it uses and creates).
That's all.

All other stuff is pure C++ stuff.
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

TrV wrote:I've read the whole thread. I think you're drowning in a glass of water (nda: french idioma). wxWidgets is nothing more than a C++ framework (in fact, C++/Python/C#/Perl).
It provides a set of classes, and an obvious part of them is aimed to design GUI.
So, the framework is built and works upon this principle : GUI application. So, no main(), but a wxApp class which has merely the same purpose.
Generally, a main() is only made of functions/methods calls. Relevant code is inside functions and methods.
That's the same thing here : wxApp class creates a wxFrame object and keeps on running into an invisible loop (the "return TRUE" at the end of wxApp code). As a GUI application is designed to wait for user commands, relevant code is in wxFrame object (and objects it uses and creates).
That's all.

All other stuff is pure C++ stuff.
many tanx dear . yeah , and it is located in wxApp::OnInit() right? so what ever i want to do , i should use wApp::OnIt(). and place the objects there ! cause its the starting function! just like int main() in a console application. ( Dear Auria thank you for your correction)
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Hossein wrote:many tanx dear . yeah , and it is located in wxApp::OnInit() right? so what ever i want to do , i should use wApp::OnIt(). and place the objects there ! cause its the starting function! just like int main() in a console application. ( Dear Auria thank you for your correction)
For classic GUI, wxApp::OnInit() contains a MyFrame instanciation (MyFrame inherits from wxFrame), and a few initializations, like parameters retrieved from the command line, which generally are passed to the MyFrame object (like size and position of frame) : around 10-50 lines for wxApp::OnInit().
I repeat, most part of relevant code is owned by MyFrame object (and its objects) : > 1000 lines for a tiny application.
The principle purpose of wxApp::OnInit() is to - what a big deal - do some initializations.
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

1) You commonly initialize your application resources (create a frame, load configs etc.) in YourApp::OnInit. This corresponds to int main (...) in an console app. It doesn't matter what the name of the cpp file is (usually YourApp.cpp)

2) Nobody can tell you where you should create the instances of your classes since that really depends on what the classes will do, when/where they are needed and how long they are supposed to exist. You could for example create instances in the event handler functions or as member variable in some GUI class. Example:

Code: Select all

class YourFrame : public wxFrame
{
public:
	.
	.
	.
private:
	SomeClass mInst;
	
	void OnMenuDoSomethingClicked ( wxCommandEvent &rEvt );
	void OnMenuDoSomethingElseClicked ( wxCommandEvent &rEvt );
};

void YourFrame::OnMenuDoSomethingClicked ( wxCommandEvent &rEvt )
{
	mInst.DoSomething();
}

void YourFrame::OnMenuDoSomethingElseClicked ( wxCommandEvent &rEvt )
{
	SomeOtherClass inst;
	inst.DoSomething();
}
HTH
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein »

thank you very very much , i really appreciate it.
by the way do you mind if i have a problem, i post it here?! :?:
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

Hossein wrote:by the way do you mind if i have a problem, i post it here?!
No, please don't reuse an old topic for new questions. It's best to create a new one.
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
Post Reply