http://bbs.csdn.net/topics/390472740
Delphi/pascal Code?
123456789101112131415161718192021222324252627282930313233343536373839 |
function
TCFADODBStorage
.
OpenConnection:
Boolean
;
//线程里打开ADOConnection,在XP下切换输入法程序会死掉
//原因:ADO自动创建一个ADODB.AsyncEventMessenger窗口,然后会有一个对应的IME窗口,但线程里没有消息循环
// XP下输入法切换时会SendMessage给IME窗口并等待返回,IME窗口并不会处理消息,造成死锁
//这个函数把线程里的IME窗口释放掉,切换输入法时就不会有消息过来了
procedure
_FreeIMEWindow;
const
IME_WINDOW_CLASS =
‘IME‘
;
IME_WINDOW_TEXT =
‘Default IME‘
;
var
h : HWND;
pid : DWORD;
dh : HWND;
begin
h := FindWindow(IME_WINDOW_CLASS, IME_WINDOW_TEXT);
while
IsWindow(h)
do
begin
if
GetWindowThreadProcessId(h, pid) = GetCurrentThreadId
then
dh := h
else
dh :=
0
;
h := FindWindowEx(
0
, h, IME_WINDOW_CLASS, IME_WINDOW_TEXT);
if
dh <>
0
then
DestroyWindow(dh);
end
;
end
;
begin
try
FConnection
.
ConnectionString := ConnectionString;
FConnection
.
Connected :=
True
;
if
GetCurrentThreadId <> Global
.
MainThreadID
{全局的主线程ID,如果是主线程,不需要Free}
then
_FreeIMEWindow;
except
on
E: Exception
do
FLastErrorMessage := e
.
Message;
end
;
Result := FConnection
.
Connected;
end
;
|
|
Useful to me [0] throw a brick [0] reference | Report | Management |
-
concern
-
Ysai
- Ysai
-
This edition level:
|
#5 Score: 0 replies.: 2013-05-28 17:01:47 This problem I have been looking for a long time reason, landlord earned |
Delphi Multi-threaded switching method after the program suspended animation