как то давно нашел утилиту по замене курсора при вводе вроде как полезная штука местами.
решил пару утилит аналогичных сделать, естественно на delphi.
#define OEMRESOURCE
#include <windows.h>
HINSTANCE g_instance;
HHOOK g_hook;
HCURSOR g_hc_ibeam;
UINT_PTR g_timer = NULL;
DWORD g_active = 0;
DWORD g_layout = 0;
void CALLBACK UpdateTimer(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
if (g_active < GetTickCount())
{
KillTimer(0, g_timer);
g_timer = NULL;
g_active = 0;
g_layout = 0;
SetSystemCursor(CopyCursor(g_hc_ibeam), OCR_IBEAM);
}
else
{
int layout = (int) GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL)) & 0xFFFF;
if (g_layout != layout)
{
g_layout = layout;
HCURSOR hc_new = LoadCursor(g_instance, MAKEINTRESOURCE(layout));
if (hc_new)
{
SetSystemCursor(hc_new, OCR_IBEAM);
}
else
{
SetSystemCursor(CopyCursor(g_hc_ibeam), OCR_IBEAM);
}
}
}
}
LRESULT CALLBACK LowLevelKeyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT *ks = (KBDLLHOOKSTRUCT*)lParam;
if (ks->vkCode==VK_LSHIFT)
{
if (wParam == WM_KEYDOWN)
{
g_active = GetTickCount() + 10000;
UpdateTimer(NULL, NULL, NULL, NULL);
g_timer = SetTimer(NULL, g_timer, 100, UpdateTimer);
}
else if (wParam == WM_KEYUP && g_active)
{
g_active = GetTickCount() + 1000;
}
}
}
return CallNextHookEx(g_hook, nCode, wParam, lParam);
}
int Main()
{
HANDLE mutex = CreateMutex(NULL, FALSE, "LangCursor");
if (GetLastError() == ERROR_ALREADY_EXISTS || GetLastError() == ERROR_ACCESS_DENIED) return 1;
g_hc_ibeam = CopyCursor(LoadCursor(NULL, IDC_IBEAM));
if (!g_hc_ibeam) return 1;
g_instance = GetModuleHandle(NULL);
g_hook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardHook, g_instance, 0);
if (!g_hook) return 1;
MSG msg;
while (GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(g_hook);
DestroyCursor(g_hc_ibeam);
return 0;
}
EXTERN_C void WINAPI WinMainCRTStartup()
{
ExitProcess(Main());
- Зачем автору в исходнике mutex?
- приложение не оконное зачем тут GetMessage.... в цикле?