简单问题,重金急寻答案(150分)

  • 主题发起人 主题发起人 LSS
  • 开始时间 开始时间
L

LSS

Unregistered / Unconfirmed
GUEST, unregistred user!
按FORM上的相应TOOLBUTTON按钮(不能设置焦点的那种),<br>来模拟键盘输入全角字符(例如"¥",或"÷"),焦点在FORM<br>上的EDIT控件上,不一定在哪个控件上。<br>要求有简单例子,解决问题即可<br>
 
activecontrol
 
TForm1.ToolButton1Click(Sender: TObject);<br>begin<br>&nbsp; if Form1.ActiveControl is TEdit then<br>&nbsp; &nbsp; with Form1.ActiveControl as TEdit do<br>&nbsp; &nbsp; &nbsp; Text:=Text+'÷'<br>end;
 
ControlList
 
我的输入框不一定是EDIT,当前光标不一定在字符何处,也可能<br>光标选择一段文字,LeeChange 说的不行,我想通过发消息来模<br>拟键盘输入,类似使用keybd_event,Perform等等,
 
Try This: (Copy From 钱达智)<br><br>procedure SendDBCSString(hFocus: HWND; const sSend: string);<br>var<br>&nbsp; hActiveControl: HWND;<br>&nbsp; i: integer;<br>&nbsp; ch: byte;<br>begin<br>&nbsp; if hFocus = 0 then hFocus := GetFocus;<br>&nbsp; if hFocus = 0 then Exit;<br>&nbsp; i := 1;<br>&nbsp; while i &lt;= Length(sSend) do<br>&nbsp; begin<br>&nbsp; &nbsp; ch := byte(sSend);<br>&nbsp; &nbsp; // SendMessage(hFocus, WM_CHAR, ch, 0); // 这样子不行<br>&nbsp; &nbsp; if Windows.IsDBCSLeadByte(ch) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(i);<br>&nbsp; &nbsp; &nbsp; SendMessage(hFocus, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; SendMessage(hFocus, WM_IME_CHAR, word(ch), 0);<br>&nbsp; &nbsp; Inc(i);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; SendDBCSString(Memo1.handle, '你好!');<br>end;
 
TO Big_Z:<br>&nbsp; 您给我的例子不好使,请您试一下,对于英文好使,双字节字符有问题,<br>针对您的回答,如何得到当前光标所在的焦点呢,如果没有焦点,如何模<br>拟输入呢?感谢您的回答,请继续...
 
haa haa.. &nbsp;???
 
什么意思???
 
&gt; 请您试一下<br>Oh, 我试过的!<br>&gt; 双字节字符有问题<br>能具体点吗?<br>&gt; 如何得到当前光标所在的焦点呢<br>调用 API 函数:<br>&nbsp; hFocus := GetFocus;<br>&gt; 如果没有焦点<br>如果没有焦点,那么无法输入,<br>&nbsp; 除非是指定需输入的控件(Window)的 Handle<br>&nbsp; SendDBCSString(Memo1.handle, '你好!');<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; SpeedButton1: TSpeedButton;<br>&nbsp; &nbsp; SpeedButton2: TSpeedButton;<br>&nbsp; &nbsp; procedure SpeedButton1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure SpeedButton2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure SendDBCSString(hFocus: HWND; const sSend: string);<br>var<br>&nbsp; hActiveControl: HWND;<br>&nbsp; i: integer;<br>&nbsp; ch: byte;<br>begin<br>&nbsp; if hFocus = 0 then hFocus := GetFocus;<br>&nbsp; if hFocus = 0 then Exit;<br>&nbsp; i := 1;<br>&nbsp; while i &lt;= Length(sSend) do<br>&nbsp; begin<br>&nbsp; &nbsp; ch := byte(sSend);<br>&nbsp; &nbsp; if Windows.IsDBCSLeadByte(ch) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(i);<br>&nbsp; &nbsp; &nbsp; SendMessage(hFocus, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; SendMessage(hFocus, WM_IME_CHAR, word(ch), 0);<br>&nbsp; &nbsp; Inc(i);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.SpeedButton1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;SendDBCSString(0, '¥');<br>end;<br><br>procedure TForm1.SpeedButton2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;SendDBCSString(Memo1.Handle, '¥');<br>end;<br><br><br>end.
 
十分抱歉,你和程序我在WIN98下使用好使,我使的是WINDOWS2000,<br>所以会出现不好使的状况,可能是有些API,WIN2000不支持,请问<br>如何才能让两种操作系统下都好使?(因为我使用WIN2000,我的用<br>户使用WIN98)<br>多谢,你好快,新回答我正在测试
 
十分抱歉,我是在 NT (SP6) 上测试通过的,<br>我没有 Win 2000,<br>而且听说 Win 2000 有 n 万多 Bug,<br>且对硬件有一定的要求,0_0?!<br>……?<br><br>声明一下,我无意诋毁微软的产品,Just 道听途说!
 
多谢Big_Z,就到这里吧
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
750
DelphiTeacher的专栏
D
后退
顶部