PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/Samples/Chap13/PopPad/PopFont.d

http://github.com/AndrejMitrovic/DWinProgramming
D | 81 lines | 64 code | 13 blank | 4 comment | 0 complexity | b32df18eea98b68b2b568ededb0ae5a8 MD5 | raw file
  1. /+
  2. + Copyright (c) Charles Petzold, 1998.
  3. + Ported to the D Programming Language by Andrej Mitrovic, 2011.
  4. +/
  5. module PopFont;
  6. import core.memory;
  7. import core.runtime;
  8. import core.thread;
  9. import std.conv;
  10. import std.math;
  11. import std.range;
  12. import std.string;
  13. import std.utf;
  14. auto toUTF16z(S)(S s)
  15. {
  16. return toUTFz!(const(wchar)*)(s);
  17. }
  18. pragma(lib, "gdi32.lib");
  19. pragma(lib, "comdlg32.lib");
  20. pragma(lib, "winmm.lib");
  21. import core.sys.windows.windef;
  22. import core.sys.windows.winuser;
  23. import core.sys.windows.wingdi;
  24. import core.sys.windows.winbase;
  25. import core.sys.windows.commdlg;
  26. import core.sys.windows.mmsystem;
  27. static LOGFONT logfont;
  28. static HFONT hFont;
  29. BOOL PopFontChooseFont(HWND hwnd)
  30. {
  31. CHOOSEFONT cf;
  32. cf.hwndOwner = hwnd;
  33. cf.hDC = NULL;
  34. cf.lpLogFont = &logfont;
  35. cf.iPointSize = 0;
  36. cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS;
  37. cf.rgbColors = 0;
  38. cf.lCustData = 0;
  39. cf.lpfnHook = NULL;
  40. cf.lpTemplateName = NULL;
  41. cf.hInstance = NULL;
  42. cf.lpszStyle = NULL;
  43. cf.nFontType = 0; // Returned from ChooseFont
  44. cf.nSizeMin = 0;
  45. cf.nSizeMax = 0;
  46. return ChooseFont(&cf);
  47. }
  48. void PopFontInitialize(HWND hwndEdit)
  49. {
  50. GetObject(GetStockObject(SYSTEM_FONT), LOGFONT.sizeof, cast(PTSTR)&logfont);
  51. hFont = CreateFontIndirect(&logfont);
  52. SendMessage(hwndEdit, WM_SETFONT, cast(WPARAM)hFont, 0);
  53. }
  54. void PopFontSetFont(HWND hwndEdit)
  55. {
  56. HFONT hFontNew;
  57. RECT rect;
  58. hFontNew = CreateFontIndirect(&logfont);
  59. SendMessage(hwndEdit, WM_SETFONT, cast(WPARAM)hFontNew, 0);
  60. DeleteObject(hFont);
  61. hFont = hFontNew;
  62. GetClientRect(hwndEdit, &rect);
  63. InvalidateRect(hwndEdit, &rect, TRUE);
  64. }
  65. void PopFontDeinitialize()
  66. {
  67. DeleteObject(hFont);
  68. }