windebug.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 2000 by Pierre Muller
  5. Win32 specific debugger routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit windebug;
  13. interface
  14. type
  15. DebuggeeState = (Running_State,Stopped_State);
  16. procedure ChangeDebuggeeWindowTitleTo(State : DebuggeeState);
  17. function CygDrivePrefix : string;
  18. implementation
  19. uses
  20. gdbint,
  21. strings,
  22. windows;
  23. const
  24. CygDrivePrefixKey1 = 'Software';
  25. CygDrivePrefixKey2 = 'Cygnus Solutions';
  26. CygDrivePrefixKey3 = 'Cygwin';
  27. CygDrivePrefixKey4 = 'mounts v2';
  28. CygDrivePrefixKey = 'cygdrive prefix';
  29. function CygDrivePrefix : string;
  30. var
  31. i : longint;
  32. length : dword;
  33. Value : pchar;
  34. _type : dword;
  35. Key,NKey : HKey;
  36. begin
  37. Length:=0;
  38. Key:=HKEY_CURRENT_USER;
  39. i := RegOpenKeyEx(Key, CygDrivePrefixKey1, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  40. if i=ERROR_SUCCESS then
  41. begin
  42. Key:=NKey;
  43. i := RegOpenKeyEx(Key, CygDrivePrefixKey2, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  44. end;
  45. if i=ERROR_SUCCESS then
  46. begin
  47. RegCloseKey(Key);
  48. Key:=NKey;
  49. i := RegOpenKeyEx(Key, CygDrivePrefixKey3, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  50. end;
  51. if i=ERROR_SUCCESS then
  52. begin
  53. RegCloseKey(Key);
  54. Key:=NKey;
  55. i := RegOpenKeyEx(Key, CygDrivePrefixKey4, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  56. end;
  57. if i=ERROR_SUCCESS then
  58. begin
  59. RegCloseKey(Key);
  60. Key:=NKey;
  61. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, nil, @length);
  62. end;
  63. if i<>ERROR_SUCCESS then
  64. CygDrivePrefix:='/cygdrive'
  65. else
  66. Begin
  67. GetMem(Value,Length);
  68. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, LPByte(Value), @length);
  69. if i<>ERROR_SUCCESS then
  70. CygDrivePrefix:='/cygdrive'
  71. else
  72. CygDrivePrefix:=StrPas(Value);
  73. FreeMem(Value,Length);
  74. End;
  75. if Key<>HKEY_CURRENT_USER then
  76. RegCloseKey(Key);
  77. end;
  78. function GetWindowHandle(H : HWND; state : LPARAM) : WINBOOL;stdcall;
  79. var pTitle, pEnd, pNewTitle : pchar;
  80. len : longint;
  81. begin
  82. GetWindowHandle:=true;
  83. GetMem(pTitle,256);
  84. { we want all windows !! }
  85. if GetWindowThreadProcessId(H,nil)=inferior_pid then
  86. begin
  87. len:=GetWindowText(H,pTitle,256);
  88. if DebuggeeState(State) = Stopped_State then
  89. begin
  90. GetMem(pNewTitle,len+50);
  91. pEnd:=strpos(pTitle,'... running under FP debugger');
  92. if assigned(pEnd) then
  93. pEnd^:=#0;
  94. strcopy(pNewTitle,pTitle);
  95. strcat(pNewTitle,'... stopped by FP debugger');
  96. SetWindowText(H,pNewTitle);
  97. FreeMem(pNewTitle,len+50);
  98. end
  99. else if DebuggeeState(State) = Running_State then
  100. begin
  101. GetMem(pNewTitle,len+50);
  102. pEnd:=strpos(pTitle,'... stopped by FP debugger');
  103. if assigned(pEnd) then
  104. pEnd^:=#0;
  105. strcopy(pNewTitle,pTitle);
  106. strcat(pNewTitle,'... running under FP debugger');
  107. SetWindowText(H,pNewTitle);
  108. FreeMem(pNewTitle,len+50);
  109. end;
  110. end;
  111. FreeMem(pTitle,256);
  112. end;
  113. procedure ChangeDebuggeeWindowTitleTo(State : DebuggeeState);
  114. begin
  115. EnumWindows(EnumWindowsProc(@GetWindowHandle),longint(State));
  116. end;
  117. end.