Howto enable Visual C++ Intellisense for wxWidgets
Intellisense - Quick Guide
- Download "_wx_intellisense.h"
- Add it to your Visual Studio project.
- Close the project and delete the *.ncb file of the project.
- Reopen the project.
- .NET 2002 is especially prone to crashes while it parses the file. If it does, close it and try again.
- Add "wx/something.h" and "wx/msw/something.h" includes to _wx_intellisense.h everytime you are using a new wxWidgets class that is not defined yet.
This method is not perfect. Several classes will still miss some or all functions. But most classes work reasonably well.
Click "here", if you are interested in the details behind _wx_intellisense.h.
Integrated (F1) Onlinehelp and wxWidgets documentation
I will no longer be making available the 'setup.msi' file here to integrate online help into visual studio. Instead I have created an installer called wxVisualSetup, which enables Intellisense, Online Help and a
Project Wizard for wxWidgets.
Intellisense and wxWidgets
I am using Visual Studio .NET but the findings should apply to VC++ 6.0 and probably to .NET 2003 as well.
The problem The solution Example wx_intellisense.h
The problem
MS Intellisense' simple approach at parsing the header files cannot cope very well with #if and #defines.
Problem #1
Take the following example:
wxprec.h
#include "wx/platform.h" // #defines __WXMSW__ and others
#include "wx/wx.h" // #includes "wx/msw/wx.h" but only if __WXMSW__ is defined
platform.h defines the macro __WXMSW__. When Intellisense parses the file wxprec.h, it follows the #include and will also read platform.h and find the #define __WXMSW__. But different from the
actual preprocessor, the macro __WXMSW__ will be undefined again once Intellisense closes platform.h. Because of that, when Intellisense parses wx.h, the macro __WXMSW__ will be undefined and thus the file msw/wx.h will not get included in the Intellisense database.
As a result, nearly all wxWidgets symbols will be left out in the Intellisense database.
Problem #2
Intellisense cannot resolve macro definitions. In the following example, the class wxWindowMSW will be known, but wxWindow will be unknown to Intellisense:
#define wxWindowMSW wxWindow class wxWindowMSW { };
Additionally, the macro WXDLLEXPORT may not get parsed correctly and the declaration
class WXDLLEXPORT wxClass {};
will in some cases not work as expected.
The solution
There is a very simple solution to both problems, that works quite well.
- Create a new file wx_intellisense.h and add it to your project. The file does not have to be #included in any source file. All you need to do is add it to the projects file tree.
- For every wxWidgets symbol you need, add #includes to the corresponding header files to your wx_intellisense.h file. Be sure to add both header files, the general .h file in the include/wx
and the implementation specific .h file in the include/wx/msw directory.
Example: if you want wxFrame to be known to Intellisense, add these lines to wx_include.h #include "wx/frame.h"
#include "wx/msw/frame.h"
- Save wx_intellisense.h. Intellisense will parse the file, find the new #includes, parse the include files and from then on the wxFrame class will be known. If it still isn't known to
Intellisense, exit Visual Studio, delete the *.ncb file in the solution directory, reopen the solution and resave wx_intellisense.h.
This will solve problem #1. You could simply #include all header files from the wxWidgets/include/wx and wxWidgets/include/wx/msw directory in wx_intellisense.h. This was what I tried at first, but the
Intellisense parser is a bit unstable when parsing so many files. Visual Studio locked up several times when I tried to rebuild the Intellisense database (*.ncb file). So I decided to include only the files I
actually need for my project and build the file incrementally. You may need to experiment a little.
Problem #2 has a simple solution as well. Just add
class wxWindow:public wxWindowMSW { };
after the last #include in your wx_intellisense.h file. This will declare a class wxWindow with all
members of wxWindowMSW, which is exactly what wxWindow really is. It does not matter that the class definition here is completely bogus as wx_intellisense.h isn't actually compiled.
And for the WXDLLEXPORT problem you need to define WXDLLEXPORT at the beginning of your wx_intellisense.h file.
#define WXDLLEXPORT /* */
Note that even if you use wxWidgets as a DLL, you can still define WXDLLEXPORT as /* */ in your wx_intellisense.h file as it doesn't get compiled.
Generally if you find that a class is undefined and pressing Ctrl-Space does not work, add the include files to wx_intellisense.h and save the file.
Example wx_intellisense.h
You will need to add the proper include files, if you are missing symbols. If you use wxBitmap for
example, you'll have to add #include "wx/bitmap.h" just before the line #include "wx/msw/bitmap.h" or else some of the wxBitmap symbols will be undefined. Use this file as a starting point.
#define WXDLLEXPORT /* */ [... snip ...] #include "wx/msw/missing.h" #include "wx/msw/setup.h" #include "wx/window.h" #include "wx/msw/window.h"
#include "wx/msw/winundef.h" #include "wx/sizer.h"
#undef wxWindow class wxWindow:public wxWindowMSW { };
|