SendMessage 视频捕获常量
我正在使用代码示例连接到网络摄像头,但并不真正理解传递给 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能已经找到了最初用 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 的正确声明:
以及发送消息的正确方法:
这将在 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:
And the proper way to send the message:
That will work correctly on both 32-bit and 64-bit operating systems.
WM_CAP_SET_SCALE
消息启用或禁用预览视频图像的缩放WM_CAP_SET_PREVIEW
消息启用或禁用预览模式WM_CAP_EDIT_COPY
消息将视频帧缓冲区和关联调色板的内容复制到剪贴板SendMessage
有下一个签名:其中
wParam
和lParam
-是“附加消息特定信息”。Wparam
类型表示word
,Lparam
表示long
。该参数是可选的,可以使用也可以不使用。因此,如果某些消息需要发送附加数据,则使用其中之一或两者。
WM_CAP_SET_SCALE
message enables or disables scaling of the preview video imagesWM_CAP_SET_PREVIEW
message enables or disables preview modeWM_CAP_EDIT_COPY
message copies the contents of the video frame buffer and associated palette to the clipboardSendMessage
has next signature:Where
wParam
andlParam
- are "Additional message-specific information".Wparam
type meansword
andLparam
meanslong
.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.