functionTCFADODBStorage.OpenConnection:Boolean; //thread open adoconnection, in XP switch IME program will die //cause: ADO automatically creates a Adodb.asynceventmessenger window, and then there is a corresponding IME window, but there is no message loop in the thread //XP When the IME switch is sendmessage to the IME window and waits to be returned, the IME window does not process messages, causing deadlocks //This function frees the IME window of the line thread, and when switching the IME, there is no message coming. procedure_freeimewindow; ConstIme_window_class='IME'; Ime_window_text='Default IME'; varH:hwnd; Pid:dword; Dh:hwnd; beginh:=FindWindow (Ime_window_class, Ime_window_text); whileIsWindow (h) Do begin ifGetWindowThreadProcessId (h, pid) = GetCurrentThreadID ThenDH:=hElseDH:=0; H:= FindWindowEx (0, H, Ime_window_class, Ime_window_text); ifDH <>0 ThenDestroyWindow (DH); End; End;begin Tryfconnection.connectionstring:=ConnectionString; Fconnection.connected:=True; ifGetCurrentThreadID <> Global.mainthreadid{the global main thread ID, if it is the main thread, does not require free} Then_freeimewindow; exceptOn E:exception DoFlasterrormessage:=E.message; End; Result:=fconnection.connected;End;
Recently encountered the program to open the thread, in the main interface edit box switch Input method, the program is stuck, only forced to close