- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Delphi 10.1 Berlin,VCL 项目。我尝试使用触摸屏和 Windows 生成的 WM_Touch 消息同时移动多个面板。我基于 Chris Benson 博客中的示例代码:http://chrisbensen.blogspot.com/2009/11/touch-demo.html
只有当我先触摸背景表单上的某个位置,然后将手指拖到面板上时,它才在一定程度上起作用。如果我先触摸背景,面板将随着我的手指移动。据我所知,当我触摸窗体顶部的面板时,似乎 TForm1.WMTouch 过程不会被调用。除非我先触摸表单,否则我不会收到 WM_Touch 消息。
在 Chris 的博客中,他调用了 RegisterTouchWindow(Handle, 0);在表单创建中。我认为这就是为什么当您触摸表单时会调用该过程的原因。每当我触摸面板时,如何调用 WM_Touch 过程?
-我尝试使用面板的 OnClick 事件,但这不起作用,因为它似乎没有将触摸注册为 OnClick 事件。
-这是我应该使用 Inherit 类的东西吗?如果是这样,我该怎么做?
预先感谢您的任何想法!
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TOUCHINPUT = record
x: Integer;
y: Integer;
hSource: THandle;
dwID: DWORD;
dwFlags: DWORD;
dwMask: DWORD;
dwTime: DWORD;
dwExtraInfo: ULONG_PTR;
cxContact: DWORD;
cyContact: DWORD;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure WMTouch(var Message: TMessage); message wm_Touch;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;
var
Form1: TForm1;
implementation
//==============================================================================
//======================== FORM CREATE =========================================
procedure TForm1.FormCreate(Sender: TObject);
begin
// inherited;
RegisterTouchWindow(Handle, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterTouchWindow(Handle);
end;
//==============================================================================
//========================= WM TOUCH ===========================================
procedure TForm1.WMTouch(var Message: TMessage);
//==============
function TouchPointToPoint(const TouchPoint: TTouchInput): TPoint;
begin
Result := Point(TouchPoint.X div 100, TouchPoint.Y div 100);
PhysicalToLogicalPoint(Handle, Result);
end;
//==============
var
TouchInputs: array of TTouchInput;
TouchInput: TTouchInput;
Handled: Boolean;
Point: TPoint;
begin
Handled := False;
SetLength(TouchInputs, Message.WParam);
GetTouchInputInfo(Message.LParam, Message.WParam,
@TouchInputs[0], SizeOf(TTouchInput));
try
for TouchInput in TouchInputs do
begin
Point := TouchPointToPoint(TouchInput);
if PtInRect(Panel1.BoundsRect,Point) then
begin
label1.Caption:='Touch ID: ' + inttostr(TouchInput.dwID);
panel1.Top:=point.Y-100;
end;
if PtInRect(Panel2.BoundsRect,Point) then
begin
label1.Caption:='Touch ID: ' + inttostr(TouchInput.dwID);
panel2.Top:=point.Y-100;
end;
if PtInRect(Panel3.BoundsRect,Point) then
begin
label1.Caption:='Touch ID: ' + inttostr(TouchInput.dwID);
panel3.Top:=point.Y-100;
end;
end;
Handled := True;
finally
if Handled then
CloseTouchInputHandle(Message.LParam)
else
// inherited;
end;
end;
end.
最佳答案
From what I can tell, it seems like the TForm1.WMTouch procedure will not get called when I touch a panel that is on top of the Form. I don't receive WM_Touch messages unless I touch the form first.
正确,因为您没有触摸表单本身,而是触摸了表单顶部的面板。
In Chris' blog he calls the RegisterTouchWindow(Handle, 0); in the Form Create. Which I assume is why the procedure will get called when you touch the Form.
是的。
How would I go about getting the WM_Touch procedure called whenever I touch the panel?
您必须注册面板的 HWND
而不是表单的 HWND
。并对每个面板单独执行此操作。这甚至在 RegisterTouchWindow()
中也有同样的说明。文档:
Note
RegisterTouchWindow
must be called on every window that will be used for touch input. This means that if you have an application that has multiple windows within it,RegisterTouchWindow
must be called on every window in that application that uses touch features. Also, an application can callRegisterTouchWindow
any number of times for the same window if it desires to change the modifier flags. A window can be marked as no longer requiring touch input using theUnregisterTouchWindow
function.
您还必须对每个面板进行子类化以处理每个面板的 WM_TOUCH
消息,因为它将直接发送到每个注册的面板而不是表单。
如果您希望表单上的每个面板都具有触摸功能,一个简单的插入器类就足够了:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TPanel = class(Vcl.ExtCtrls.TPanel)
protected
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure WMTouch(var Message: TMessage); message WM_TOUCH;
end;
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
end;
var
Form1: TForm1;
implementation
type
TOUCHINPUT = record
x: Integer;
y: Integer;
hSource: THandle;
dwID: DWORD;
dwFlags: DWORD;
dwMask: DWORD;
dwTime: DWORD;
dwExtraInfo: ULONG_PTR;
cxContact: DWORD;
cyContact: DWORD;
end;
procedure TPanel.CreateWnd;
begin
inherited;
RegisterTouchWindow(Handle, 0);
end;
procedure TPanel.DestroyWnd;
begin
UnregisterTouchWindow(Handle);
inherited;
end;
procedure TPanel.WMTouch(var Message: TMessage);
function TouchPointToPoint(const TouchPoint: TTouchInput): TPoint;
begin
Result := Point(TouchPoint.X div 100, TouchPoint.Y div 100);
PhysicalToLogicalPoint(Handle, Result);
end;
var
TouchInputs: array of TTouchInput;
TouchInput: TTouchInput;
Handled: Boolean;
Point: TPoint;
begin
Handled := False;
SetLength(TouchInputs, Message.WParam);
GetTouchInputInfo(Message.LParam, Message.WParam,
@TouchInputs[0], SizeOf(TTouchInput));
try
for TouchInput in TouchInputs do
begin
Point := TouchPointToPoint(TouchInput);
if PtInRect(BoundsRect, Point) then
begin
//labelX.Caption := 'Touch ID: ' + IntToStr(TouchInput.dwID);
Top := Point.Y - 100;
end;
Handled := True;
end;
finally
if Handled then
CloseTouchInputHandle(Message.LParam)
else
inherited;
end;
end;
end.
关于Delphi VCL - WM_Touch RegisterTouchWindow(Handle, 0);触摸面板时不会处理消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58348375/
尝试使用集成到 QTCreator 的表单编辑器,但即使我将插件放入 QtCreator.app/Contents/MacOS/designer 也不会显示。不过,相同的 dylib 文件确实适用于独
在此代码示例中。 “this.method2();”之后会读到什么?在返回returnedValue之前会跳转到method2()吗? public int method1(int returnedV
我的项目有通过gradle配置的依赖项。我想添加以下依赖项: compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', v
我将把我们基于 Windows 的客户管理软件移植到基于 Web 的软件。我发现 polymer 可能是一种选择。 但是,对于我们的使用,我们找不到 polymer 组件具有表格 View 、下拉菜单
我的项目文件夹 Project 中有一个文件夹,比如 ED 文件夹,当我在 Eclipse 中指定在哪里查找我写入的文件时 File file = new File("ED/text.txt"); e
这是奇怪的事情,这个有效: $('#box').css({"backgroundPosition": "0px 250px"}); 但这不起作用,它只是不改变位置: $('#box').animate
这个问题在这里已经有了答案: Why does OR 0 round numbers in Javascript? (3 个答案) 关闭 5 年前。 Mozilla JavaScript Guide
这个问题在这里已经有了答案: Is the function strcmpi in the C standard libary of ISO? (3 个答案) 关闭 8 年前。 我有一个问题,为什么
我目前使用的是共享主机方案,我不确定它使用的是哪个版本的 MySQL,但它似乎不支持 DATETIMEOFFSET 类型。 是否存在支持 DATETIMEOFFSET 的 MySQL 版本?或者有计划
研究 Seam 3,我发现 Seam Solder 允许将 @Named 注释应用于包 - 在这种情况下,该包中的所有 bean 都将自动命名,就好像它们符合条件一样@Named 他们自己。我没有看到
我知道 .append 偶尔会增加数组的容量并形成数组的新副本,但 .removeLast 会逆转这种情况并减少容量通过复制到一个新的更小的数组来改变数组? 最佳答案 否(或者至少如果是,则它是一个错
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
noexcept 函数说明符是否旨在 boost 性能,因为生成的对象中可能没有记录异常的代码,因此应尽可能将其添加到函数声明和定义中?我首先想到了可调用对象的包装器,其中 noexcept 可能会产
我正在使用 Angularjs 1.3.7,刚刚发现 Promise.all 在成功响应后不会更新 angularjs View ,而 $q.all 会。由于 Promises 包含在 native
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我正在编写一个玩具(物理)矢量库,并且遇到了 GHC 坚持认为函数应该具有 Integer 的问题。是他们的类型。我希望向量乘以向量以及标量(仅使用 * ),虽然这可以通过仅使用 Vector 来实现
PHP 的 mail() 函数发送邮件正常,但 Swiftmailer 的 Swift_MailTransport 不起作用! 这有效: mail('user@example.com', 'test
我尝试通过 php 脚本转储我的数据,但没有命令行。所以我用 this script 创建了我的 .sql 文件然后我尝试使用我的脚本: $link = mysql_connect($host, $u
使用 python 2.6.4 中的 sqlite3 标准库,以下查询在 sqlite3 命令行上运行良好: select segmentid, node_t, start, number,title
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我是一名优秀的程序员,十分优秀!