Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.4 KiB

  1. /* (C) Copyright Microsoft Corporation 1991-1994. All Rights Reserved */
  2. /* Revision History.
  3. 4/2/91 LaurieGr (AKA LKG) Ported to WIN32 / WIN16 common code
  4. */
  5. /* nftext.c
  6. *
  7. * Implements the no-flicker static text control ("td_nftext").
  8. *
  9. * This is NOT a general-purpose control (see the globals below).
  10. *
  11. * Note: most NoFlickerText controls use ANSI_VAR_FONT, but the status
  12. * control (ID_STATUSTXT) uses the font defined in the dialog box
  13. * template (e.g. Helv8). Also, the foreground color of most NoFlickerText
  14. * controls is RGB_FGNFTEXT, but the foreground color of the status control
  15. * is whatever the current value of <grgbStatusColor> is.
  16. *
  17. * Borrowed from ToddLa (with many, many modifications).
  18. */
  19. #include "nocrap.h"
  20. #include <windows.h>
  21. #include <mmsystem.h>
  22. #include <mmreg.h>
  23. #include "soundrec.h"
  24. /* statics */
  25. HFONT ghfontDialog = NULL; // font of dialog box
  26. void NEAR PASCAL
  27. NFTextPaint(HWND hwnd, HDC hdc)
  28. {
  29. RECT rc;
  30. TCHAR ach[128];
  31. int iLen;
  32. long lStyle;
  33. int xOrigin;
  34. GetClientRect(hwnd, &rc);
  35. iLen = GetWindowText(hwnd, ach, SIZEOF(ach));
  36. SetTextColor(hdc, grgbStatusColor);
  37. SelectObject(hdc, ghfontDialog);
  38. SetBkColor(hdc, RGB_BGNFTEXT);
  39. lStyle = GetWindowLong(hwnd, GWL_STYLE);
  40. {
  41. SIZE size;
  42. if (lStyle & SS_RIGHT)
  43. { GetTextExtentPoint(hdc, ach, iLen, &size);
  44. xOrigin = rc.right - size.cx;
  45. }
  46. else
  47. if (lStyle & SS_CENTER)
  48. { GetTextExtentPoint(hdc, ach, iLen, &size);
  49. xOrigin = (rc.right - size.cx) / 2;
  50. }
  51. else
  52. xOrigin = 0;
  53. }
  54. ExtTextOut(hdc, xOrigin, 0, ETO_OPAQUE,
  55. &rc, ach, iLen, NULL);
  56. }
  57. INT_PTR CALLBACK
  58. NFTextWndProc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  59. {
  60. PAINTSTRUCT ps;
  61. HDC hdc;
  62. switch (wMsg)
  63. {
  64. case WM_SETTEXT:
  65. DefWindowProc(hwnd, wMsg, wParam, lParam);
  66. hdc = GetDC(hwnd);
  67. if (hdc)
  68. {
  69. NFTextPaint(hwnd, hdc);
  70. ReleaseDC(hwnd, hdc);
  71. }
  72. return 0L;
  73. case WM_SETFONT:
  74. ghfontDialog = (HFONT)wParam;
  75. return 0L;
  76. case WM_ERASEBKGND:
  77. return 0L;
  78. case WM_PAINT:
  79. BeginPaint(hwnd, &ps);
  80. NFTextPaint(hwnd, ps.hdc);
  81. EndPaint(hwnd, &ps);
  82. return 0L;
  83. }
  84. return DefWindowProc(hwnd, wMsg, wParam, lParam);
  85. }