應用程序未通過文本服務框架 DLL 檢測輸入語言更改 (Application not detecting input language changes via Text Service Framework DLL)


問題描述

應用程序未通過文本服務框架 DLL 檢測輸入語言更改 (Application not detecting input language changes via Text Service Framework DLL)

OK, I have been at this for a while ...

I am trying to track when user changes input languages from Language Bar.

I have a Text Service DLL ‑ modeled from MSDN and WinSDK samples ‑ that registers fine, and I can use the interfaces ITfActiveLanguageProfileNotifySink & ITfLanguageProfileNotifySink and see those events just fine.

I also have finally realized that when I change languages these events occur for the application/process that currently has focus. 

What I need to do is to simply have these events able to callback to my own application, when it has the focus.  I know I am missing something.

Any help here is appreciated.

Thanks.


參考解法

方法 1:

I did some double‑checking, and you should be able to create a thread manager object without implementing ITextStoreACP so long as you don't call ITfThreadMgr::Activate.

So, the code should look like:

HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
    ITfThreadMgr* pThreadMgr(NULL);
    hr = CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (LPVOID*) &pThreadMgr);
    if (SUCCEEDED(hr))
    {
        ITfSource *pSource;
        hr = pThreadMgr‑>QueryInterface(IID_ITfSource, (LPVOID*)&pSource);
        if(SUCCEEDED(hr))
        {
            hr = pSource‑>AdviseSink(IID_ITfActiveLanguageProfileNotifySink, 
                (ITfActiveLanguageProfileNotifySink*)this,
                &m_dwCookie);

            pSource‑>Release();
        }
    }
}

Alternatively, you can use ITfLanguageProfileNotifySink ‑ this interface is driven from the ItfInputProcessorProfiles object instead of ItfThreadMgr.  There's a sample of how to set it up on the MSDN page for ItfLanguageProfileNotifySink.

For both objects, you need to keep the source object (ITfThreadMgr or ITfInputProcessorProfiles) as well as the sink object (what you implement) alive until your application exits.

Before your application exits, you need to remove the sink from the source object using ITfSource::UnadviseSink, and then release the source object (using Release).  (You don't need to keep the ItfSource interface alive for the life of your application, though.)

(by user2621234Eric Brown)

參考文件

  1. Application not detecting input language changes via Text Service Framework DLL (CC BY‑SA 3.0/4.0)

#Callback #input-language #text-services-framework






相關問題

將 C++ 函數指針設置為 C# 委託 (set C++ function pointer as C# delegate)

YouTube(注入)視頻結束回調 (YouTube (injected) video ends callback)

我如何在 Rails 中“驗證”銷毀 (How do I 'validate' on destroy in rails)

Як я магу рэалізаваць зваротныя выклікі на іншы сервер у C# (How can I implement callbacks to another server in c#)

顯示等待通知,直到回調從線程返回 (Show waiting notification till callback returns from thread)

應用程序未通過文本服務框架 DLL 檢測輸入語言更改 (Application not detecting input language changes via Text Service Framework DLL)

回調參數名稱 (Callback parameters name)

我是否以正確的方式考慮回調? (Am I thinking about Callbacks the right way?)

MSMQ 異步異常行為 - .NET 4.0 與 .NET 2.0 (MSMQ asynchronous exception behavior - .NET 4.0 vs .NET 2.0)

參數連接問題。我該如何處理 (parameter connection problem. How can I deal with this)

如何在 JavaScript 中實現動態回調參數 (How can I achieve dynamic callback arguments in JavaScript)

回調警告:回調錯誤創建破折號數據表 (Callback warning: Callback error creating dash' DataTable)







留言討論