PageRenderTime 75ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Samples/Chap11/Colors3/Colors3.d

http://github.com/AndrejMitrovic/DWinProgramming
D | 70 lines | 54 code | 12 blank | 4 comment | 0 complexity | 8b09e892a0b0391cf50479a9b10c7ef2 MD5 | raw file
  1. /+
  2. + Copyright (c) Charles Petzold, 1998.
  3. + Ported to the D Programming Language by Andrej Mitrovic, 2011.
  4. +/
  5. module Colors2;
  6. import core.runtime;
  7. import core.thread;
  8. import std.conv;
  9. import std.math;
  10. import std.range;
  11. import std.string;
  12. import std.utf;
  13. auto toUTF16z(S)(S s)
  14. {
  15. return toUTFz!(const(wchar)*)(s);
  16. }
  17. pragma(lib, "gdi32.lib");
  18. pragma(lib, "comdlg32.lib");
  19. import core.sys.windows.windef;
  20. import core.sys.windows.winuser;
  21. import core.sys.windows.wingdi;
  22. import core.sys.windows.winbase;
  23. import core.sys.windows.commdlg;
  24. string appName = "Colors2";
  25. string description = "Color Scroll";
  26. enum ID_TIMER = 1;
  27. HINSTANCE hinst;
  28. extern (Windows)
  29. int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
  30. {
  31. int result;
  32. try
  33. {
  34. Runtime.initialize();
  35. result = myWinMain(hInstance, hPrevInstance, lpCmdLine, iCmdShow);
  36. Runtime.terminate();
  37. }
  38. catch (Throwable o)
  39. {
  40. MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | MB_ICONEXCLAMATION);
  41. result = 0;
  42. }
  43. return result;
  44. }
  45. int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
  46. {
  47. static CHOOSECOLOR cc;
  48. static COLORREF crCustColors[16];
  49. cc.hwndOwner = NULL;
  50. cc.hInstance = NULL;
  51. cc.rgbResult = RGB(0x80, 0x80, 0x80);
  52. cc.lpCustColors = crCustColors.ptr;
  53. cc.Flags = CC_RGBINIT | CC_FULLOPEN;
  54. cc.lCustData = 0;
  55. cc.lpfnHook = NULL;
  56. cc.lpTemplateName = NULL;
  57. return ChooseColor(&cc);
  58. }