import std.stdio;
template HANDLE_MSG(alias hwnd, string message, string fn) {
const string HANDLE_MSG = "case " ~ message ~ ": " ~
"return HANDLE_" ~ message ~ "(" ~
hwnd.stringof ~ ", wParam, lParam, &" ~ fn ~ ");";
}
version(D_Version2) {
template HANDLE_MSG(alias hwnd, alias message, alias fn) {
const string HANDLE_MSG = "case " ~ message.stringof ~ ": " ~
"return HANDLE_" ~ message.stringof ~ "(" ~
hwnd.stringof ~ ", wParam, lParam, " ~ (&fn).stringof ~ ");";
}
}
int HANDLE_WM_MSG1(void* h, int w, int l, int function(void*, int, int) fn) {
return fn(h, w, l);
}
int HANDLE_WM_MSG2(void* h, int w, int l, int function(void*, int, int) fn) {
return fn(h, w, l);
}
int handler1(void* h, int w, int l) {
writef("WM_MSG1: wParam = %d, lParam = %d\n", w, l);
return 0;
}
int handler2(void* h, int w, int l) {
writef("WM_MSG2: wParam = %d, lParam = %d\n", w, l);
return 0;
}
const int WM_MSG1 = 1;
const int WM_MSG2 = 2;
int test(int msg) {
void* hwnd = null;
int wParam = 1, lParam = 2;
version(D_Version2) {
switch(msg) {
mixin(HANDLE_MSG!(hwnd, WM_MSG1, handler1));
mixin(HANDLE_MSG!(hwnd, WM_MSG2, handler2));
default:
}
} else {
switch(msg) {
mixin(HANDLE_MSG!(hwnd, "WM_MSG1", "handler1"));
mixin(HANDLE_MSG!(hwnd, "WM_MSG2", "handler2"));
default:
}
}
return 0;
}
void main() {
test(WM_MSG1);
test(WM_MSG2);
}