Local-MT-Extension/ExampleExtension/Extension.cpp

50 lines
3.1 KiB
C++
Raw Normal View History

2018-09-02 01:21:35 +08:00
<EFBFBD><EFBFBD>#include "Extension.h"
2018-09-22 03:28:22 +08:00
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxW(NULL, L"Extension Loaded", L"", MB_OK);
break;
case DLL_PROCESS_DETACH:
MessageBoxW(NULL, L"Extension Removed", L"", MB_OK);
break;
}
return TRUE;
}
2018-09-02 01:21:35 +08:00
//#define COPY_CLIPBOARD
//#define EXTRA_NEWLINES
2018-09-02 00:41:53 +08:00
/**
2018-09-02 01:21:35 +08:00
* Param sentence: sentence received by NextHooker (UTF-16).
2018-09-23 05:33:40 +08:00
* Param sentenceInfo: contains miscellaneous info about the sentence. See README.md
2018-09-02 00:41:53 +08:00
* Return value: whether the sentence was modified.
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
*/
2018-09-23 05:33:40 +08:00
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
2018-09-02 01:21:35 +08:00
{
#ifdef COPY_CLIPBOARD
// This example extension automatically copies sentences from the hook currently selected by the user into the clipboard.
2018-09-23 05:33:40 +08:00
if (sentenceInfo["current select"] == 1)
2018-09-02 01:21:35 +08:00
{
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (sentence.size() + 2) * sizeof(wchar_t));
2018-09-09 09:19:00 +08:00
memcpy(GlobalLock(hMem), sentence.c_str(), (sentence.size() + 2) * sizeof(wchar_t));
2018-09-02 01:21:35 +08:00
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
}
return false;
#endif // COPY_CLIPBOARD
2018-09-02 00:41:53 +08:00
#ifdef EXTRA_NEWLINES
2018-09-02 01:21:35 +08:00
// This example extension adds extra newlines to all sentences.
sentence += L"\r\n";
2018-09-02 00:41:53 +08:00
return true;
2018-09-02 01:21:35 +08:00
#endif // EXTRA_NEWLINES
}
2018-07-12 08:07:22 +08:00