hook.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C++ version by Glenn Fiedler ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. }
  17. Constructor TDirectXHook.Create(console : Pointer; window : HWND; thread : DWord; _cursor, managed, fullscreen : Boolean);
  18. Begin
  19. m_console := console;
  20. m_cursor := _cursor;
  21. m_managed := managed;
  22. m_fullscreen := fullscreen;
  23. LOG('creating window hook');
  24. Inherited Create(window, thread);
  25. End;
  26. Destructor TDirectXHook.Destroy;
  27. Begin
  28. LOG('destroying window hook');
  29. Inherited Destroy;
  30. End;
  31. Procedure TDirectXHook.cursor(flag : Boolean);
  32. Begin
  33. m_cursor := flag;
  34. End;
  35. Function TDirectXHook.WndProc(hWnd : HWND; message : DWord; wParam : WPARAM; lParam : LPARAM) : LRESULT;
  36. Var
  37. active : Boolean;
  38. thread : DWord;
  39. placement : WINDOWPLACEMENT;
  40. console : TDirectXConsole;
  41. Begin
  42. Case message Of
  43. WM_PAINT : Begin
  44. LOG('TDirectXHook WM_PAINT');
  45. { paint console }
  46. TDirectXConsole(m_console).paint;
  47. End;
  48. WM_ACTIVATEAPP : Begin
  49. LOG('TDirectXHook WM_ACTIVATEAPP');
  50. { get window message data }
  51. active := Boolean(wParam);
  52. thread := lParam;
  53. { check active flag }
  54. If active = False Then
  55. Begin
  56. { deactivate }
  57. deactivate;
  58. { check cursor and fullscreen }
  59. If (Not m_cursor) And m_fullscreen Then
  60. { show cursor }
  61. Win32Cursor_resurrect;
  62. End
  63. Else
  64. Begin
  65. { check cursor and fullscreen }
  66. If (Not m_cursor) And m_fullscreen Then
  67. Begin
  68. { get window placement for active app }
  69. If Not GetWindowPlacement(hWnd, placement) Then
  70. { on failure set to normal show }
  71. placement.showCmd := SW_SHOWNORMAL;
  72. { check show command is not minimize }
  73. If placement.showCmd <> SW_SHOWMINIMIZED Then
  74. {hide cursor}
  75. Win32Cursor_kill;
  76. End;
  77. { activate }
  78. activate;
  79. End;
  80. { handled }
  81. WndProc := 1;
  82. Exit;
  83. End;
  84. WM_SETCURSOR : Begin
  85. { check cursor }
  86. If Not m_cursor Then
  87. { hide cursor }
  88. SetCursor(12);
  89. { handled }
  90. WndProc := 1;
  91. Exit;
  92. End;
  93. WM_CLOSE : Begin
  94. LOG('TDirectXHook WM_CLOSE');
  95. If m_managed Then
  96. Begin
  97. console := TDirectXConsole(m_console);
  98. { close console }
  99. console.close;
  100. { note: at this point the hook object has been destroyed by the console! }
  101. { internal console shutdown }
  102. console.internal_shutdown;
  103. { halt }
  104. Halt(0);
  105. End;
  106. { handled }
  107. WndProc := 1;
  108. Exit;
  109. End;
  110. End;
  111. { unhandled }
  112. WndProc := 0;
  113. End;
  114. Procedure TDirectXHook.activate;
  115. Var
  116. console : TDirectXConsole;
  117. display : TDirectXDisplay;
  118. primary : TDirectXPrimary;
  119. Begin
  120. console := TDirectXConsole(m_console);
  121. { check if open }
  122. If console.m_open Then
  123. Begin
  124. LOG('activate');
  125. { get console object references }
  126. display := console.m_display;
  127. primary := console.m_primary;
  128. { check if primary is not active }
  129. If Not primary.active Then
  130. Begin
  131. { save display }
  132. display.save;
  133. { activate primary }
  134. primary.activate;
  135. End;
  136. End;
  137. End;
  138. Procedure TDirectXHook.deactivate;
  139. Var
  140. console : TDirectXConsole;
  141. display : TDirectXDisplay;
  142. primary : TDirectXPrimary;
  143. Begin
  144. console := TDirectXConsole(m_console);
  145. { check if open }
  146. If console.m_open Then
  147. Begin
  148. LOG('deactivate');
  149. { get console object references }
  150. display := console.m_display;
  151. primary := console.m_primary;
  152. { check if primary is not active }
  153. If primary.active Then
  154. Begin
  155. { save primary }
  156. primary.save;
  157. { deactivate primary }
  158. primary.deactivate;
  159. { restore display }
  160. display.restore;
  161. End;
  162. End;
  163. End;