开发者

SendMessage videocapture consts

开发者 https://www.devze.com 2023-01-01 06:51 出处:网络
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.

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 mea开发者_StackOverflow中文版n?

Thank you very much in advance :)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号