谁会用 wm_ime_char 消息? (200分)

  • 主题发起人 主题发起人 duckdo
  • 开始时间 开始时间
D

duckdo

Unregistered / Unconfirmed
GUEST, unregistred user!
//当用这一句时. <br>edit1.text := widechar(33394); &nbsp;<br>//edit.text = '色' <br><br>//当用这一句时. <br>sendmessage(edit1.handle,wm_ime_char,33394,0); &nbsp;<br>//edit.text &lt;&gt; '色'. <br>&nbsp;<br>为什么?
 
procedure TForm1.Button3Click(Sender: TObject);<br>var<br>&nbsp; S: string;<br>begin<br>&nbsp; S := '色';<br>&nbsp; SendMessage(Edit1.Handle, wm_ime_char, (ord(S[1]) shl 8) + ord(S[2]),0);<br>end;<br>看API帮助就知道了:<br>chCharCode1 = (TCHAR) wParam;<br>chCharCode2 = (TCHAR) wParam&gt;&gt;8;<br>chCharCode2是前面的引导字符,即为S[1],chCharCode1为S[2]<br>因为wParam右移8位得到chCharCode2,所以应该所Ord(S[1])左移8位。
 
同意楼上的说法
 
下面函数用于模拟VB里面的sendkey函数,可以向当前有焦点的输入<br>procedure SendKeys(Mstr:string);<br>var CharCode,i:integer;<br>&nbsp; &nbsp; Sstr:string;<br>&nbsp; &nbsp; focushld,windowhld:hwnd;<br>&nbsp; &nbsp; threadld:dword;<br>begin<br>&nbsp; windowhld:=GetForegroundWindow;<br>&nbsp; threadld:=GetWindowThreadProcessId(Windowhld,nil);<br>&nbsp; AttachThreadInput(GetCurrentThreadId,threadld,true);<br>&nbsp; Focushld:=getfocus;<br>&nbsp; AttachThreadInput(GetCurrentThreadId,threadld,false);<br>&nbsp; if focushld&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; for i:=1 to length(Mstr) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Sstr:=Mstr;<br>&nbsp; &nbsp; &nbsp; CharCode:=ord(Sstr[1]);<br>&nbsp; &nbsp; &nbsp; if length(Sstr)&gt;1 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CharCode:=CharCode shl 8+ord(Sstr[2]);<br>&nbsp; &nbsp; &nbsp; sendmessage(Focushld,WM_IME_CHAR,CharCode,1);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>
 
procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; ShowString('测试程序!');<br>end;<br><br>Procedure ShowString(S:String);<br>var<br>&nbsp; I:Integer;<br>&nbsp; Ch:Char;<br>begin<br>&nbsp; For I:=1 to Length(S) do<br>&nbsp; begin<br>&nbsp; &nbsp; Ch:=S;<br>&nbsp; &nbsp; SendMessage(Form1.Edit1.Handle,WM_IME_CHAR,Ord(Ch),0);<br>&nbsp; end;<br>end;<br>
 
[blue]同意xianjun说法。即:<br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br>&nbsp; S: string;<br>begin<br>&nbsp; S := '色';<br>&nbsp; SendMessage(Edit1.Handle, wm_ime_char, (ord(S[1]) shl 8) + ord(S[2]),0);<br>end;<br>看API帮助就知道了:<br>chCharCode1 = (TCHAR) wParam;<br>chCharCode2 = (TCHAR) wParam&gt;&gt;8;<br>chCharCode2是前面的引导字符,即为S[1],chCharCode1为S[2]<br>因为wParam右移8位得到chCharCode2,所以应该所Ord(S[1])左移8位。[/blue]
 
谢谢大家!分数大家都分一点。<br>benlei &nbsp;25<br>xianjun &nbsp;100<br>zhihuali &nbsp;50<br>酷尔贝塔 &nbsp;25
 

Similar threads

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