歪
歪就歪
Unregistered / Unconfirmed
GUEST, unregistred user!
300分求详细解决方案:<br><br>在Notepad上加入自己的菜单项,并能响应Onclick事件<br><br>这不是吃饱了撑的么!自己编一个Notepad不就得了?!没辙,<br>我老板非要这么做:用Delphi 程序找到运行着的Notepad,并<br>给它加上一个菜单项,当这菜单项被Click时,在显示的文件<br>的指定位置上加入一个字串。<br><br>我现在能做到的是:<br><br>1、用FindWindow找到Notepad<br>2、读出Notepad的内容,<br>3、用CreateWindows在Notepad上放一个“死”Button,(MenuItem<br>不会加,只好先用Button试试)<br>4、在内容中加入字串(但不是指定位置)<br><br>剩下的就实在是做不出来了。<br><br>代码如下:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Memo1: TMemo;<br> btnGetText: TButton;<br> btnWriteText: TButton;<br> Edit1: TEdit;<br> Edit2: TEdit;<br> btnCreateBtn: TButton;<br> btnCreateMenu: TButton;<br> procedure btnGetTextClick(Sender: TObject);<br> procedure btnWriteTextClick(Sender: TObject);<br> procedure btnCreateBtnClick(Sender: TObject);<br> procedure btnCreateMenuClick(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br><br>var<br> Form1: TForm1;<br> WindowCaption : String;<br> AimWindow : HWND;<br> FoundWnd : HWND;<br><br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.btnGetTextClick(Sender: TObject);<br>var<br> Buf:array [0..1024] of char;<br> Wnd : HWND;<br>begin<br> Memo1.Clear;<br> WindowCaption := Edit2.Text;<br> FoundWnd := 0;<br> AimWindow := FindWindow(PChar(WindowCaption), nil);<br> if AimWindow <>0 then begin<br> Wnd := GetWindow(AimWindow, GW_CHILD);<br> while Wnd <> 0 do begin<br> FoundWnd := Wnd;<br> SendMessage(Wnd, WM_GETTEXT, 1024, LongInt(@Buf));<br> Memo1.Lines.Add(Buf);<br> Wnd :=GetWindow(Wnd, GW_HWNDNEXT);<br> end;<br> end<br> else ShowMessage('Can not found Window: ' + WindowCaption)<br><br>end;<br><br>procedure TForm1.btnWriteTextClick(Sender: TObject);<br>var Wnd : HWND;<br> Buf : array [0..256] of char;<br> St : String;<br>begin<br> WindowCaption := Edit2.Text;<br> St := Edit1.Text;<br> AimWindow := FindWindow(PChar(WindowCaption), nil);<br> if AimWindow <> 0 then begin<br> Wnd := GetWindow(AimWindow, GW_CHILD);<br> if Wnd <> 0 then<br> SendMessage(Wnd, WM_SETTEXT, 256, LongInt(PChar(st)));<br> end;<br>end;<br><br>procedure TForm1.btnCreateBtnClick(Sender: TObject);<br>begin<br> if AimWindow <> 0 then begin<br> if (CreateWindowEx(WS_EX_TOPMOST, 'Button', nil,<br> ws_child or ws_visible or ws_border or bs_PushButton,<br> 10,10, 70, 30, AimWindow, 100, 0, nil)=0) then<br> showmessage('not work');<br> end<br> else showmessage('window not exist');<br>end;<br><br>procedure TForm1.btnCreateMenuClick(Sender: TObject);<br>begin<br> if AimWindow <> 0 then begin<br> if (CreateWindowEx(WS_EX_TOPMOST, 'SubMenu', nil,<br> ws_child or ws_visible or ws_border or bs_PushButton,<br> 10,10, 70, 30, AimWindow, 100, 0, nil)=0) then<br> showmessage('not work');<br> end<br> else showmessage('window not exist');<br><br>end;<br><br>end.<br><br>各位帮帮忙吧,别三言两语的,给我点CODE,我出300分。<br><br>这叫什么事儿,杀了老板的心都有!<br>