救火:如何获知其它程序某个Edit是否处于焦点状态(等待输入)? ( 积分: 100 )

  • 主题发起人 主题发起人 ax518598
  • 开始时间 开始时间
A

ax518598

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用delphi编程,获得另外一个程序(该程序只有两个输入框)中光标停在哪一个输入框上,以及该输入框中当前输入的内容,为自己程序所用。<br>请指点一条&quot;生路&quot;。(我比较菜,拜托大虾们给点代码给小弟学习学习)
 
我想用delphi编程,获得另外一个程序(该程序只有两个输入框)中光标停在哪一个输入框上,以及该输入框中当前输入的内容,为自己程序所用。<br>请指点一条&quot;生路&quot;。(我比较菜,拜托大虾们给点代码给小弟学习学习)
 
用findwindow获得窗体的句柄,再根据ActiveControl进行判断是哪个输入框得到焦点。<br>具体用法自己查查。
 
方法:<br>1、找到当前窗体的句柄。<br>2、用windows的消息机制获得对方内容。<br>具体获得方法因控件类型不同而不同,具体可以查看windows的控件的消息处理方法。
 
通过FindWindow确实能找到目标窗口,返回值为MainHandle:THandle型变量,但如何引用它的ActiveControl呢?是MainHandle.ActiveControl还是其它表示方法?
 
浪费时间
 
[:(!]我都想知呀
 
procedure TForm1.Button2Click(Sender: TObject);<br>var<br> &nbsp;h, YH, MH, DH, BtnH, LblH, TMPH: THandle;<br> &nbsp;s, i, Y, M, D, DAYCount, Charcount: integer;<br> &nbsp;sl: TstringList;<br> &nbsp;str, strY, strM, strD, nowstr, oldSTR: string;<br> &nbsp;p: PChar;<br><br>begin<br> &nbsp;Button2.Enabled := false;<br> &nbsp;YH := StrToInt(Edit1.Text);<br> &nbsp;MH := StrToInt(Edit2.Text);<br> &nbsp;DH := StrToInt(Edit3.Text);<br> &nbsp;BtnH := StrToInt(Edit4.Text);<br> &nbsp;LblH := StrToInt(Edit5.Text);<br> &nbsp;p := GetMemory(255);<br> &nbsp;sl := TStringList.Create;<br> &nbsp;for s := 10 downto 2 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;sl.Clear;<br><br> &nbsp; &nbsp; &nbsp;for i := 0 to 99 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Y := s * 100 + i;<br><br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(YH, WM_SETTEXT, 0, longint(pchar(inttostr(Y))));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strY := inttostr(Y);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for m := 1 to 12 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(MH, WM_SETTEXT, 0, longint(pchar(inttostr(M))));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strM := RightStr('00' + inttostr(m), 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if m = 2 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if y mod 4 = 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAYCount := 29<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAYCount := 28;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if m in [1, 3, 5, 7, 8, 10, 12] then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAYCount := 31<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAYCount := 30;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sleep(30);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application.ProcessMessages;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for D := 1 to DAYCount do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(DH, WM_SETTEXT, 0, longint(pchar(inttostr(D))));<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(BtnH, BM_CLICK, 0, 0);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strD := RightStr('00' + inttostr(d), 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Charcount := 255;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(LblH, p, Charcount);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := strY + '-';<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := str + strM;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := str + '-';<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := str + strD;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := str + '=';<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nowstr := StrPas(p);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nowstr := StringReplace(nowstr, #13, ',',[rfReplaceAll]);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nowstr := StringReplace(nowstr, #10, ',',[rfReplaceAll]);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if oldSTR &amp;lt;&amp;gt; nowstr then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str := str + nowstr;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;oldSTR := nowstr;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := FindWindowEx(GetParent(yh),0, nil, '两千年中西历速查');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if h &amp;lt;&amp;gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(h, WM_CLOSE, 0, 0);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sl.Add(str);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;sl.SaveToFile('c:/' + inttostr(s) + '.TXT');<br><br> &nbsp; &nbsp;end;<br><br><br> &nbsp;FreeAndNil(sl);<br>end;<br>
 
<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;WH, YH, MH, DH, BtnH, LblH, TMPH: THandle;<br><br>begin<br> &nbsp;wh := 0;<br> &nbsp;YH := 0;<br> &nbsp;MH := 0;<br> &nbsp;DH := 0;<br> &nbsp;BtnH := 0;<br> &nbsp;LblH := 0;<br> &nbsp;WH := FindWindow(nil, '两千年中西历速查');<br><br>// &nbsp;TMPH := GetWindow(WH, GW_CHILD);<br>// &nbsp;TMPH := GetWindow(TMPH, );<br><br>end;
 
// <br>上面 是我 读 , '两千年中西历速查' 数据的程序
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部