I think that then source code of VC++ about IME is useful for u to resolution this problame, So please study the source code of the IME.
If you have not, please go:
http://www.csdn.net/expert/topic/503/503993.shtm
Here is a simple example that works for every control I have tried to use it on.
1. Start a new project
2. Add a command button to the form
3. Paste this code into the form
4. Run it
5. move mouse over and off the command button
option Explicitprivate
Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Longprivate Declare Function ReleaseCapture Lib "user32" () as Long
'Code:
'Put this code in MouseMove event. In this example, I put a
'CommandButton on a
'form with the name Command1
private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _as Single, Y as Single)
static CtrMov as Boolean
static Counter as Long
Counter = Counter + 1
With Command1
'Change this
'Command1
' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
ReleaseCapture
CtrMov = false
Command1.BackColor = &HFF&
Command1.Caption = " Not Over " & Counter
Command1.Refresh
'Put here your code to LostMouseFocus
'for example:
me.print "LostMouseFocus"
else
SetCapture .hwnd
If CtrMov = false then
' do this only once per "over"
CtrMov = true
Command1.BackColor = &HFFFFFF
Command1.Caption = " Over " & Counter
Command1.Refresh
'Put here your code to GetMouseFocus
'for example:
me.print "GetMouseFocus"
End If
End If
End With
End Sub
'form
option Explicit
private Sub Form_Load()
hHook = SetWindowsHookEx(WH_KEYBOARD, _
AddressOf KeyboardProc, _
0&, _
App.ThreadID)
End Sub
private Sub Form_Unload(Cancel as Integer)
Call UnhookWindowsHookEx(hHook)
End Sub
'module
option Explicit
public Declare Function CallNextHookEx Lib "user32" _
(byval hHook as Long, _
byval nCode as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
public Declare Function UnhookWindowsHookEx Lib "user32" _
(byval hHook as Long) as Long
public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(byval idHook as Long, _
byval lpfn as Long, _
byval hmod as Long, _
byval dwThreadId as Long) as Long
public Const WH_KEYBOARD = 2
public hHook as Long
public Function KeyboardProc(byval nCode as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
Dim Temp as string
If nCode >= 0 then
Temp = Chr(wParam)
End If
KeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
先来个函数:
private function coninput(para_key as integer,para_constr as string)
dim sconstr as string
sconstr=ucase(para_constr)+chr(13)+chr(8)+chr(27)
if instr(1,sconstr,ucase(chr(para_key)),vbtextcompare)=0 then
coninput=0
else
coninput=para_key
end if
end function
在控件的keypress事件中加入:
private sub text1_keypress(...)
keyascii=coninput(keyascii,"123...")
end sub
“123...”为要想被允许输入的字(仅限E文)
不知是否符合要求
先来个函数:
private function coninput(para_key as integer,para_constr as string)
dim sconstr as string
sconstr=ucase(para_constr)+chr(13)+chr(8)+chr(27)
if instr(1,sconstr,ucase(chr(para_key)),vbtextcompare)=0 then
coninput=0
else
coninput=para_key
end if
end function
在控件的keypress事件中加入:
private sub text1_keypress(...)
keyascii=coninput(keyascii,"123...")
end sub
“123...”为要想被允许输入的字(仅限E文)
不知是否符合要求