PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Samples/Chap02/ScrnSize/ScrnSize.d

http://github.com/AndrejMitrovic/DWinProgramming
D | 59 lines | 42 code | 13 blank | 4 comment | 0 complexity | 33cab5292482a1127dceda730a441402 MD5 | raw file
  1. /+
  2. + Copyright (c) Charles Petzold, 1998.
  3. + Ported to the D Programming Language by Andrej Mitrovic, 2011.
  4. +/
  5. module ScrnSize;
  6. import core.runtime;
  7. import std.string;
  8. import std.utf;
  9. auto toUTF16z(S)(S s)
  10. {
  11. return toUTFz!(const(wchar)*)(s);
  12. }
  13. pragma(lib, "gdi32.lib");
  14. import core.sys.windows.windef;
  15. import core.sys.windows.winuser;
  16. import core.sys.windows.wingdi;
  17. extern (Windows)
  18. int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
  19. {
  20. int result;
  21. try
  22. {
  23. Runtime.initialize();
  24. result = myWinMain(hInstance, hPrevInstance, lpCmdLine, iCmdShow);
  25. Runtime.terminate();
  26. }
  27. catch (Throwable o)
  28. {
  29. MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | MB_ICONEXCLAMATION);
  30. result = 0;
  31. }
  32. return result;
  33. }
  34. int myWinMain(HINSTANCE hInstance,
  35. HINSTANCE hPrevInstance,
  36. LPSTR lpCmdLine,
  37. int iCmdShow)
  38. {
  39. int cxScreen, cyScreen;
  40. cxScreen = GetSystemMetrics(SM_CXSCREEN);
  41. cyScreen = GetSystemMetrics(SM_CYSCREEN);
  42. auto echo = format("The screen is %s pixels wide by %s pixels high.",
  43. cxScreen, cyScreen).toUTF16z;
  44. MessageBox(NULL, echo, "Screen Size", 0);
  45. return 0;
  46. }