zoukankan      html  css  js  c++  java
  • 最近遇到程序开启线程后,在主界面编辑框中切换输入法,程序就卡住,只有强制关闭

    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;
  • 相关阅读:
    matlab colormap
    张量的基本概念
    河南省测绘资质单位大全
    Meanshift算法
    图形图像的绘制 GandyDraw
    leetcode
    Java 实现装饰(Decorator)模式
    Python
    Asp.Net+Easyui实现重大CRUD
    Scriptcase演示程序,现在,他们使用SC多么简单的开发系统
  • 原文地址:https://www.cnblogs.com/moonwind/p/4492067.html
Copyright © 2011-2022 走看看