Uisubs.pas
资源名称:Wingb_Mz.rar [点击查看]
上传用户:wen198501
上传日期:2013-04-01
资源大小:335k
文件大小:15k
源码类别:
输入法编程
开发平台:
Delphi
- {******************************************************}
- { }
- { Copyright (c) 1990-1999 Microsoft Corporation }
- { }
- { Module Name: Uisubs.c ->> Uisubs.pas }
- { }
- { Translator: Liu_mazi@126.com, 2005-11-14 }
- { }
- {******************************************************}
- unit Uisubs;
- {$I Define.Inc}
- interface
- uses Windows;
- procedure DrawDragBorder(_hWnd: hWnd; lCursorPos, lCursorOffset: DWord); // 绘制拖拽方框
- procedure DrawFrameBorder(_hDC: hDC; _hWnd: hWnd); // 绘制窗口边框
- function ContextMenuWndProc(hCMenuWnd: hWnd; uMsg: uInt; wParam: WParam; lParam: LParam): LResult; stdcall; // Context菜单窗口回调
- function SoftkeyMenuWndProc(hKeyMenuWnd: hWnd; uMsg: uInt; wParam: WParam; lParam: LParam): LResult; stdcall; // Softkey菜单窗口回调
- procedure ContextMenu(hStatusWnd: hWnd; x, y: Integer); // 弹出Context菜单
- procedure SoftkeyMenu(hStatusWnd: hWnd; x, y: Integer); // 弹出Softkey菜单
- function HtmlHelp(hWndCaller: HWnd; pszFile: PChar; uCommand: UInt; dwData: DWord): HWnd; stdcall;
- implementation
- uses Messages, ImmDev, ImeDefs, Data, Init, DDIS, Notify, Statusui;
- const
- HH_DISPLAY_TOC = $0001;
- HH_DISPLAY_TOPIC = $0000;
- HH_CLOSE_ALL = $0012;
- HH_DISPLAY_INDEX = $0002;
- HH_HELP_CONTEXT = $000F;
- HH_DISPLAY_SEARCH = $0003;
- function HtmlHelp; external 'HHCtrl.ocx' Name 'HtmlHelpA';
- // 绘制拖拽方框
- procedure DrawDragBorder(_hWnd: hWnd; lCursorPos, lCursorOffset: DWord);
- var
- _hDC: hDC;
- cxBorder, cyBorder, x, y: Integer;
- rcWnd: TRect;
- begin
- // 边框宽度
- cxBorder := GetSystemMetrics(SM_CXBORDER);
- cyBorder := GetSystemMetrics(SM_CYBORDER);
- // 当前位置
- x := PSmallPoint(@lCursorPos).x;
- y := PSmallPoint(@lCursorPos).y;
- // 偏移计算
- Dec(x, PSmallPoint(@lCursorOffset).x);
- Dec(y, PSmallPoint(@lCursorOffset).y);
- // 防止越界
- if (x < sImeG.rcWorkArea.Left) then x := sImeG.rcWorkArea.Left;
- if (y < sImeG.rcWorkArea.Top) then y := sImeG.rcWorkArea.Top;
- // 窗口尺寸
- GetWindowRect(_hWnd, rcWnd);
- // 防止越界
- if (x + (rcWnd.Right - rcWnd.Left) > sImeG.rcWorkArea.Right) then
- x := sImeG.rcWorkArea.Right - (rcWnd.Right - rcWnd.Left);
- if (y + (rcWnd.Bottom - rcWnd.Top) > sImeG.rcWorkArea.Bottom) then
- y := sImeG.rcWorkArea.Bottom - (rcWnd.Bottom - rcWnd.Top);
- // 绘制方框
- _hDC := CreateDC('DISPLAY', nil, nil, nil);
- SelectObject(_hDC, GetStockObject(GRAY_BRUSH));
- PatBlt(_hDC, x, y, rcWnd.Right - rcWnd.Left - cxBorder, cyBorder, PATINVERT);
- PatBlt(_hDC, x, y + cyBorder, cxBorder, rcWnd.Bottom - rcWnd.Top - cyBorder, PATINVERT);
- PatBlt(_hDC, x + cxBorder, y + rcWnd.Bottom - rcWnd.Top, rcWnd.Right - rcWnd.Left - cxBorder, - cyBorder, PATINVERT);
- PatBlt(_hDC, x + rcWnd.Right - rcWnd.Left, y, - cxBorder, rcWnd.Bottom - rcWnd.Top - cyBorder, PATINVERT); // **
- DeleteDC(_hDC);
- end;
- // 绘制窗口边框
- procedure DrawFrameBorder(_hDC: hDC; _hWnd: hWnd);
- var
- rcWnd: TRect;
- xWi, yHi: Integer;
- begin
- GetWindowRect(_hWnd, rcWnd);
- xWi := rcWnd.Right - rcWnd.Left; // 宽度
- yHi := rcWnd.Bottom - rcWnd.Top; // 高度
- // 第1层
- PatBlt(_hDC, 0, 0, xWi, 1, WHITENESS);
- PatBlt(_hDC, 0, 0, 1, yHi, WHITENESS);
- PatBlt(_hDC, 0, yHi, xWi, -1, BLACKNESS);
- PatBlt(_hDC, xWi, 0, -1, yHi, BLACKNESS);
- // 第2层
- Dec(xWi, 2);
- Dec(yHi, 2);
- SelectObject(_hDC, GetStockObject(LTGRAY_BRUSH));
- PatBlt(_hDC, 1, 1, xWi, 1, PATCOPY);
- PatBlt(_hDC, 1, 1, 1, yHi, PATCOPY);
- PatBlt(_hDC, xWi + 1, 1, -1, yHi, PATCOPY);
- SelectObject(_hDC, GetStockObject(GRAY_BRUSH));
- PatBlt(_hDC, 1, yHi + 1, xWi, -1, PATCOPY);
- // 第3层
- Dec(xWi, 2);
- Dec(yHi, 2);
- PatBlt(_hDC, 2, 2, xWi, 1, PATCOPY);
- PatBlt(_hDC, 2, 2, 1, yHi, PATCOPY);
- PatBlt(_hDC, xWi + 2, 3, -1, yHi - 1, WHITENESS);
- SelectObject(_hDC, GetStockObject(LTGRAY_BRUSH));
- PatBlt(_hDC, 2, yHi + 2, xWi, -1, PATCOPY);
- // 第4层
- Dec(xWi, 2);
- Dec(yHi, 2);
- SelectObject(_hDC, GetStockObject(GRAY_BRUSH));
- PatBlt(_hDC, 3, 3, xWi, 1, PATCOPY);
- PatBlt(_hDC, 3, 3, 1, yHi, PATCOPY);
- SelectObject(_hDC, GetStockObject(LTGRAY_BRUSH));
- PatBlt(_hDC, xWi + 3, 4, -1, yHi - 1, PATCOPY);
- PatBlt(_hDC, 3, yHi + 3, xWi, -1, WHITENESS);
- end;
- // Context菜单窗口回调
- function ContextMenuWndProc(hCMenuWnd: hWnd; uMsg: uInt; wParam: WParam; lParam: LParam): LResult; stdcall;
- var
- hUIWnd{, hCompWnd}: hWnd;
- _hIMC: hIMC;
- lpIMC: PInputContext;
- lpImcP: PPrivContext;
- ptSTFixPos: TPoint;
- _hMenu: hMenu;
- ui_Mode: Integer;
- szOptGudHlpName: array[0..MAX_PATH] of Char;
- szImeGudHlpName: array[0..MAX_PATH] of Char;
- begin
- Result := 0;
- case (uMsg) of
- WM_DESTROY:
- begin
- hUIWnd := GetWindowLong(hCMenuWnd, CMENU_HUIWND);
- if IsWindow(hUIWnd) then SendMessage(hUIWnd, WM_IME_NOTIFY, IMN_PRIVATE, IMN_PRIVATE_CMENUDESTROYED);
- end;
- WM_USER_DESTROY:
- begin
- SendMessage(hCMenuWnd, WM_CLOSE, 0, 0); // **, Send此消息, 下面就没有必要调用DestroyWindow()了..
- DestroyWindow(hCMenuWnd);
- end;
- WM_COMMAND:
- begin
- case LoWord(wParam) of
- IDM_PROP: // 设置...
- begin
- hUIWnd := GetWindowLong(hCMenuWnd, CMENU_HUIWND);
- if (IsWindow(hUIWnd) = False) then Exit;
- _hIMC := GetWindowLong(hUIWnd, IMMGWLP_IMC);
- if (_hIMC = 0) then Exit;
- lpIMC := ImmLockIMC(_hIMC);
- if (lpIMC = nil) then Exit;
- lpImcP := ImmLockIMCC(lpIMC.hPrivate);
- if (lpImcP = nil) then Exit; // **
- ImeConfigure(GetKeyboardLayout(0), lpIMC.hWnd, IME_CONFIG_GENERAL, nil);
- lpImcP.iImeState := CST_INIT;
- CompCancel(_hIMC, lpIMC);
- // init fields of hIMC
- lpIMC.fOpen := True;
- if ((lpIMC.fdwInit and INIT_CONVERSION) = 0) then
- begin
- lpIMC.fdwConversion := IME_CMODE_NATIVE;
- lpIMC.fdwInit := lpIMC.fdwInit or INIT_CONVERSION;
- end;
- lpImcP.fdwImeMsg := lpImcP.fdwImeMsg or MSG_IMN_DESTROYCAND;
- GenerateMessage(_hIMC, lpIMC, lpImcP);
- // set cand window data
- if (sImeG.IC_Trace <> 0) then
- ui_Mode := BOX_UI // **
- else begin
- ui_Mode := LIN_UI;
- ptSTFixPos.x := 0;
- ptSTFixPos.y := sImeG.rcWorkArea.Bottom - sImeG.yStatusHi;
- ImmSetStatusWindowPos(_hIMC, @ptSTFixPos);
- end;
- InitCandUIData(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER), ui_Mode);
- ImmUnlockIMCC(lpIMC.hPrivate);
- ImmUnlockIMC(_hIMC);
- end;
- IDM_OPTGUD: // 操作指南...
- begin
- szOptGudHlpName[0] := #0;
- GetWindowsDirectory(szOptGudHlpName, MAX_PATH);
- lStrCat(szOptGudHlpName, 'HELPWINIME.CHM');
- HtmlHelp(hCMenuWnd, szOptGudHlpName, HH_DISPLAY_TOPIC, 0);
- end;
- IDM_IMEGUD: // 输入法入门...
- begin
- szImeGudHlpName[0] := #0;
- GetWindowsDirectory(szImeGudHlpName, MAX_PATH);
- lStrCat(szImeGudHlpName, 'HELPWINGB.CHM');
- HtmlHelp(hCMenuWnd, szImeGudHlpName, HH_DISPLAY_TOPIC, 0);
- end;
- IDM_VER: // 版本信息...
- begin
- hUIWnd := GetWindowLong(hCMenuWnd, CMENU_HUIWND);
- if (IsWindow(hUIWnd) = False) then Exit;
- _hIMC := GetWindowLong(hUIWnd, IMMGWLP_IMC);
- if (_hIMC = 0) then Exit;
- lpIMC := ImmLockIMC(_hIMC);
- if (lpIMC = nil) then Exit;
- DialogBox(HInstance, 'IMEVER', lpIMC.hWnd, @ImeVerDlgProc);
- ImmUnlockIMC(_hIMC);
- end;
- end;
- end;
- WM_CLOSE:
- begin
- GetMenu(hCMenuWnd); // ??
- _hMenu := GetWindowLong(hCMenuWnd, CMENU_MENU);
- if (_hMenu <> 0) then
- begin
- SetWindowLong(hCMenuWnd, CMENU_MENU, 0);
- DestroyMenu(_hMenu);
- end;
- Result := DefWindowProc(hCMenuWnd, uMsg, wParam, lParam); // **, DefWindowProc()将调用DestroyWindow()
- end;
- else
- Result := DefWindowProc(hCMenuWnd, uMsg, wParam, lParam);
- end;
- end;
- // Softkey菜单窗口回调
- function SoftkeyMenuWndProc(hKeyMenuWnd: hWnd; uMsg: uInt; wParam: WParam; lParam: LParam): LResult; stdcall;
- var
- hUIWnd: hWnd;
- _hMenu: hMenu;
- _hIMC: hIMC;
- lpIMC: PInputContext;
- lpImcP: PPrivContext;
- fdwConversion: DWord;
- J: uInt;
- begin
- Result := 0;
- case (uMsg) of
- WM_DESTROY:
- begin
- hUIWnd := GetWindowLong(hKeyMenuWnd, SOFTKEYMENU_HUIWND);
- if IsWindow(hUIWnd) then SendMessage(hUIWnd, WM_IME_NOTIFY, IMN_PRIVATE, IMN_PRIVATE_SOFTKEYMENUDESTROYED);
- end;
- WM_USER_DESTROY:
- begin
- SendMessage(hKeyMenuWnd, WM_CLOSE, 0, 0);
- DestroyWindow(hKeyMenuWnd); // **
- end;
- WM_COMMAND:
- begin
- case LoWord(wParam) of
- IDM_SKL1, IDM_SKL2, IDM_SKL3, IDM_SKL4, IDM_SKL5, IDM_SKL6, IDM_SKL7,
- IDM_SKL8, IDM_SKL9, IDM_SKL10, IDM_SKL11, IDM_SKL12, IDM_SKL13: // 键盘类型
- begin
- hUIWnd := GetWindowLong(hKeyMenuWnd, SOFTKEYMENU_HUIWND);
- if (IsWindow(hUIWnd) = False) then Exit;
- _hIMC := GetWindowLong(hUIWnd, IMMGWLP_IMC);
- if (_hIMC = 0) then Exit;
- lpIMC := ImmLockIMC(_hIMC);
- if (lpIMC = nil) then Exit;
- lpImcP := ImmLockIMCC(lpIMC.hPrivate);
- if (lpImcP = nil) then Exit; // **
- sImeL.dwSKWant := LoWord(wParam) - IDM_SKL1;
- sImeL.dwSKState[sImeL.dwSKWant] := 1;
- // clear other SK State
- for J := 0 to NumsSK - 1 do if (J <> sImeL.dwSKWant) then sImeL.dwSKState[J] := 0;
- if (sImeL.dwSKState[sImeL.dwSKWant] <> 0) then
- begin
- if (LoWord(wParam) = IDM_SKL1) then lpImcP.iImeState := CST_INIT else lpImcP.iImeState := CST_SOFTKB;
- fdwConversion := lpIMC.fdwConversion or IME_CMODE_SOFTKBD;
- end else
- begin
- lpImcP.iImeState := CST_INIT;
- fdwConversion := lpIMC.fdwConversion and (not IME_CMODE_SOFTKBD);
- end;
- ImmSetConversionStatus(_hIMC, fdwConversion and (not IME_CMODE_SOFTKBD), lpIMC.fdwSentence);
- ImmSetConversionStatus(_hIMC, fdwConversion, lpIMC.fdwSentence);
- ImmUnlockIMCC(lpIMC.hPrivate);
- ImmUnlockIMC(_hIMC);
- end;
- end;
- end;
- WM_CLOSE:
- begin
- GetMenu(hKeyMenuWnd); // ??
- _hMenu := GetWindowLong(hKeyMenuWnd, SOFTKEYMENU_MENU);
- if (_hMenu <> 0) then
- begin
- SetWindowLong(hKeyMenuWnd, SOFTKEYMENU_MENU, 0);
- DestroyMenu(_hMenu);
- end;
- Result := DefWindowProc(hKeyMenuWnd, uMsg, wParam, lParam); // **
- end;
- WM_SETCURSOR:
- begin
- if (HiWord(lParam) = WM_RBUTTONUP) then MessageBeep($FFFFFFFF);
- Result := DefWindowProc(hKeyMenuWnd, uMsg, wParam, lParam);
- end;
- else
- Result := DefWindowProc(hKeyMenuWnd, uMsg, wParam, lParam);
- end;
- end;
- // 弹出Context菜单
- procedure ContextMenu(hStatusWnd: hWnd; x, y: Integer);
- label
- ContextMenuUnlockIMC;
- var
- hUIWnd, hCMenuWnd: hWnd;
- hUIPrivate: hGlobal;
- lpUIPrivate: PUIPriv;
- _hIMC: hIMC;
- lpIMC: PInputContext;
- _hMenu, hCMenu: hMenu;
- rcStatusWnd: TRect;
- begin
- hUIWnd := GetWindow(hStatusWnd, GW_OWNER);
- if (IsWindow(hUIWnd) = False) then Exit;
- GetWindowRect(hStatusWnd, rcStatusWnd);
- _hIMC := GetWindowLong(hUIWnd, IMMGWLP_IMC);
- if (_hIMC = 0) then Exit;
- lpIMC := ImmLockIMC(_hIMC);
- if (lpIMC = nil) then Exit;
- hUIPrivate := GetWindowLong(hUIWnd, IMMGWLP_PRIVATE);
- if (hUIPrivate = 0) then goto ContextMenuUnlockIMC;
- lpUIPrivate := GlobalLock(hUIPrivate);
- if (lpUIPrivate = nil) then goto ContextMenuUnlockIMC;
- if (IsWindow(lpUIPrivate.hCMenuWnd) = False) then
- begin
- lpUIPrivate.hCMenuWnd := CreateWindowEx(CS_HREDRAW or CS_VREDRAW, szCMenuClassName,
- 'Context Menu', WS_POPUP or WS_DISABLED, 0, 0, 0, 0, lpIMC.hWnd, 0, HInstance, nil);
- end;
- hCMenuWnd := lpUIPrivate.hCMenuWnd;
- GlobalUnlock(hUIPrivate);
- if (IsWindow(hCMenuWnd) = False) then goto ContextMenuUnlockIMC;
- _hMenu := LoadMenu(HInstance, 'PROPMENU');
- hCMenu := GetSubMenu(_hMenu, 0);
- SetWindowLong(hCMenuWnd, CMENU_HUIWND, hUIWnd);
- SetWindowLong(hCMenuWnd, CMENU_MENU, _hMenu);
- TrackPopupMenu(hCMenu, TPM_LEFTBUTTON, rcStatusWnd.Left, rcStatusWnd.Top, 0, hCMenuWnd, nil);
- _hMenu := GetWindowLong(hCMenuWnd, CMENU_MENU);
- if (_hMenu <> 0) then
- begin
- SetWindowLong(hCMenuWnd, CMENU_MENU, 0);
- DestroyMenu(_hMenu);
- end;
- ContextMenuUnlockIMC:
- ImmUnlockIMC(_hIMC);
- end;
- // 弹出Softkey菜单
- procedure SoftkeyMenu(hStatusWnd: hWnd; x, y: Integer);
- label
- KeyMenuUnlockIMC;
- var
- hUIWnd, hSoftkeyMenuWnd: hWnd;
- hUIPrivate: hGlobal;
- lpUIPrivate: PUIPriv;
- _hIMC: hIMC;
- lpIMC: PInputContext;
- _hMenu, hKeyMenu: hMenu;
- rcStatusWnd: TRect;
- begin
- hUIWnd := GetWindow(hStatusWnd, GW_OWNER);
- if (IsWindow(hUIWnd) = False) then Exit;
- GetWindowRect(hStatusWnd, rcStatusWnd);
- _hIMC := GetWindowLong(hUIWnd, IMMGWLP_IMC);
- if (_hIMC = 0) then Exit;
- lpIMC := ImmLockIMC(_hIMC);
- if (lpIMC = nil) then Exit;
- hUIPrivate := GetWindowLong(hUIWnd, IMMGWLP_PRIVATE);
- if (hUIPrivate = 0) then goto KeyMenuUnlockIMC;
- lpUIPrivate := GlobalLock(hUIPrivate);
- if (lpUIPrivate = nil) then goto KeyMenuUnlockIMC;
- if (IsWindow(lpUIPrivate.hSoftkeyMenuWnd) = False) then
- begin
- lpUIPrivate.hSoftkeyMenuWnd := CreateWindowEx(CS_HREDRAW or CS_VREDRAW, szSoftkeyMenuClassName,
- 'Softkey Menu', WS_POPUP or WS_DISABLED, 0, 0, 0, 0, lpIMC.hWnd, 0, HInstance, nil);
- end;
- hSoftkeyMenuWnd := lpUIPrivate.hSoftkeyMenuWnd;
- GlobalUnlock(hUIPrivate);
- if (IsWindow(hSoftkeyMenuWnd) = False) then goto KeyMenuUnlockIMC;
- _hMenu := LoadMenu(HInstance, 'SKMENU');
- hKeyMenu := GetSubMenu(_hMenu, 0);
- SetWindowLong(hSoftkeyMenuWnd, SOFTKEYMENU_HUIWND, hUIWnd);
- SetWindowLong(hSoftkeyMenuWnd, SOFTKEYMENU_MENU, _hMenu);
- if (sImeL.dwSKState[sImeL.dwSKWant] <> 0) then CheckMenuItem(_hMenu, sImeL.dwSKWant + IDM_SKL1, MF_CHECKED);
- TrackPopupMenu(hKeyMenu, TPM_LEFTBUTTON, rcStatusWnd.Left, rcStatusWnd.Top, 0, hSoftkeyMenuWnd, nil);
- _hMenu := GetWindowLong(hSoftkeyMenuWnd, SOFTKEYMENU_MENU);
- if (_hMenu <> 0) then
- begin
- SetWindowLong(hSoftkeyMenuWnd, SOFTKEYMENU_MENU, 0);
- DestroyMenu(_hMenu);
- end;
- KeyMenuUnlockIMC:
- ImmUnlockIMC(_hIMC);
- end;
- end.