📄 compui.cpp
字号:
LPUIPRIV lpUIPriv;
lpUIPriv = (LPUIPRIV)GetWindowLong(hCompWnd, IMMGWL_PRIVATE);
if (!lpUIPriv) {
return 0L;
}
lpUIPriv->hCompWnd = (HWND)NULL;
return 0;
}
/**********************************************************************/
/* OnCompPaint() */
/**********************************************************************/
static __inline
LRESULT OnCompPaint(HWND hCompWnd)
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hCompWnd, &ps);
PaintCompWindow(GetWindow(hCompWnd, GW_OWNER), hDC);
EndPaint(hCompWnd, &ps);
return 0L;
}
/**********************************************************************/
/* OnSettingChange() */
/**********************************************************************/
static __inline
LRESULT OnSettingChange(HWND hCompWnd, WPARAM wFlag)
{
LPUIPRIV lpUIPriv;
RECT rcPrev;
lpUIPriv = (LPUIPRIV)GetWindowLong(hCompWnd, IMMGWL_PRIVATE);
rcPrev = g_sImeUIG.rcWorkArea;
switch(wFlag) {
case SPI_SETCURRENTIM:
GetWorkArea(&g_sImeUIG.rcWorkArea);
break;
case SPI_SETSIPINFO:
GetWorkArea(&g_sImeUIG.rcWorkArea);
break;
default:
return 1L;
}
if (rcPrev.left == g_sImeUIG.rcWorkArea.left &&
rcPrev.top == g_sImeUIG.rcWorkArea.top &&
rcPrev.right == g_sImeUIG.rcWorkArea.right &&
rcPrev.bottom == g_sImeUIG.rcWorkArea.bottom) {
return 0L;
}
if (lpUIPriv->fdwUIFlags & UI_CAND_ALREADY_OPEN) {
POINT ptNew;
ptNew.x = lpUIPriv->ptComp.x;
ptNew.y = lpUIPriv->ptComp.y + lpUIPriv->nCompHi - g_sImeUIG.cyBorder;
AdjustCandWnd(lpUIPriv->hCandWnd, ptNew);
}
return 0L;
}
/**********************************************************************/
/* CompWndProc() */
/**********************************************************************/
LRESULT CALLBACK CompWndProc(HWND hCompWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_CREATE:
return OnCompCreate(hCompWnd, (LPCREATESTRUCT)lParam);
case WM_DESTROY:
return OnCompDestroy(hCompWnd);
case WM_IME_NOTIFY:
if (wParam == IMN_SETCOMPOSITIONWINDOW) {
SetCompPosition(hCompWnd);
}
break;
case WM_PAINT:
return OnCompPaint(hCompWnd);
case WM_SETTINGCHANGE:
return OnSettingChange(hCompWnd, wParam);
break;
default:
return DefWindowProc(hCompWnd, uMsg, wParam, lParam);
}
return 0L;
}
//=====================================================================//
// Exported API //
//=====================================================================//
/**********************************************************************/
/* ShowComp() : Show the composition window */
/**********************************************************************/
void ShowComp(HWND hUIWnd, int nShowCompCmd)
{
LPUIPRIV lpUIPriv;
BOOL bCompShowed;
// show or hid the UI window
lpUIPriv = (LPUIPRIV)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
if (!lpUIPriv) {
return;
}
if (!(lpUIPriv->fdwUIFlags & UI_COMP_ALREADY_START)) {
return;
}
if (!lpUIPriv->hCompWnd) {
return;
}
bCompShowed = IsWindowVisible(lpUIPriv->hCompWnd);
if (bCompShowed && nShowCompCmd == SW_SHOWNOACTIVATE) {
return;
} else if (!bCompShowed && nShowCompCmd == SW_HIDE) {
return;
} else {
}
if (nShowCompCmd == SW_HIDE) {
lpUIPriv->fdwSetContext &= ~ISC_SHOWUICOMPOSITIONWINDOW;
}
ShowWindow(lpUIPriv->hCompWnd, nShowCompCmd);
return;
}
/**********************************************************************/
/* StartComp() */
/**********************************************************************/
void StartComp(HWND hUIWnd)
{
LPUIPRIV lpUIPriv;
HIMC hIMC;
#ifndef WPC
LPINPUTCONTEXT lpIMC;
LPCOMPOSITIONSTRING lpCompStr;
#endif // WPC
DWORD dwCompStrLen;
lpUIPriv = (LPUIPRIV)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
if (!lpUIPriv) { // Oh! Oh!
return;
}
hIMC = (HIMC)GetWindowLong(hUIWnd, IMMGWL_IMC);
if (!hIMC) {
return;
}
#ifndef WPC
lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
if (!lpIMC) {
return;
}
lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
if (!lpCompStr) {
ImmUnlockIMC(hIMC);
return;
}
dwCompStrLen = lpCompStr->dwCompStrLen;
ImmUnlockIMCC(lpIMC->hCompStr);
ImmUnlockIMC(hIMC);
#else
UINT uData;
uData = IME_ESC_GET_COMPSTR_LEN;
if (ImmEscape(NULL, hIMC, IME_ESC_QUERY_SUPPORT, (LPVOID)&uData)) {
dwCompStrLen = ImmEscape(NULL, hIMC, IME_ESC_GET_COMPSTR_LEN, NULL);
} else {
dwCompStrLen = 0;
}
#endif // WPC
if (0 == dwCompStrLen) { return; }
if (!lpUIPriv->hCompWnd) {
lpUIPriv->hCompWnd = CreateWindowEx(
WS_EX_NOACTIVATE|WS_EX_TOPMOST,
v_szCompClassName, NULL,
WS_POPUP|WS_BORDER,
0, 0, 10, 10,
hUIWnd, (HMENU)NULL, lpUIPriv->hInst, NULL);
}
if (lpUIPriv->hCompWnd) {
SetWindowPos(lpUIPriv->hCompWnd, HWND_TOPMOST, 0, 0,
lpUIPriv->nCompWi, lpUIPriv->nCompHi,
SWP_NOACTIVATE|SWP_NOMOVE);//|SWP_NOZORDER);
}
lpUIPriv->fdwUIFlags |= UI_COMP_ALREADY_START;
SetCompPosition(lpUIPriv->hCompWnd);
ShowComp(hUIWnd, SW_SHOWNOACTIVATE);
return;
}
/**********************************************************************/
/* OnComp() */
/**********************************************************************/
void OnComp(HWND hUIWnd, DWORD fdwFlags)
{
LPUIPRIV lpUIPriv;
if (!(fdwFlags & (GCS_COMPSTR|GCS_COMPREADSTR|GCS_CURSORPOS))) {
return;
}
lpUIPriv = (LPUIPRIV)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
if (!lpUIPriv) {
return;
}
if (!(lpUIPriv->fdwUIFlags & UI_COMP_ALREADY_START)) {
return;
}
if (lpUIPriv->hCompWnd) {
HDC hDC;
hDC = GetDC(lpUIPriv->hCompWnd);
PaintCompWindow(hUIWnd, hDC);
ReleaseDC(lpUIPriv->hCompWnd, hDC);
}
return;
}
/**********************************************************************/
/* EndComp() */
/**********************************************************************/
void EndComp(HWND hUIWnd)
{
LPUIPRIV lpUIPriv;
lpUIPriv = (LPUIPRIV)GetWindowLong(hUIWnd, IMMGWL_PRIVATE);
if (!lpUIPriv) {
return;
}
if (!(lpUIPriv->fdwUIFlags & UI_COMP_ALREADY_START)) {
return;
}
lpUIPriv->fdwUIFlags &= ~(UI_COMP_ALREADY_START);
if (lpUIPriv->hCompWnd && IsWindowVisible(lpUIPriv->hCompWnd)) {
ShowWindow(lpUIPriv->hCompWnd, SW_HIDE);
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -