Leaked source code of windows server 2003
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.

209 lines
5.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // escbutt.c - escape button control functions
  24. ////
  25. #include "winlocal.h"
  26. #include "escbutt.h"
  27. #include "trace.h"
  28. ////
  29. // private definitions
  30. ////
  31. // escbutt control struct
  32. //
  33. typedef struct ESCBUTT
  34. {
  35. WNDPROC lpfnButtWndProc;
  36. DWORD dwFlags;
  37. } ESCBUTT, FAR *LPESCBUTT;
  38. // helper functions
  39. //
  40. LRESULT DLLEXPORT CALLBACK EscButtWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  41. ////
  42. // public functions
  43. ////
  44. // EscButtInit - initialize escape subclass from button control
  45. // <hwndButt> (i) button control to be subclassed
  46. // <dwFlags> (i) subclass flags
  47. // reserved must be zero
  48. // return 0 if success
  49. //
  50. int DLLEXPORT WINAPI EscButtInit(HWND hwndButt, DWORD dwFlags)
  51. {
  52. BOOL fSuccess = TRUE;
  53. WNDPROC lpfnEscButtWndProc;
  54. HGLOBAL hEscButt;
  55. LPESCBUTT lpEscButt;
  56. if (hwndButt == NULL)
  57. fSuccess = TraceFALSE(NULL);
  58. // get pointer to escape subclass window proc
  59. //
  60. else if ((lpfnEscButtWndProc =
  61. (WNDPROC) MakeProcInstance((FARPROC) EscButtWndProc,
  62. (HINSTANCE) GetWindowWordPtr(GetParent(hwndButt), GWWP_HINSTANCE))) == NULL)
  63. fSuccess = TraceFALSE(NULL);
  64. // memory is allocated such that the client app owns it
  65. //
  66. else if ((hEscButt = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
  67. sizeof(ESCBUTT))) == NULL)
  68. fSuccess = TraceFALSE(NULL);
  69. else if ((lpEscButt = GlobalLock(hEscButt)) == NULL)
  70. fSuccess = TraceFALSE(NULL);
  71. // store old window proc address
  72. //
  73. else if ((lpEscButt->lpfnButtWndProc =
  74. (WNDPROC) GetWindowLongPtr(hwndButt, GWLP_WNDPROC)) == NULL)
  75. fSuccess = TraceFALSE(NULL);
  76. // store flags
  77. //
  78. else if ((lpEscButt->dwFlags = dwFlags) != dwFlags)
  79. fSuccess = TraceFALSE(NULL);
  80. else if (GlobalUnlock(hEscButt), FALSE)
  81. ;
  82. // store old window proc address as a property of the control window
  83. //
  84. else if (!SetProp(hwndButt, TEXT("hEscButt"), hEscButt))
  85. fSuccess = TraceFALSE(NULL);
  86. // replace old window proc with new window proc
  87. //
  88. else if ( !SetWindowLongPtr(hwndButt, GWLP_WNDPROC, (LONG_PTR) lpfnEscButtWndProc) )
  89. fSuccess = TraceFALSE(NULL);
  90. return fSuccess ? 0 : -1;
  91. }
  92. // EscButtTerm - terminate escape subclass from button control
  93. // <hwndButton> (i) subclassed button control
  94. // return 0 if success
  95. //
  96. int DLLEXPORT WINAPI EscButtTerm(HWND hwndButt)
  97. {
  98. BOOL fSuccess = TRUE;
  99. WNDPROC lpfnEscButtWndProc;
  100. HGLOBAL hEscButt;
  101. LPESCBUTT lpEscButt;
  102. if (hwndButt == NULL)
  103. fSuccess = TraceFALSE(NULL);
  104. // get pointer to escape subclass window proc
  105. //
  106. else if ((lpfnEscButtWndProc =
  107. (WNDPROC) GetWindowLongPtr(hwndButt, GWLP_WNDPROC)) == NULL)
  108. fSuccess = TraceFALSE(NULL);
  109. // retrieve old window proc address from window property
  110. //
  111. else if ((hEscButt = GetProp(hwndButt, TEXT("hEscButt"))) == NULL)
  112. fSuccess = TraceFALSE(NULL);
  113. else if ((lpEscButt = GlobalLock(hEscButt)) == NULL ||
  114. lpEscButt->lpfnButtWndProc == NULL)
  115. fSuccess = TraceFALSE(NULL);
  116. // replace new window proc with old window proc
  117. //
  118. else if ( !SetWindowLongPtr(hwndButt, GWLP_WNDPROC, (LONG_PTR) lpEscButt->lpfnButtWndProc) )
  119. fSuccess = TraceFALSE(NULL);
  120. else if (GlobalUnlock(hEscButt), FALSE)
  121. ;
  122. //
  123. //
  124. else if (( hEscButt = RemoveProp(hwndButt, TEXT("hEscButt"))) == NULL)
  125. fSuccess = TraceFALSE(NULL);
  126. else if (GlobalFree(hEscButt) != NULL)
  127. fSuccess = TraceFALSE(NULL);
  128. return fSuccess ? 0 : -1;
  129. }
  130. ////
  131. // helper functions
  132. ////
  133. // EscButtWndProc - window procedure for escape button control
  134. //
  135. LRESULT DLLEXPORT CALLBACK EscButtWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  136. {
  137. BOOL fSuccess = TRUE;
  138. LRESULT lResult;
  139. HGLOBAL hEscButt;
  140. LPESCBUTT lpEscButt;
  141. // retrieve old window proc address from window property
  142. //
  143. if ((hEscButt = GetProp(hwnd, TEXT("hEscButt"))) == NULL)
  144. fSuccess = TraceFALSE(NULL);
  145. else if ((lpEscButt = GlobalLock(hEscButt)) == NULL ||
  146. lpEscButt->lpfnButtWndProc == NULL)
  147. fSuccess = TraceFALSE(NULL);
  148. switch (msg)
  149. {
  150. // convert escape key messages into spacebar messages
  151. //
  152. case WM_KEYUP:
  153. case WM_KEYDOWN:
  154. case WM_CHAR:
  155. if (wParam == VK_ESCAPE)
  156. wParam = VK_SPACE;
  157. // fall through rather than break;
  158. default:
  159. {
  160. // call old window proc
  161. //
  162. if (fSuccess)
  163. lResult = CallWindowProc(lpEscButt->lpfnButtWndProc, hwnd, msg, wParam, lParam);
  164. else
  165. lResult = 0L;
  166. }
  167. break;
  168. }
  169. if (fSuccess)
  170. GlobalUnlock(hEscButt);
  171. return lResult;
  172. }