WxMSW Issues

From WxWiki
Jump to: navigation, search

Windows Tidbits

If you need to get to a Window handle (HWND), call wxWindow::GetHandle().

Getting the handle to the Application Instance is a little more involved. You need to include a header and then you can call an undocumented function that is only on Windows:

#ifdef __WXMSW__
#include "wx/msw/private.h"
HINSTANCE hInstance = wxGetInstance();

Win98 and Large DLL's

For those of us still stuck in the stone age it's worth noting that Windows 98 doesn't seem to behave well with large DLLs. The wxWidgets DLL is quite large (30 mb's) unstripped and may mean your exe doesn't run. Just strip it and you'll be fine.

The windows.h Header File, Macros and Compiling Errors

If you are getting multiple definition errors with CreateDialog(), Yield() etc. even though you're not using the functions, read this:

When you include <wx/wx.h> it also includes <wx/app.h>. If you are compiling under MS Windows, <wx/app.h> should include <windows.h> and <wx/msw/winundef.h> just after. Sometimes (TODO: determine on which cases), wxWidgets will just forget to include the second header so you will have to do it yourself if you are getting errors with CreateDialog(), Yield() or anything else when compiling. The reason is <windows.h> defines a lot of macros that have the same name as wxWidgets classes' methods. Including <wx/msw/winundef.h> will fix that bug.

Also this will fix errors involving undefined GetClassInfoA() members. So in short: whenever your source includes <windows.h> include <wx/msw/winundef.h> on the next line!

DOS Window

If your program opens a DOS-Window, check you linking options.

With MinGW, you'll need to add -mwindows, for more info see the MinGW faq: http://mingw.org/mingwfaq.shtml#faq-ridconsole

But what if you *want* to have a DOS-Window? (for instance for debugging information)? -ARN -Open program from dos prompt and use standard output -karlan

There are also cases where you may want Windows to see a GUI application as if it were a command line application. To achieve that you need to use Microsoft's tool:

 EditBin /subsystem:console $(OutDir)/MyProg.exe

Now printfs and piping to stdout and stderror will appear on the console, and you still get a GUI too.


I had problems using PNG files from an XRC in a wxTreeCtrl with a wxImageList. The app worked fine in OSX and GTK but failed to load the images into the tree in Windows XP. Make sure you use PNGs with the same dimensions and use the constructor wxImageList(16, 16, true) rather then the constructor wxImageList() so that masking is done properly.

Using Native DC on Windows

If you'd like to handle native DC on windows, there are some tricks.

  • Get the Window handle
 hwnd = ::FindWindow("TfmMain", NULL);
  • Get DC
 hdc = ::GetDC(hwnd);
  • wxDCTemp can handle this
 wxDCTemp tmp_dc(hdc);