Page 1 of 3


Posted: Fri Sep 10, 2004 8:18 am
by Ryan Norton

This is the "official" wxWidgets C++ Users Forum FAQ.

This FAQ is user-editable - if you have a FAQ you think should be here, post a reply to this topic with the FAQ and corresponding answer.

You should read the main wxWidgets FAQ first; here we just try to cover issues not covered in the main FAQ. The main wxWidgets FAQ is located at

The wxWiki FAQ is also very useful

Posted: Wed Nov 24, 2004 8:17 pm
by Ryan Norton
When will version XXX come out?

See the roadmap at

Yes, it's out of date usually

Posted: Wed Nov 24, 2004 8:18 pm
by Ryan Norton
Help!!! I'm new/stuck and need a tutorial - NOW!

Posted: Wed Nov 24, 2004 8:19 pm
by Ryan Norton
What other resources are there for help/information?

Posted: Wed Nov 24, 2004 8:20 pm
by Ryan Norton
I'm frustrated! I keep on getting stuff like Xlib: unexpected async reply (...) and other wierdness when I use threads on non-windows platforms!!!

You cannot use GUI functions/classes in secondary threads (INCLUDING wxBitmap!!!!)- you may only use them in the main thread. Windows supports this because it's the leader in this kind of thing - but the free X11 servers still don't support this. By GUI functions/classes I mean _anything_ that draws, creates windows, etc.. This includes even wxMessageBox and wxBitmap.

However, there is a possible workaround for this - simply put wxMutexGuiEnter() before any GUI stuff in a secondary thread and wxMutexGuiLeave() when you're done with the GUI stuff in the secondary thread. Note that this may or may not work all the time - people have reported problems with this.

Posted: Wed Nov 24, 2004 8:21 pm
by Ryan Norton
When the OpenGL/GLCanvas examples compile, I get an error to change wxUSE_GLCANVAS to 1, and then when I do so in setup.h I get a whole bunch of link errors!! (sebol)

Windows : You should make sure that you recompile the library with wxUSE_GLCANVAS in setup.h set to 1, also not forgetting to include the opengl32.lib and glu.lib libraries.
Linux/Unix : Do not edit setup.h manually, instead delete your build folder, and start a new one, with ../configure --with-opengl

Posted: Wed Nov 24, 2004 8:21 pm
by Ryan Norton
What would be the wxWidget equivalent to the MFC VERIFY macro?

There is none, although wxCHECK comes close. Here's a better alternative:

Code: Select all

#ifdef _DEBUG 
#define wxVERIFY(cmd) \ 
#define wxVERIFY(cmd) \ 

Posted: Wed Nov 24, 2004 8:22 pm
by Ryan Norton
Why can't I add a wxPanel or sizer to a wxButton when it is derived from wxWindow?

The jist of it is that most native APIs don't support this - and wxWidgets uses the native APIs underneath the hood.

To solve this, either subclass wxButton and take care of it yourself, or use wxUniversal - which only relies on the native API's drawing routines.

Posted: Wed Nov 24, 2004 8:23 pm
by Ryan Norton
Help! I just updated CVS and I'm getting linker errors!!

Before reporting linker errors to the lists or sourceforge, make sure you do the following things:
  • Rebuild the wxWidgets library
    You can usually do this via a "make clean". Don't forget to run configure again afterwards
  • Make sure you update to get new files
    Sounds self explanatory, but if you don't do a full cvs update you may miss files that were added
  • Rubuild any components that you use that use wxWidgets
    For example, if you use Jorg's wxMultiTreeCtrl or similar, make sure to rebuild that also

Posted: Wed Nov 24, 2004 8:24 pm
by Ryan Norton
I need to do XXX for my game with wxWidgets...

In general, wxWidgets is probably not the best choice for games, it definately won't help you win any size contests :).

However, it does provide some things:
  • wxWindow::WarpPointer is a fairly accurate and fast way of interacting with the mouse
  • wxGetKeyState is a pretty fast way to get the state of a key - on mac its really fast
  • wxGLCanvas and friends interact with opengl for decent graphics
Instead of wxWidgets (or in addition to) you may want to try the following:
  • Allegro
    Public domain game library. Lacks decent 3D API. Other than that has a very decent API and some of the best - if not the best - documentation, period.
  • SDL (Simple Directmedia Layer)
    SDL is the de-facto media library for linux, and has decent support for other platforms. Under a LPGL with additional restriction(s).
  • OpenAL
    Once maintained by the game company Loki, now maintained by Creative. OpenAL isn't really a game library unto itself, but provides pretty much the industry standard 3d sound. Somewhat annoying API - is simple, but there is a lot of unexpected behavior and platform-specific funnies to keep you busy.

Posted: Wed Nov 24, 2004 8:26 pm
by Ryan Norton
I want balloon tooltips on my wxTaskBarIcon!!

That is in the snippets forum, along with other helpful pieces of code

Posted: Wed Nov 24, 2004 8:27 pm
by Ryan Norton
I want to make my own main() and/or WinMain()!!


Posted: Wed Nov 24, 2004 8:28 pm
by Ryan Norton
No really, how do you make a custom event??
Use the following template and replace media etc. with whatever you want.

Code: Select all

//in .h
class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent
    // ------------------------------------------------------------------------
    // wxMediaEvent Constructor
    // Normal constructor, much the same as wxNotifyEvent
    // ------------------------------------------------------------------------
    wxMediaEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
        : wxNotifyEvent(commandType, id)
    {                                       }

    // ------------------------------------------------------------------------
    // wxMediaEvent Copy Constructor
    // Normal copy constructor, much the same as wxNotifyEvent
    // ------------------------------------------------------------------------
    wxMediaEvent(const wxMediaEvent &clone)
            : wxNotifyEvent(clone)
    {                                       }

    // ------------------------------------------------------------------------
    // wxMediaEvent::Clone
    // Allocates a copy of this object.
    // Required for wxEvtHandler::AddPendingEvent
    // ------------------------------------------------------------------------
    virtual wxEvent *Clone() const
    {   return new wxMediaEvent(*this);     }

    // Put this class on wxWidget's RTTI table

//Event ID to give to our events
#define wxMEDIA_FINISHED_ID    13000
#define wxMEDIA_STOP_ID    13001

//Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later

//Function type(s) our events need
typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);

//Macro for usage with message maps
#define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMediaEventFunction) & fn, (wxObject *) NULL ),
#define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMediaEventFunction) & fn, (wxObject *) NULL ),

//in .cpp

Posted: Wed Nov 24, 2004 8:32 pm
by Ryan Norton
Does wxWidgets have any stuff for ActiveX??

There is a 3rd party add-on called wxActiveX that is a ActiveX container, but there are no known 3rd party add-ons for making ActiveX controls.

Posted: Wed Nov 24, 2004 8:34 pm
by Ryan Norton
How do I open the application of a file extension?? How do I launch the default browser??

Just do something like:

Code: Select all

wxFileType *ft = 
wxTheMimeTypesManager->GetFileTypeFromExtension (suffix);
  if (!ft) {
    wxLogError("Impossible to determine the file type for extension %s.\n"
	       "Please edit your MIME types.", suffix);

  wxString cmd; 
  bool ok =
    ft->GetOpenCommand (&cmd,
	wxFileType::MessageParameters (afile.GetFullPath(),
  delete ft;

  if (ok)
      wxExecute (cmd, wxEXEC_ASYNC);
In theory, launching the defualt browser is similar - just get whatever opens .htm(l) pages by default through the mime types manager. However, in practice you'll probably want to use the 2.6+ wxLaunchDefaultBrowser function.