标签:
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;
最近遇到程序开启线程后,在主界面编辑框中切换输入法,程序就卡住,只有强制关闭
标签:
原文地址:http://www.cnblogs.com/moonwind/p/4492067.html