TabTip.exe(虚拟键盘)在 Windows 10 上的大小和位置?
Size and position of TabTip.exe (virtual keyboard) on Windows 10?
需要确定 TabTip.exe(虚拟键盘)在 windows 10 上的大小(宽度、高度)和位置(左、上)?
任务是移动所有组件所在的面板,使输入焦点转移到的输入字段位于虚拟键盘上方。
使用Windows10不在admin下,但是编译的项目是运行作为admin!
以下解决方案在 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 应用程序没有原生 windows,无法通过 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;
没有成功(left = 0 top = 0 width = 0 height = 0)!有没有人做过这样的事情,或者他知道该怎么办?
您应该实施 IFrameworkInputPaneHandler
:
Enables an app to be notified when the input pane (the on-screen keyboard or handwriting panel) is being shown or hidden. This allows the app window to adjust its display so that no input areas (such as a text box) are obscured by the input pane.
有关详细信息和示例代码,请参阅 this blog post。
需要确定 TabTip.exe(虚拟键盘)在 windows 10 上的大小(宽度、高度)和位置(左、上)?
任务是移动所有组件所在的面板,使输入焦点转移到的输入字段位于虚拟键盘上方。
使用Windows10不在admin下,但是编译的项目是运行作为admin!
以下解决方案在 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 应用程序没有原生 windows,无法通过 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;
没有成功(left = 0 top = 0 width = 0 height = 0)!有没有人做过这样的事情,或者他知道该怎么办?
您应该实施 IFrameworkInputPaneHandler
:
Enables an app to be notified when the input pane (the on-screen keyboard or handwriting panel) is being shown or hidden. This allows the app window to adjust its display so that no input areas (such as a text box) are obscured by the input pane.
有关详细信息和示例代码,请参阅 this blog post。