实现加到菜单里,点击Unit中出现文字了,但是怎样作为一个按钮加到IDE上还是没办法。
unit EditUnit;
interface
uses ToolsAPI, windows, messages;
type
TEditUnit = class(TNotifierObject, IOTAMenuWizard, IOTAWizard)
public
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
function GetMenuText: string;
end;
function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
procedure Register;
var
UnitHandle: hwnd;
implementation
uses Dialogs;
procedure Register;
begin
RegisterPackageWizard(TEditUnit.Create);
end;
//自定义的函数
/////////////////////////////////////////////////////
procedure sendkey(focushld: hwnd; ssend: string);
var
i: integer;
ch: byte;
begin
i := 1;
while i <= length(ssend) do
begin
ch := byte(ssend);
if windows.isDBCSLeadByte(ch) then
begin
inc(i);
sendmessage(focushld, WM_IME_CHAR, makeword(byte(ssend), ch), 0);
end
else
sendmessage(focushld, WM_IME_CHAR, word(ch), 0);
inc(i);
end;
PostMessage(focushld,WM_KEYDOWN,VK_RETURN,0);
end;
/////////////////////////////////////////////////////
function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL;
var
ClassName: array[0..255] of char; // this holds the class name of our child windows
begin
{get the class name of the given child window}
GetClassName(hWnd, ClassName, 255);
if ClassName = 'TEditControl' then
UnitHandle := hWnd;
{continue enumeration}
Result := TRUE;
end;
/////////////////////////////////////////////////////
procedure TEditUnit.Execute;
var
FoundWindow: hwnd;
begin
FoundWindow := FindWindowEx(0, 0, 'TEditWindow', nil);
{enumerate all child windows belonging to Form1}
EnumChildWindows(FoundWindow, @EnumerateChildWindows, 0);
if UnitHandle <> 0 then
begin
SetForegroundWindow(UnitHandle);
sendkey(UnitHandle, '//hello, welcome to delphibbs.com ! ');
keybd_event(vk_return, 1, 0, 0);
end
else
showmessage('can''t find UnitHandle,sorry sir.');
end;
function TEditUnit.GetIDString: string;
begin
Result := 'Save night';
end;
function TEditUnit.GetMenuText: string;
begin
Result := '&Save night';
end;
function TEditUnit.GetName: string;
begin
Result := 'Save night';
end;
function TEditUnit.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
end.