SendMessage 视频捕获常量

发布于 2024-09-03 14:45:43 字数 427 浏览 6 评论 0原文

我正在使用代码示例连接到网络摄像头,但并不真正理解传递给 SendMessage 方法的变量的含义。

SendMessage(DeviceHandle, WM_CAP_SET_SCALE, -1, 0)

SendMessage(DeviceHandle, WM_CAP_SET_PREVIEW, -1, 0)

-1 是什么意思?缩放/预览还是不缩放/预览?我更喜欢使用零/一,零意味着错误,并且不知道-1意味着什么。

SendMessage(DeviceHandle, WM_CAP_EDIT_COPY, 0, 0);

在这种情况下零意味着什么?或者这条消息只是无效并且零没有任何意义,类似于最后一个零参数?

顺便说一句,最后一个零参数是什么意思?

预先非常感谢您:)

I am using a code sample to connect to a webcam, and don't really understand the meaning of the variables passed to the SendMessage method.

SendMessage(DeviceHandle, WM_CAP_SET_SCALE, -1, 0)

SendMessage(DeviceHandle, WM_CAP_SET_PREVIEW, -1, 0)

What does the -1 mean? To scale/preview or not to scale/preview? I'd prefer that zero/one would be used, zero meaning false, and have no idea what the -1 means.

SendMessage(DeviceHandle, WM_CAP_EDIT_COPY, 0, 0);

What does the zero mean in this case? Or does this message is simply void and the zero has no meaning, similar to the last zero argument?

Btw, what DOES the last zero argument mean?

Thank you very much in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-09-10 14:45:43

您可能已经找到了最初用 Visual Basic 编写的示例代码。 SendMessage() 的 WParam 参数被记录为 BOOL。它应该为 FALSE (0) 或 TRUE (1)。 VB6 的一个怪癖是它的布尔 TRUE 值为 -1。原因有点晦涩,与 AND 和 OR 运算符的工作方式有关。

您当前的代码是偶然运行的,解释该消息的 Windows 代码只是将任何非零值视为“TRUE”。

但还有一个更大的问题,您的 SendMessage() 声明是错误的。 WParam 和 LParam 参数可能被声明为“int”,一个 32 位值。然而,在 64 位操作系统上,它们是 64 位值。在这样的操作系统上,您的 SendMessage() 调用将严重失败。还有一些可能性是,您已经在 64 位操作系统上,并且将这些参数声明为 Long,就像它们在 VB6 中声明的方式一样。在这种情况下,您的代码将在 32 位操作系统上失败。

SendMessage 的正确声明:

 [DllImport("user32.dll")]
 private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

以及发送消息的正确方法:

 SendMessage(DeviceHandle, WM_CAP_SET_SCALE, (IntPtr)1, IntPtr.Zero);

这将在 32 位和 64 位操作系统上正常工作。

You've probably found sample code that was originally written in Visual Basic. The WParam argument for SendMessage() is documented to be a BOOL. It should be either FALSE (0) or TRUE (1). A quirk of VB6 is that its boolean TRUE value is -1. The reason is a bit obscure and related to the way its AND and OR operators work.

Your current code works by accident, the Windows code that interprets the message simply treats any non-zero value as "TRUE".

There is a bigger problem though, your SendMessage() declaration is wrong. The WParam and LParam arguments are probably declared as "int", a 32-bit value. On 64-bit operating systems they are however a 64-bit value. On such an operating system your SendMessage() call will fail badly. There's also some odds that you are already on a 64-bit operating system and have these arguments declared as Long, the way they were declared in VB6. In which case your code will fail on a 32-bit operating system.

The proper declaration for SendMessage:

 [DllImport("user32.dll")]
 private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

And the proper way to send the message:

 SendMessage(DeviceHandle, WM_CAP_SET_SCALE, (IntPtr)1, IntPtr.Zero);

That will work correctly on both 32-bit and 64-bit operating systems.

祁梦 2024-09-10 14:45:43

WM_CAP_SET_SCALE 消息启用或禁用预览视频图像的缩放

WM_CAP_SET_PREVIEW 消息启用或禁用预览模式

WM_CAP_EDIT_COPY 消息将视频帧缓冲区和关联调色板的内容复制到剪贴板

SendMessage 有下一个签名:

LRESULT WINAPI SendMessage(
  __in  HWND hWnd,
  __in  UINT Msg,
  __in  WPARAM wParam,
  __in  LPARAM lParam
);

其中 wParamlParam -是“附加消息特定信息”。 Wparam 类型表示 wordLparam 表示 long

该参数是可选的,可以使用也可以不使用。因此,如果某些消息需要发送附加数据,则使用其中之一或两者。

WM_CAP_SET_SCALE message enables or disables scaling of the preview video images

WM_CAP_SET_PREVIEW message enables or disables preview mode

WM_CAP_EDIT_COPY message copies the contents of the video frame buffer and associated palette to the clipboard

SendMessage has next signature:

LRESULT WINAPI SendMessage(
  __in  HWND hWnd,
  __in  UINT Msg,
  __in  WPARAM wParam,
  __in  LPARAM lParam
);

Where wParam and lParam - are "Additional message-specific information". Wparam type means word and Lparam means long.

This parameters are optional and can be used or can be not used. So one of them or both are used if some message requires addition data to be sent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文