開發開發

          軟件的生命
          隨筆 - 18, 文章 - 0, 評論 - 0, 引用 - 0
          數據加載中……

          Testaaa

          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.

          posted on 2011-09-26 15:26 wm6run 閱讀(211) 評論(0)  編輯  收藏

          主站蜘蛛池模板: 惠东县| 玛曲县| 岳西县| 固镇县| 江阴市| 平顶山市| 同心县| 高青县| 莱阳市| 夏邑县| 永州市| 景洪市| 比如县| 依安县| 右玉县| 秦皇岛市| 高州市| 桂阳县| 江都市| 澎湖县| 习水县| 陵水| 都匀市| 九龙县| 长乐市| 绥芬河市| 皮山县| 老河口市| 扎赉特旗| 靖远县| 三门峡市| 隆林| 铜山县| 弥勒县| 乌拉特前旗| 六盘水市| 定西市| 五台县| 保康县| 施甸县| 凤庆县|