Hello people
I'm sorry about the title
I'm having another problem.
I'm using
SetWindowLong with
GWL_USERDATA to store a pointer, doing that I dont have to declare a dinamic array to store the values returned by
SetWindowLong and
GWL_WNDPROC.
So I have this to store a pointer to the window:
Delphi-Quellcode:
procedure NotepadCreated(
Handle: HWND);
var
Win: PWinInfo;
begin
New(Win);
Win^.Handle :=
Handle;
Win^.OldPtr := GetWindowLong(
Handle, GWL_WNDPROC);
{ lets subclass it }
SetWindowLong(
Handle, GWL_WNDPROC, Integer(@NotepadProc));
{ assign pointer to window }
SetWindowLong(
Handle, GWL_USERDATA, Integer(@Win));
end;
when the hook sends me a message that notepad is clossing I have this:
Delphi-Quellcode:
procedure NotepadDestroyed(
Handle: HWND);
var
Win: PWinInfo;
begin
Win := PWinInfo(GetWindowLong(
Handle, GWL_USERDATA));
{ set oldptr back}
SetWindowLong(
Handle, GWL_WNDPROC, Win^.OldPtr);
{ free memory pointer}
Dispose(Win);
end;
Well, that works good.
The problem is when closing my application.
I have to set back all notepad pointers so I call CleanNotepadPtrs.
Delphi-Quellcode:
function EnumWins(
Handle: HWND; lParam: LPARAM): Boolean;
stdcall;
var
szClass:
array [0..256]
of Char;
Win: PWinInfo;
begin
ZeroMemory(@szClass, 256);
GetClassName(
Handle, szClass, 256);
if szClass = '
Notepad'
then
begin
Win := PWinInfo(GetWindowLong(
Handle, GWL_USERDATA));
{ set back ptr }
SetWindowLong(
Handle, GWL_WNDPROC, Win^.OldPtr);
{ free memory }
Dispose(Win);
end;
Result := True;
end;
procedure CleanNotepadPtrs;
begin
EnumWindows(@EnumWins, 0);
end;
Well, You see, It's the same as before, but Notepad crashes.
do you know what could I been doing wrong ?
I have also tried to send a message inside NotePadWndProc and
read the pointer (GWL_USERDATA) and then that sets back the pointer (GWL_WNDPROC), but also causes an error
Thank You.