fork download
  1. // マクロ
  2. string makeHANDLE_MSG(alias hwnd, alias message, string fn)() @property
  3. {
  4. return "case " ~ message.stringof ~ ":"
  5. "return HANDLE_" ~ message.stringof ~ "("
  6. ~ hwnd.stringof ~ ", wParam, lParam, "
  7. ~ "&" ~ fn ~ ");";
  8. }
  9.  
  10. // ダミー:既にどこかで定義済みのはず
  11. int HANDLE_WM_MSG1(void* h, int l, int w, int function(void* hwnd, int,int) fn)
  12. {
  13. return fn(h, l, w);
  14. }
  15. int HANDLE_WM_MSG2(void* h, int l, int w, int function(void* hwnd, int,int) fn)
  16. {
  17. return fn(h, l, w);
  18. }
  19. int HANDLE_WM_MSG3(void* h, int l, int w, int function(void* hwnd, int,int) fn)
  20. {
  21. return fn(h, l, w);
  22. }
  23.  
  24. // メッセージごとに作成する?
  25. const int WM_MSG1 = 1, WM_MSG2 = 2, WM_MSG3 = 3;
  26. int handler1(void* h, int l, int w) {
  27. return 0;
  28. }
  29. int handler2(void* h, int l, int w) {
  30. return 0;
  31. }
  32. int handler3(void* h, int l, int w) {
  33. return 0;
  34. }
  35.  
  36. int main()
  37. {
  38. int msg = WM_MSG1;
  39. void* hwnd;
  40. int wParam, lParam; // makeHANDLE_MSG を展開した後で参照される
  41.  
  42. // 使用例
  43. switch (msg) {
  44. mixin( makeHANDLE_MSG!(hwnd, WM_MSG1, "handler1") ); // HANDLE_MSG(hwnd, message, fn)
  45. // 複数行並べる場合はこっちのほうがマシ
  46. mixin(
  47. makeHANDLE_MSG!(hwnd, WM_MSG2, "handler2") ~
  48. makeHANDLE_MSG!(hwnd, WM_MSG3, "handler3") ~
  49. "" );
  50. default:
  51. assert(false);
  52. }
  53. }
  54.  
Success #stdin #stdout 0.01s 1992KB
stdin
Standard input is empty
stdout
Standard output is empty