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.

115 lines
3.4 KiB

  1. /*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  2. **
  3. ** FILE: BUTTON.CPP
  4. ** DATE: 5/12/98
  5. ** PROJ: NT5
  6. ** PROG: BLJ
  7. ** COMMENTS:
  8. **
  9. ** DESCRIPTION: Window class custom buttons
  10. **
  11. ** HISTORY:
  12. ** DATE WHO WHAT
  13. ** ---- --- ----
  14. ** 5/12/98 a-brycej Wrote it.
  15. **
  16. **
  17. ** Copyright (C) Microsoft 1998. All Rights Reserved.
  18. **
  19. **~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
  20. #include <malloc.h> // for _alloca
  21. #include "resrc1.h"
  22. #include "cplsvr1.h"
  23. extern HINSTANCE ghInst;
  24. extern CDIGameCntrlPropSheet_X *pdiCpl;
  25. // Colour of text for buttons!
  26. #define TEXT_COLOUR RGB(202,202,202)
  27. HICON hIconArray[2];
  28. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. //
  30. // FUNCTION : ButtonWndProc
  31. // REMARKS : The callback function for the CustomButton Window.
  32. //
  33. // PARAMS : The usual callback funcs for message handling
  34. //
  35. // RETURNS : LRESULT - Depends on the message
  36. // CALLS :
  37. // NOTES :
  38. //
  39. LRESULT CALLBACK ButtonWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  40. {
  41. switch( iMsg )
  42. {
  43. case WM_PAINT:
  44. {
  45. PAINTSTRUCT *pps = new (PAINTSTRUCT);
  46. assert (pps);
  47. HDC hDC = BeginPaint(hWnd, pps);
  48. // Draw the appropriate icon
  49. DrawIconEx(hDC, 0, 0, hIconArray[GetWindowLong(hWnd, GWLP_USERDATA)], 0, 0, 0, NULL, DI_NORMAL);
  50. // Prepare the DC for the text
  51. SetBkMode (hDC, TRANSPARENT);
  52. SetTextColor(hDC, TEXT_COLOUR);
  53. // Enforce the proper size!
  54. pps->rcPaint.top = pps->rcPaint.left = 0;
  55. pps->rcPaint.bottom = 33;
  56. pps->rcPaint.right = 30;
  57. TCHAR tsz[3];
  58. // Draw the Number
  59. DrawText (hDC, (LPCTSTR)tsz, GetWindowText(hWnd, tsz, sizeof(tsz)/sizeof(TCHAR)), &pps->rcPaint, DT_VCENTER|DT_CENTER|DT_NOPREFIX|DT_SINGLELINE|DT_NOCLIP);
  60. SetBkMode(hDC, OPAQUE);
  61. EndPaint (hWnd, pps);
  62. if( pps )
  63. delete (pps);
  64. }
  65. return(FALSE);
  66. default:
  67. return(DefWindowProc(hWnd, iMsg,wParam, lParam));
  68. }
  69. return(FALSE);
  70. }
  71. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. //
  73. // FUNCTION : RegisterCustomButtonClass
  74. // REMARKS : Registers the Custom Button control window.
  75. //
  76. // PARAMS : hInstance - Used for the call to RegisterClassEx
  77. //
  78. // RETURNS : TRUE - if successfully registered
  79. // FALSE - failed to register
  80. // CALLS : RegisterClassEx
  81. // NOTES :
  82. //
  83. extern ATOM RegisterCustomButtonClass()
  84. {
  85. LPWNDCLASSEX pCustCtrlClass = (LPWNDCLASSEX)_alloca(sizeof(WNDCLASSEX));
  86. assert (pCustCtrlClass);
  87. ZeroMemory(pCustCtrlClass, sizeof(WNDCLASSEX));
  88. pCustCtrlClass->cbSize = sizeof(WNDCLASSEX);
  89. pCustCtrlClass->style = CS_CLASSDC;
  90. pCustCtrlClass->lpfnWndProc = ButtonWndProc;
  91. pCustCtrlClass->hInstance = ghInst;
  92. pCustCtrlClass->lpszClassName = TEXT("TESTBUTTON");
  93. return(RegisterClassEx( pCustCtrlClass ));
  94. }