-
Notifications
You must be signed in to change notification settings - Fork 2
/
autosip.cpp
34 lines (32 loc) · 1018 Bytes
/
autosip.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Silly WinCE SIP automator
// Copyright (c) 2022 datadiode
// SPDX-License-Identifier: MIT
#include <windows.h>
#include <sipapi.h>
template<typename f>
struct DllImport {
FARPROC p;
f operator*() const { return reinterpret_cast<f>(p); }
};
static struct sipapi {
static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) {
static HWND static_focus = NULL;
static DWORD static_flag = SIPF_OFF;
HWND const focus = GetFocus();
DWORD const flag = focus && (
(SendMessage(focus, WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL) >
(GetWindowLong(focus, GWL_STYLE) & ES_READONLY)
) ? SIPF_ON : SIPF_OFF;
if (static_focus != focus || static_flag != flag) {
static_focus = focus;
(*::sipapi.SipShowIM)(static_flag = flag);
}
}
HMODULE h;
DllImport<BOOL(WINAPI*)(DWORD)> SipShowIM;
UINT_PTR timer;
} const sipapi = {
GetModuleHandle(L"COREDLL.DLL"),
GetProcAddress(sipapi.h, L"SipShowIM"),
*sipapi.SipShowIM ? SetTimer(NULL, 0, 500, sipapi::TimerProc) : 0
};