需要确定TabTip的大小(宽度、高度)和位置(左、上)。windows 10上的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\U 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)!有没有人做过这样的事,或者他知道该怎么做?