unit MainUnit;
interface
var
PlugInID: Integer;
implementation
uses
Windows, Messages, SysUtils, Dialogs, Controls, Menus, Classes, PlugInIntf;
const
Name = 'DUserPlugin';
SubName = 'Security';
Desc = 'Dynamic User Plugin';
var
ControlAtom: TAtom;
ControlAtomString: string;
RM_GetObjectInstance: DWORD;
OldProc: FARPROC;
function FindControlEx(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and (OwningProcess = GetCurrentProcessId) then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
end;
end;
function HookPLSQLAppProc(hwnd, msg, wParam, lParam: LongInt): LRESULT; stdcall;
//var
// ActiveCtrl: TForm;
begin
case msg of
WM_CONTEXTMENU:
begin
//ActiveCtrl := TForm(FindControl1(hwnd));
//if ActiveCtrl <> nil then
//begin
//ShowMessage(ActiveCtrl.Name);
//ShowMessage(PChar(IntToHex(ActiveCtrl.Menu.Handle, 8)));
//if (form.PopupMenu <> nil) and (form.PopupMenu.Items <> nil) then
//begin
// ShowMessage(IntToStr(form.PopupMenu.Items.Count));
//end;
//end;
end;
WM_INITMENUPOPUP:
begin
IDE_DebugLog('333333333333333333333333333333333333333');
IDE_DebugLog(PChar(IntToHex(hwnd, 8)));
IDE_DebugLog('444444444444444444444444444444444444444');
end;
end;
Result := CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
end;
// This function receives a Plug-In ID from PL/SQL Developer and should return a
// description for the Plug-In. The returned description should be unique for your Plug-In
// and will be displayed in the Plug-In configuration dialog. The ID identifies your Plug-In
// and can be used in other callback functions.
function IdentifyPlugIn(ID: Integer): PChar; cdecl;
begin
PlugInID := ID;
Result := Desc;
end;
// This function is called when the Plug-In is loaded into memory. You can use it to do
// some one-time initialization. PL/SQL Developer is not logged on yet and you can’t
// use the callback functions, so you are limited in the things you can do.
procedure OnActivate; cdecl;
begin
//IDE_DebugLog('1111111111111111111111111111111111');
//OldProc := Pointer(GetWindowLong(IDE_GetWindowHandle(), GWL_WNDPROC));
//SetWindowLong(IDE_GetWindowHandle(), GWL_WNDPROC, Integer(@HookPLSQLAppProc));
//IDE_DebugLog('Hook success');
IDE_DebugLog('Plugin Active');
end;
procedure WriteMenuItem(MenuItem: TMenuItem; Level: Integer; Buffer: TStringList);
var
i: Integer;
begin
Buffer.Add(StringOfChar('-', Level) + MenuItem.Caption);
if MenuItem.Count > 0 then
for i := 0 to MenuItem.Count - 1 do
WriteMenuItem(MenuItem.Items[i], Level + 1, Buffer);
end;
procedure OnPopup(ObjectType, ObjectName: PChar); cdecl;
var
ActiveCtrl: TWinControl;
MenuItem: TMenuItem;
i: Integer;
rr: TStringList;
begin
IDE_DebugLog('处理全部的弹出开始');
ActiveCtrl := FindControlEx(IDE_GetWindowHandle());
if ActiveCtrl <> nil then
begin
rr := TStringList.Create;
try
for i := 0 to ActiveCtrl.ComponentCount - 1 do
begin
if ActiveCtrl.Components[i].ClassName = 'TMenuItem' then
begin
MenuItem := TMenuItem(ActiveCtrl.Components[i]);
WriteMenuItem(MenuItem, 0, rr);
if MenuItem.Caption = 'Drop' then
begin
MenuItem.Enabled := False;
MenuItem.OnClick := nil;
end;
end;
if ActiveCtrl.Components[i].ClassName = 'TPopupMenu' then
begin
ShowMessage(TPopupMenu(ActiveCtrl.Components[i]).Name);
end;
end;
finally
rr.SaveToFile('d://test.txt');
rr.Free;
end;
end;
end;
// The PlugIn name (if defined) will be used for online updates, and as name for
// command window PlugIn commands. If you want your PlugIn to be handled by online
// updates, please contact support.
// If this function is not defined, the PlugInName will be the dll filename.
function PlugInName: PChar; cdecl;
begin
Result := Name;
end;
// The subname will be added to the PlugInName. Possible values are ‘Trial’ or ‘Beta’.
function PlugInSubName: PChar; cdecl;
begin
Result := SubName;
end;
procedure OnDeactivate; cdecl;
begin
//SetWindowLong(IDE_GetWindowHandle(), GWL_WNDPROC, Integer(OldProc));
//IDE_DebugLog('UnHook success');
IDE_DebugLog('Plugin Deactive');
end;
exports
IdentifyPlugIn,
RegisterCallback,
OnActivate,
PlugInName,
PlugInSubName,
OnPopup,
OnDeactivate;
initialization
ControlAtomString := Format('ControlOfs%.8X%.8X', [GetModuleHandle(nil), GetCurrentThreadID]);
ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
finalization
GlobalDeleteAtom(ControlAtom);
ControlAtomString := '';
end.