If you're here I assume you know what wxWidgets is, so let's not waste time.
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.