I modified the method slightly to remove some snippets not relevant here, but the idea is solid. If anyone wants to add this as a nice utility method to wxWidgets in general, please do ahead. Also, some error checking is missing.