It hasn't been particularly straight forward the procedure for setting wxWidgets up with my Visual Studio 2012, so I'll tell you how to do it from the ground up until having a gui running, that you'll have made with wxFormBuilder, the easy way, for lazy morons.
1. Compiling the libraries
We'll compile the libraries for our particular version of VS, so we can make sure they work, and because the pre-compiled stuff that you can find in the internet (wxPack) is a heavy pile of shit with unnecessary gigabytes.
- First download the Windows Installer from the wxWidgets official site http://wxwidgets.org/downloads/ Install it.
- Download and install wxFormBuilder too.
- Go to C:\Program Files (x86)\wxWidgets-3.0.3\build\msw. Obviously, the path may vary if you changed the installation folder.
- Open the right Solution file, don't get fooled with the names:
vc10 means VS2010
vc11 means VS2012
vc12 means VS2013
- Build the project in Debug mode and after completed, in Release mode.
- Done.
2. Check if you fucked something up
- Go to C:\Program Files (x86)\wxWidgets-3.0.3\samples and open the solution file called 'samples'. Let VS upgrade the project if it's made with an old version of VS.
- Right click the project 'minimal' and Debug > Start new instance.
- If it compiles OK and you can see the program window, you did fine.
3. Creating a test GUI
- Open wxFormBuilder and create a test GUI. I'm not detailing this, you need to add a new form, a layout and then it allows you to insert something like a button.
- Save the project somewhere and generate the code by pressing the gear icon.
This is the tricky part, the following lines are damn golden.
4. Getting wxWidgets to compile in your program
- Create a new project of type 'Win32 Project'. In the second page of the wizard, under 'Additional options', check 'Empty project' and uncheck 'Security Development Lifecycle (SDL) checks'.
- Once created, open the project properties.
- In parallel, open the 'minimal' sample like in point 2, and open its properties.
- Go through the sections and copy each and every damn option that is in bold to your project properties, so both project configurations match. Obviously, options like 'Output directory' aren't meant to be changed.
- Your project should compile now when using wxWidgets in your code.
5. Using a wxFormBuilder GUI in your program
- Move the files generated by wxFormBuilder to a suitable place like your project folder.
- Add the header and the .cpp to your project.
- Use the following example code in your main.cpp (for example) to launch your GUI.
#include <wx/wx.h>
#include "gui\gui.h"
class MyApp: public wxApp {
public:
virtual bool OnInit();
virtual int OnExit() { return 0; }
};
IMPLEMENT_APP (MyApp);
bool MyApp::OnInit() {
wxFrame* mainFrame = new MyFrame1(NULL);
mainFrame->Show(true);
SetTopWindow(mainFrame);
return true;
}
NOTE 'MyFrame1' is the default frame name if you didn't change it in wxFB.
- Now if you press play, your beloved GUI should appear.
Tell me in the comments if it worked for you.
Hi Pedro,
ReplyDeletethank you so much for this description.
Finally it worked well for me (Windows 10 + VisualStudio Community 2017) after overcoming some tiny problems.
I just list the problems and solutions for the help of others.
Some problems really occured because I'm not very familar with c++ and visual studio.
Problem 1:
My wxWidget 3.0.3 source files didn't contain a proper version for VSC 2017.
But there was a "wx.dsw" in folder "wxWidgets\build\msw".
After opening this with VSC2017 it was converted into VSC 2017 versions.
I could create the libraries for debug and release X86 with this sources.
2. problem
For copying the properties I first used the properties window with configuration = "all configurations". Because of this I couldn't see the entries in the relevant property items. It has to be done separately for "debug" and "release" configuration.
3. problem
I really just copied the property values.
After a while of trouble shooting I realised that the include and lib path values are stated relatively to the sample projects.
To fix this the paths need to be adapted to the paths of my locally built wxWidget libraries.
I hope this comments will help some other novices and save some hours of trouble shooting.
Cheers
Stephan
Hi Stephan, I appreciate very much your comment. Cheers mate.
DeleteWorks well. Thanks Pedro!
DeleteDear Pedro,
ReplyDeleteThank you very much for your post. It really works and helped me a lot!
With kind regards,
Yaroslav
Cheers Yaroslav!
ReplyDeleteAt last, after hours upon hours googling, youtubing and reading, finding something that actual explained how to patch the 2 main bits together - Visual Studio (2019) and WxFormbuilder... thanks Pedro
ReplyDelete