需要确定Windows 10上TabTip.exe(虚拟键盘)的大小(宽度,高度)和位置(左侧,顶部)?
任务是移动所有组件所在的面板,以便输入焦点的输入字段位于虚拟键盘上方。
使用Windows 10不在管理员下,但已编译的项目以管理员身份运行!
以下解决方案适用于Windows 7,Windows 8,在Windows 10中不起作用:
uses ..., Winapi.Windows, Winapi.Dwmapi
...
procedure TForm1.SizeKeyboard;
var KeyBoardRect: TRect;
KeyboardWindow : HWND;
begin
KeyboardWindow := FindWindow('IPTip_Main_Window', nil);
if (KeyboardWindow <> 0) then
KeyBoardRect := GetRect1(KeyboardWindow);
...
end;
...
function TForm1.GetRect1(AKeyboardWindow : HWND): Trect;
var KeyBoardRect: Trect;
begin
GetWindowRect(AKeyboardWindow, KeyBoardRect);
Result := KeyBoardRect;
end;
function TForm1.GetRect2(AKeyboardWindow : HWND): Trect;
var KeyBoardRect: Trect;
begin
DwmGetWindowAttribute(AKeyboardWindow, DWMWA_EXTENDED_FRAME_BOUNDS, @KeyBoardRect, sizeof(KeyBoardRect));
Result := KeyBoardRect;
end;
但
Windows 10触控键盘是一个UWP应用程序。 UWP应用程序没有本机窗口,无法通过HWND引用。您可以使用UI自动化来获取触摸键盘Get size of Windows 10 touch keyboard window的边界矩形!
https://msdn.microsoft.com/en-us/library/windows/desktop/ee671425(v=vs.85).aspx!
加载类型库 - UIAutomationClient接口IUIAutomation,IUIAutomationElement(UIAutomationClient_TLB)
function TForm1.getRect4(AKeyboardWindow : HWND): Trect;
var AUTOMATION : IUIAutomation;
Root : IUIAutomationElement;
rRect:UIAutomationClient_TLB.tagRECT;
begin
AUTOMATION := CoCUIAutomation.Create;
AUTOMATION.GetRootElement(Root);
AUTOMATION.ElementFromHandle(Pointer(AKeyboardWindow), Root);
Root.Get_CurrentBoundingRectangle(rRect);
Result := TRect(rRect);
end;
function TForm1.getRect5(AKeyboardWindow : HWND): Trect;
var AUTOMATION : IUIAutomation;
Root : IUIAutomationElement;
olRect: OleVariant;
rRect:UIAutomationClient_TLB.tagRECT;
begin
AUTOMATION := CoCUIAutomation.Create;
AUTOMATION.GetRootElement(Root);
AUTOMATION.ElementFromHandle(Pointer(AKeyboardWindow), Root);
Root.GetCurrentPropertyValue(BoundingRectangle, olRect);
AUTOMATION.VariantToRect(olRect, rRect);
Result := TRect(rRect);
end;
键盘通话
function ExpandEnvironmentVar(var Value: string): Boolean;
var
R: Integer;
Expanded: string;
procedure StrResetLength(var S: string);
var
I: Integer;
begin
for I := 0 to Length(S) - 1 do
if S[I + 1] = #0 then
begin
SetLength(S, I);
Exit;
end;
end;
begin
SetLength(Expanded, 1);
R := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), 0);
SetLength(Expanded, R);
Result := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), R) <> 0;
if Result then
begin
StrResetLength(Expanded);
Value := Expanded;
end;
end;
procedure TForm1.btnCloseClick(Sender: TObject);
var
MyHandle1: THandle;
begin
MyHandle1 := FindWindow('IPTip_Main_Window', nil);
if MyHandle1 <> 0 then
PostMessage(MyHandle1, WM_SYSCOMMAND, SC_CLOSE, 0);
end;
procedure TForm1.btnOpenClick(Sender: TObject);
var
S: string;
begin
btnClose.Click;
S := '%CommonProgramW6432%\microsoft shared\ink\tabtip.exe';
ExpandEnvironmentVar(S);
ShellExecute(0, PChar('open'), PChar(S), nil, nil, SW_SHOWNORMAL);
end;
没有成功(左= 0顶= 0宽= 0高= 0)!有没有人这样做过,或者他知道该怎么办?
答案 0 :(得分:1)
您应该实施IFrameworkInputPaneHandler
:
允许在显示或隐藏输入窗格(屏幕键盘或手写面板)时通知应用。这允许应用程序窗口调整其显示,以便输入窗格不会遮挡输入区域(例如文本框)。
有关详细信息和示例代码,请参阅this blog post。