Unable to pass winform control size to unmanaged code

I use unmanaged libraries to get the video stream from the IP camera. There is a function:

[DllImport("client.dll", EntryPoint = "Network_ClientStartLive", SetLastError = true)] protected static extern int Network_ClientStartLive( ref IntPtr pStream, IntPtr hDev, IntPtr pClientInfo, [MarshalAs(UnmanagedType.FunctionPtr)] ReadDatacbf lpfnCallbackFunc = null, UInt32 dwUserData = 0 ); 

pClientInfo is a pointer to a structure type:

 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] protected struct LiveConnect { public UInt32 dwChannel; public IntPtr hPlayWnd; public UInt32 dwConnectMode; } 

where hPlayWnd is the handle to the window in which the video stream should be displayed. The library determines the resolution of the video by the size of this window (during a call to Network_ClientStartLive ). I tested it in the C ++ MFC program, where the Picture control output window and by setting the size using the MoveWindow method, the resolution of the output video was determined.

In the C # version of this program, I use a PictureBox -control to draw a video stream. The video is displayed, but the size of the PictureBox does not affect the resolution of the video stream. I tried several ways to resize PictureBox :

  • setting pictureBox.Size
  • using WinAPI SetWindowPos :
  [DllImport ("user32.dll")]
 private static extern bool SetWindowPos (
     IntPtr hWnd, 
     IntPtr hWndInsertAfter,
     int x, 
     int y 
     int width, 
     int height, 
     uint uFlags);

In both methods, the size of the control was changed, but the camera library continued to output the video stream with maximum resolution.

How can I solve this problem?

Thanks!

+7
source share
1 answer

Each control in Windows Forms has SizeChanged ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.sizechanged(v = vs .110) .aspx ). Maybe you can add code to change the video resolution manually in this event handler? If not, the PictureBox handler that you provide may not send WM_SIZE messages that the unmanaged library will look for. As mentioned in one of the comments, Spy ++ (part of Visual Studio) will be a useful program for monitoring messages and make sure that the descriptor and event values ​​are what you expect from them.

+1
source

All Articles