In Waxe version 1.0.1, there’s no MessageDialog implementation, so we have to create one ourselves. This requires that we have the wxWidgets-2.9.3 source code and that we have compiled the needed obj files from that. (I’ll describe that process later, in part 7…)
In short, this involves the following steps:
- Adding the wxMessageDialog implementation to the cpp code
- Compiling a new waxw.ndll, including the wx_message_dialog_show function as a result of above.
- Creating the wx.MessageDialog.hx class
- Use it in your applications!
So, here we go!
Step 1. Adding the c++ code
When trying to figure out how to implement the MessageDialog, i found that the wxFileDialog and wxDirDialog implemetations both reside in the haxe/lib/waxe/1,0,1/src/waxe/Dialog.cpp file. As they both extend the Dialog class, and so does the MessageDialog, I choose to follow that example and put the MessageDialog code there as well.
This is what I added to the end of the Dialog.cpp file:
//-------------------------------------------------------------------------------------------------------------------
// wxMessageDialog implemetation, added to /haxe/lib/waxe/1.0.1/src/waxe/Dialog.cpp
value wx_message_dialog_show(value ioData)
{
wxWindow *parent = 0;
wxString message;
wxString caption;
int style;
ValueToWX(val_field(ioData,val_id("parent")),parent);
ValueToWX(val_field(ioData,val_id("message")),message);
ValueToWX(val_field(ioData,val_id("caption")),caption);
ValueToWX(val_field(ioData,val_id("style")),style);
wxMessageDialog *dlg = new wxMessageDialog(parent,message, caption, style);
int result = dlg->ShowModal();
dlg->Destroy();
return alloc_int(result);
}
DEFINE_PRIM(wx_message_dialog_show,1)
Step 2. Compiling a new waxe.ndll
NOTE: This requres that you have already built the needed obj files from wxWidgets-2.9.3 source code!
Start by making a backup of your waxe.ndll file (typically haxe/lib/waxe/1.0.1/ndll/Windows/waxe.ndll). We’re going to replace this one in the following. Then open a command window in the haxe/lib/waxe/1.0.1/src directory, and run the following command:
haxelib run hxcpp Build.xml
This should build a new waxe.ndll with the included wx_message_dialog_show function that we added in step 1.
Step 3. Creating the haxe code
Create a new haxe source code file named MessageDialog.hx in the haxe/lib/waxe/1,0,1/wx directory:
// haxe/lib/waxe/1.0.1/wx/MessageDialog.hx
package wx;
import wx.Window;
class MessageDialog
{
public var parent:Dynamic;
public var message:String;
public var caption:String;
public var style:Int;
public static inline var OK = 0x00000004;
public static inline var YES = 0x00000002;
public static inline var NO = 0x00000008;
public static inline var CANCEL = 0x00000010;
public static inline var YES_NO = YES | NO;
public static inline var ICON_WARNING = 0x00000100;
public static inline var ICON_ERROR = 0x00000200;
public static inline var ICON_QUESTION = 0x00000400;
public static inline var ICON_INFORMATION = 0x00000800;
public function new (
inParent:Window = null,
inMessage:String = "Message",
inCaption:String = "Caption",
inStyle:Int = OK
)
{
this.parent = (inParent==null) ? null : inParent.wxHandle;
this.message = inMessage;
this.caption = inCaption;
this.style = inStyle;
}
public function showModal() : Int
{
return wx_message_dialog_show(this);
}
static var wx_message_dialog_show = Loader.load("wx_message_dialog_show", 1);
}
I found the values for the constants in the onlined docs for wxWidgets, on this page: http://docs.wxwidgets.org/trunk/defs_8h.html
Step 4. Add dialogs to your application
So, now you should be able to add a message dialog to your Waxe application.
The following gives a simple dialog with the default settings – an info icon and one OK button:
new MessageDialog(null, 'Hello world!', 'Message caption').showModal();
By combining the MessageDialog constants we can combine button alternatives…
- OK
- CANCEL
- YES
- NO
- YES_NO
…and icon alternatives:
- WARNING
- ERROR
- QUESTION
- INFORMATION
By setting the style parameter to MessBelow we get a Yes/No dialog box with a warning icon. The result is an int that we can filter logically to find out wether yes or no was answered:
var style = MessageDialog.YES_NO | MessageDialog.ICON_WARNING;
var result = new MessageDialog(null, 'Important question: Does the pope wear a nice hat?', 'Message caption', style).showModal();
if ((result & MessageDialog.YES) == MessageDialog.YES) {
trace('Yes');
} else {
trace('No');
}
Please note that this is only a basic implementation of the wxMessageDialog. There are other constructor parameters to use (position etc), but this suits my needs for now!
Cheers!


Nick Holder
October 22, 2012
Wow, great stuff. I wasn’t brave enough to delve into the c++ , fantastic job
cambiatablog
October 22, 2012
Neither was I… But thanks to Mockey and Pah i managed to sort it out!
Simon
October 24, 2012
Sounds cool. What is the best way to add the drag file system (drag file on th app, exactly like an AIR app) to a haxe desktop app? Possible with waxe ? Need to do some C++ ? Can be done with C++ and no need to have waxe ?
Thnks
pah arif (@misterpah)
October 26, 2012
hi! it’s great to know u liked my tutorial
i want to pull your code to the github..
is it okey with you ?
cambiatablog
October 29, 2012
@Simon: I’m sure wxWidgets has functions for that. I guess that the workflow would be something like this MessageDialog thing: 1) create the cpp code for including the needed wxWidget functions, 2) Recompiling the waxe.ndll with these included functions, 3) Writing the corresponding haxe code to be able to communicate with the waxe.ndll, 4) Create the application code
cambiatablog
October 29, 2012
@Pah: Of course! Github repo is a great idea!
pah arif (@misterpah)
November 1, 2012
it’s me again. I’ve tried your function for both neko and windows. It works great! FYI, I’ve pull your function(s) to the github. you can access them at https://github.com/misterpah/waxe
cambiatablog
November 5, 2012
Thank you, Pah! I will try to fork your github lib and create pull requests if I come up with further solutions.