你可以使用
function GetClassInfo(hInstance: HINST; lpClassName: PChar; var lpWndClass: TWndClass): BOOL;
我想这就是雷米想要做的。
就像是:
Function IsRichEdit(MyControl : TWinControl):Boolean;
var
Info : TWNDClass;
begin
Result := False;
if GetClassInfo(HInstance,PCHAR('RICHEDIT'),Info) and (Info.lpfnWndProc = MyControl.DefWndProc) then
Result := True
else if GetClassInfo(HInstance,PCHAR('RICHEDIT20A'),Info) and (Info.lpfnWndProc = MyControl.DefWndProc) then
Result := True
else if GetClassInfo(HInstance,PCHAR('RICHEDIT30A'),Info) and (Info.lpfnWndProc = MyControl.DefWndProc) then
Result := True
else if GetClassInfo(HInstance,PCHAR('RICHEDIT41A'),Info) and (Info.lpfnWndProc = MyControl.DefWndProc) then
Result := True
else if GetClassInfo(HInstance,PCHAR('RICHEDIT50A'),Info) and (Info.lpfnWndProc = MyControl.DefWndProc) then
Result := True
end;
如果您使用的是 Delphi > 2007,那么您可能还需要测试“W”(unicode)版本,例如“RICHEDIT20W”
编辑:添加 Info.WndProc 测试以匹配控件。
奇怪的是,这对 cxControls 不起作用,因为 cxRichEdit 不是使用富编辑窗口的控件(它是一个包含,因此您需要传递 cxControl.InnerControl 以使其返回 true)。
编辑除了创建的第一个richedit 控件之外,我无法让它工作。