- Windows 7, 8.1, 10, XP
- Microsoft Visual C++ 2010 Express, 2013, 2015 Express / Community Edition
- wxWidgets v3.0.2 / v3.0.3 / v3.0.4
- Unzip wxWidgets archive to a folder and compile it following its install instructions. It takes time and it would take some time too to configure it properly for compile both for debug and release.
- File >> New Project >> Visual C++ >> Win32 >> Win32 Project.
- Input solution title and press [OK] button. No need to check "Create directory for solution."
- [Next]
- Check [Empty Project] >> [Finish]
- Result: A new wxWidgets GUI Project has been created.
Now create/add necessary source/header files and configure the project:
- File >> New >> File... >> Visual C++ >>
- C++ File(.cpp) >> [Open]
File >> Save All
File >> Save File As... >> Browse for the folder of the project then save the newly created 'Source1.cpp' with a proper name into it. That may well be the main source file of the project:
- or
Right-click on [Source] item of VC++'s [Solution Explorer] >> Add >> New Item...
- Input proper name of the source file then click [Add] button:
Then, save all.
Result:
- C++ File(.cpp) >> [Open]
- Now create a main header file named after the source file with an '.h' extension the same way as done above.
- Project >> (Project) Properties...(Alt+F7) :
- Configuration >> All Configuration :
- Configuration Properties >> General >> Project Defaults >> Character Set >>
Use Unicode Character Set :
- Configuration Properties >> C++ >> General >> Additional Include Directories >>
Click its drop-down box's <Edit...> item :
Then add the following lines :
$(WX3)\include <- The location of the wxWidgets include directory.
$(WX3)\include\msvc <- This automatically includes the build-specific setup.h files.
[OK] - Configuration Properties >> C++ >> Preprocessor >> Preprocessor Definitions >> <Edit...>.
Then add the following definitions: WIN32 <- Already there.
WINVER=0x0500 (or WINVER=0x0400 for old version of Windows)
_WINDOWS
__WXMSW__
wxUSE_GUI=1 <- If using GUI components(non-console app)
WXUSINGDLL <- If compiling using DLLs instead of a static method.
_CRT_SECURE_NO_DEPRECATE<- Optional, to suppress deprecation notification warnings.
_CRT_NONSTDC_NO_DEPRECATE<- Optional, to suppress security warnings.
_CRT_NON_CONFORMING_SWPRINTFS<- Optional, for swprintf.
[Apply]
Now, switch to <Debug> configuration to add the following definition :
__WXDEBUG__ <- only for debug configuration
[APPLY]
Now, if the wxWidgets library was compiled with parameter switches as follows:
DEBUG_INFO=0 DEBUG_FLAG=0 DEBUG_RUNTIME_LIBS=0
switch to configuration to add the following definition :
(otherwise, nothing to do with release definitions)
wxDEBUG_LEVEL=0
[APPLY] - For static build (no wxWidgets DLL will be distributed accompanied) :
- Configuration >> <Debug>:
Configuration Properties >> C++ >> Code Generation >> Runtime Library >> Multi-threaded Debug (/MTd) - Configuration >> <Release>:
Configuration Properties >> C++ >> Code Generation >> Runtime Library >> Multi-threaded (/MT)
[APPLY]Excerpt from wxWidgets:
The multi-threaded DLL libraries are the ones wxWidgets is linked with by default. If you get something like MSVCRT.lib(MSVCRT.dll) : error LNK2005: _free already defined in LIBC.lib(free.obj) then you're linking with the wrong run-time library.
- Configuration >> <Debug>:
- Configuration >> : <All Configuration>:
Configuration Properties >> Linker >> General >> Additional Library Directories >> <Edit...>.
$(WX3)\lib\vc_lib
or
$(WX3)\lib\vc_dll for projects using DLLs : (WXUSINGDLL)
[APPLY] - Configuration Properties >> Linker >> Input >> Additional Dependencies >> <Edit...>.
comctl32.lib
rpcrt4.lib
winmm.lib
wsock32.lib
advapi32.lib
(VC defaults: already there)<- wxWidgets needs these.wxmsw30[ud]_core.lib
wxbase30[ud].lib
<- The core wxWidgets libraries.
wxpng[d].lib
wxzlib[d].lib
wxjpeg[d].lib
wxtiff[d].lib
<- wxWidgets support libraries (optional, modify file names according to need). For example, for debug ANSI static :
wxmsw30d_core.lib
wxbase30d.lib
For example, for debug Unicode static :
wxmsw30ud_core.lib
wxbase30ud.lib
For example, for release Unicode static :
wxmsw30u_core.lib
wxbase30u.libConfiguration >> <Debug Configuration>
...
[APPLY]Configuration >> <Release Configuration>
...
[APPLY] - Configuration >> <All Configuration> :
Configuration Properties >> Linker >> System >> SubSystem >> Windows (/SUBSYSTEM:WINDOWS) - Configuration >> <All Configuration> :
Configuration Properties >> Linker >> Manifest File >> Generate Manifest >> No (/MANIFEST:NO) - Finally click [OK] to close the project configuration dialog box.
What follows here are to walk around a bug that a VC 2013 project gets wrong version information of Windows v8.1 or later (...9200 not ..9600): - Right click on the project name inside Solution Explorer >> Add >> Resource... >> Version.
- Again in the Solution Explorer, right click on the created resource file ´....rc´ then select View Code menu item to open the rc file in the IDE for edit.
- Write down the following line at the top followed by #include statement of the rc file:1
/* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "ProjectName.exe.manifest" where the ´ProjectName.exe´ is the name of the executable file being created by the project on its build:
- Now create its manifest file with the above name of the following content
under the project´s directory:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="False"/> </requestedPrivileges> </security> </trustInfo> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="Microsoft.Windows.AppName" type="win32" /> <description>AppName</description> <!--dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency--> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!-- Windows Vista/Server 2008 functionality --> <!-- supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/--> <!-- Windows 7/Server 2008 R2 functionality--> <!-- supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/--> <!-- Windows 8/Server 2012 functionality--> <!-- supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/--> <!-- Windows 8.1 and Windows Server 2012 R2 --> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <!-- Windows Blue/Server 2012 R2 functionality--> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <!-- Windows 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> </application> </compatibility> </assembly>
- asInvoker
- highestAvailable
- requireAdministrator
- Main Header File :
- Main Source File :
- Now build the project and try running it :
Voila!
The following window appears on the screen which contains no menu, no toolbar , no status bar or other controls at all. Just the skeleton of a window. That's it. Succeeded in creating the first bare basic window, which means a difficult and complicated hurdle has been removed now:
Step 4: Add a Main Menu and a Status Bar :
- Declare menu item IDs in the header file :
enum {ID_FME_MAIN = 4096, ID_HELLO};
- Declare event handler methods for each menu item and declare an event table in the header :
private:
void OnAboutClick(wxCommandEvent &event);
void OnHelloClick(wxCommandEvent &event);
void OnExitClick(wxCommandEvent &event);
wxDECLARE_EVENT_TABLE(); - In the source file :
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) EVT_MENU(ID_HELLO , MainFrame::OnHelloClick) EVT_MENU(wxID_EXIT , MainFrame::OnExitClick) EVT_MENU(wxID_ABOUT , MainFrame::OnAboutClick) wxEND_EVENT_TABLE()
- Also in the source file :
void MainFrame::OnExitClick(wxCommandEvent &event) { Close(true); } //---------------------------------------------------------------------------- void MainFrame::OnAboutClick(wxCommandEvent &event) { wxMessageBox(L"About clicked!!", L"About PanCake" , wxOK|wxICON_INFORMATION); } //---------------------------------------------------------------------------- void MainFrame::OnHelloClick(wxCommandEvent &event) { wxLogMessage("Hello world from wxWidgets!"); } //----------------------------------------------------------------------------
- Also in the source file's main frame constructor :Excerpt from wxWidgets Help
{ wxMenu *menuFile = new wxMenu; menuFile->Append(ID_HELLO, L"&Hello...\tCtrl-H", L"Help string shown in status bar for this menu item"); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); wxMenu *menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, L"&File"); menuBar->Append(menuHelp, L"&Help"); SetMenuBar(menuBar); CreateStatusBar(); SetStatusText(L"Welcome to wxWidgets!"); }
- Now again run the project and the Result is as follows :
Download Project Source Code (src_sample_wx_vc2015_Setana.rar, 854 KB) for Visual Studio 2015.
No comments:
Post a Comment