FAQ

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

FAQ

Postby Ryan Norton » Fri Sep 10, 2004 8:18 am


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

http://wxwidgets.org/docs/faq.htm


The wxWiki FAQ is also very useful
http://wiki.wxwidgets.org/WxFAQ
Last edited by DavidHart on Fri Jun 20, 2014 2:27 pm, edited 12 times in total.
Reason: Updated the wxWiki FAQ url
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:17 pm

When will version XXX come out?

See the roadmap at http://wxwidgets.org/develop/roadmap.htm.

Yes, it's out of date usually
Last edited by Ryan Norton on Mon Sep 04, 2006 7:36 pm, edited 4 times in total.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:18 pm

Help!!! I'm new/stuck and need a tutorial - NOW!

Last edited by Ryan Norton on Mon Sep 04, 2006 7:37 pm, edited 3 times in total.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:19 pm

What other resources are there for help/information?
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:20 pm

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.
Last edited by Ryan Norton on Thu Dec 08, 2005 7:05 am, edited 1 time in total.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:21 pm

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
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:21 pm

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) \
    wxASSERT((cmd))
#else
#define wxVERIFY(cmd) \
    (cmd)
#endif 
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:22 pm

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.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:23 pm

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
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:24 pm

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 http://alleg.sf.net
    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) http://libsdl.org
    SDL is the de-facto media library for linux, and has decent support for other platforms. Under a LPGL with additional restriction(s).
  • OpenAL http://openal.org
    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.
Last edited by Ryan Norton on Fri Apr 22, 2005 9:28 pm, edited 1 time in total.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:26 pm

I want balloon tooltips on my wxTaskBarIcon!!

That is in the snippets forum, along with other helpful pieces of code
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:27 pm

I want to make my own main() and/or WinMain()!!

Use IMPLEMENT_APP_NO_MAIN instead of IMPLEMENT_APP
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:28 pm

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
{
public:
    // ------------------------------------------------------------------------
    // 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
    DECLARE_DYNAMIC_CLASS(wxMediaEvent)
};

//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
DECLARE_EVENT_TYPE(wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
DECLARE_EVENT_TYPE(wxEVT_MEDIA_STOP,     wxMEDIA_STOP_ID)

//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
IMPLEMENT_DYNAMIC_CLASS(wxMediaEvent, wxEvent);
DEFINE_EVENT_TYPE(wxEVT_MEDIA_FINISHED);
DEFINE_EVENT_TYPE(wxEVT_MEDIA_STOP);
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:32 pm

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.

Last edited by Ryan Norton on Thu Dec 08, 2005 7:03 am, edited 1 time in total.
[Mostly retired moderator, still check in to clean up some stuff]

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Postby Ryan Norton » Wed Nov 24, 2004 8:34 pm

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);
    return;
  }

  wxString cmd;
  bool ok =
    ft->GetOpenCommand (&cmd,
   wxFileType::MessageParameters (afile.GetFullPath(),
                                       _T("")));
  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.
Last edited by Ryan Norton on Tue Jan 23, 2007 8:23 am, edited 1 time in total.
[Mostly retired moderator, still check in to clean up some stuff]


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot] and 15 guests