How to capture video to full screen in Visual Basic Express 2008

The Problem
TV capture devices that use standard Microsoft WDM drivers have a maximum resolution of 720 x 576 .
That frame has a 5:4 ratio, so when the TV is broadcasting a film in 16:9 ratio,
you get black filler strips along the top and bottom of the frame.
My monitor has a native resolution of 1440 x 900 , a ratio of 8:5 .
So when the 5:4 ratio frame is displayed inside the 8:5 monitor,
you get black filler strips along the left and right edges of the monitor.



What I want is to be able to zoom the picture as much as I like,
so the good bits fill the screen.

The Solution
This application is written in Visual Basic Express 2008.
The zipped project files can be downloaded from :
www.peakoil.org.au/dave.kimble/doctor/kvideocapture/videocapture.zoom.zip [ 1.0 MB ]

It is a simple example of capturing a video stream from the first Imaging Device in Device Manager's list,
and putting it on the screen centred and zoomable - so any unnecessary black filler around the picture can be eliminated.

There is a form the same size as the monitor screen ( 1440 x 900 ) in this case.
And there is a PictureBox control that starts with size ( 1126 x 900 ) -
in proportion 5:4 like the ( 720 x 576 ) output of the imaging device ( Belkin F5U228 "Hi-Speed USB2 DVD Creator" ).

When the mouse-wheel is rolled, the PictureBox.Size is increased/decreased,
keeping the proportions and changing PictureBox.Location to keep the control centred on the form.
Double-click to bring up the input device driver controls, that let you choose colour system,
adjust brightness/contrast/etc.
Press ALT+F4 to close the application.

This project started off using code from Ken Homza's video capture application at
http://www.a1vbcode.com/download.asp?ID=2470 without which this project would not have been possible.
But it has changed so much since then that Ken can't be blamed for anything.

I have subsequently discovered a mine of information at
MSDN: Video Capture: A minimal approach , particularly the reference section at
http://msdn.microsoft.com/en-us/library/ms713476(VS.85).aspx .



This is the event code:
==============================
     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 720, 576, TVarea.Handle.ToInt32, 0)
        SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0)
        SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
        SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
        ' Preview rate in milliseconds should match monitor refresh rate
        SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 17, 0)
        SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, TVarea.Width, TVarea.Height, SWP_NOZORDER)
    End Sub
=================================
    'This zooms the TVarea, keeping it in proportion and centred on the form by moving the mousewheel 
    'ALT+f4 to close the application

    Private Sub Monitor_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles Me.MouseWheel
        ' Scroll-  increases the TVarea by 10 px 
        If (e.Delta < 0) Then
            TVarea.Left -= 5
            TVarea.Width += 10
            TVarea.Top -= 4
            TVarea.Height += 8
        Else
            ' Scroll+  decreases the TVarea by 10 px
            TVarea.Left += 5
            TVarea.Width -= 10
            TVarea.Top += 4
            TVarea.Height -= 8
        End If
        SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, TVarea.Width, TVarea.Height, SWP_NOZORDER)
    End Sub
===================================
    ' Double click to bring up the video source driver controls
    Private Sub Monitor_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
        SendMessage(hHwnd, WM_CAP_DLG_VIDEOSOURCE, 0, 0)
    End Sub
End Class
===================================