I’m trying to subclass an WinApi edit control and override the paint method . so far i’m using the SetWindowLong function and the GWL_WNDPROC flag to override the original window procedure, then I receive the WM_PAINT message and use my own Paint logic, this is working good, but I’m wondering if it’s possible create a shadow TEdit component and pass the original handle of the Winapi EDIT control to the Delphi TEdit component and in that way i can use the shadow TEdit to get and set the properties of the EDIT control. Is that possible?
Update
Following the Remy suggestion about using the WindowHandle property I ended with this code, but is not working (setting the color of the edit control has not effect).
type
TWinControlCracker= class(TWinControl);
Var
ShadowEdit : TEdit;
newWndProc : Pointer;
EditHandle : NativeInt;
begin
EditHandle:=$00320530;//this is the handle to the EDIT control
ShadowEdit:=TEdit.Create(nil);
TWinControlCracker(ShadowEdit).WindowHandle:=EditHandle;
newWndProc := MakeObjectInstance(ShadowEdit.WindowProc);
SetWindowLong(EditHandle, GWL_WNDPROC, NativeInt(newWndProc));
ShadowEdit.Color:=clLime;
ShadowEdit.Refresh;
end;
TWinControl(whichTEditderives from) has a publicWindowHandleproperty that you can assign a non-VCLHWNDto. Just be sure to set the property back to 0 before you destroy theTEditor do anything that might cause it to call itsRecreateWnd()method internally, otherwise the WinAPI control will get destroyed. And don’t use anything that requires theTEdit.Parentproperty to be meaningful.