what is the meaning of  following assignment in vb.net2003 windows application ?

Posted on 2009-12-29
Last Modified: 2013-11-17
Const WM_CAP As Short = &H400S

what is meaning of &h400s
what is the meaning of the symbol  &
what will execute   for this assignment ?
please explain as clear.
Question by:Tamilselvan
    LVL 8

    Accepted Solution

    Its a constant. You are defining a constant. Something like #define in C,C++. Can you tell the background of this code snippet???
    LVL 8

    Assisted Solution

    &H is use for defining a variable in HEX
    LVL 5

    Assisted Solution

    by:Khalid Mehmood Awan
    May be this will help you, &H is used for hexadecimal numbers.

    LVL 42

    Assisted Solution

    deinfing a constant variable named WM_CAP with value 0x400 in hex (1024 in decimal)

    C# ->  const short WM_CAP = 0x400;

    it is used in multimedia messages to capture video from a video device such as a webcam.



    Author Comment

    Const WM_CAP As Short = &H400S
    is this &h400s identifiy the usb port or  not  ?

    LVL 42

    Assisted Solution

    it is just a constant to use for other WM_CAP mesages to send to the device.
    chjeck the code snippet
    ' Create constant to use when sending messages to device
        Const WM_CAP As Short = &H400S
        Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
        Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
        Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
        Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
        Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
        Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
        Const WS_CHILD As Integer = &H40000000
        Const WS_VISIBLE As Integer = &H10000000
        Const SWP_NOMOVE As Short = &H2S
        Const SWP_NOSIZE As Short = 1
        Const SWP_NOZORDER As Short = &H4S
        Const HWND_BOTTOM As Short = 1
        Dim iDevice As Integer = 0  ' Normal device ID 
        Dim hHwnd As Integer  ' Handle value to preview window
      ' Declare function from AVI capture DLL.
        Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
            (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
             ByVal lParam As Object) As Integer
        Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
            ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
            ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
        Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean
        Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
            (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
            ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
            ByVal nHeight As Short, ByVal hWndParent As Integer, _
            ByVal nID As Integer) As Integer
        Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
            ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
            ByVal cbVer As Integer) As Boolean
      ' Load name of all avialable devices into the lstDevices .
    Private Sub LoadDeviceList()
            Dim strName As String = Space(100)
            Dim strVer As String = Space(100)
            Dim bReturn As Boolean
            Dim x As Integer = 0
    Dim lstDevices as ListBox = new ListBox()
              '   Get Driver name and version
               bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
               ' If there was a device add device name to the list 
               If bReturn Then lstDevices.Items.Add(strName.Trim)
                x += 1
            Loop Until bReturn = False
        End Sub
       ' To display the output from a video capture device, you need to create a capture window.
     Private Sub OpenPreviewWindow()
            Dim iHeight As Integer = picCapture.Height
            Dim iWidth As Integer = picCapture.Width
            ' Open Preview window in picturebox .
            ' Create a child window with capCreateCaptureWindowA so you can display it in a picturebox.
            hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
                480, picCapture.Handle.ToInt32, 0)
         ' Connect to device
          If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
          ' Set the preview scale
               SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
          ' Set the preview rate in milliseconds
              SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
          ' Start previewing the image from the camera 
                SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
           ' Resize window to fit in picturebox 
                SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
                                       SWP_NOMOVE Or SWP_NOZORDER)
                btnSave.Enabled = True
                btnStop.Enabled = True
                btnStart.Enabled = False
            ' Error connecting to device close window 
              btnSave.Enabled = False
            End If
        End Sub
     'disconnect from the device
      Private Sub ClosePreviewWindow()
           ' Disconnect from device
           SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
       End Sub

    Open in new window

    LVL 42

    Assisted Solution

    u can see that WM_CAP is merely used as an offset of the actual messages Ids.
    u could have drop WM_CAP and use the actual value of the WM_CAP_XXX:

        Const WM_CAP_DRIVER_CONNECT As Integer = 1034
        Const WM_CAP_DRIVER_DISCONNECT As Integer = 1035
        Const WM_CAP_EDIT_COPY As Integer = 1054
        Const WM_CAP_SET_PREVIEW As Integer = 1074
        Const WM_CAP_SET_PREVIEWRATE As Integer = 1076
        Const WM_CAP_SET_SCALE As Integer = 1077

    Author Comment

    i dont understand. please clarify.
    what does identify 1034.
    is it call to function id ?
    is it a driver file id number?
    LVL 42

    Assisted Solution

    1034 is the message id sent to the device.
    it's similar to any other window message in win32 api.
    for example, when u click a left button on winform, in the background SendMessage() is called with WM_LBUTTONCLICK:
    SendMessage( m_hWnd, WM_LBUTTONCLICK, 0, 0);  

    m_hWnd is the handle of the window, WM_LBUTTONCLICK is a constant with value 0x0201 (which is 513 in decimal)
    the other 2 params has different meaning for each message.

    regarding WM_CAP messages, in avicap32.dll all constants are declared the same way.
    so lets take one line from the code above:
    SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

    SendMessage locate the target using the handle hHwnd and send the message  WM_CAP_DRIVER_DISCONNECT with 2 additional params (iDevice and 0).
    somehere in avicap32.dll there's a switch which handles all WM_CAP messages, something like:

    LRESULT ::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )  
    case Const WM_CAP_DRIVER_CONNECT :
    //connect to device

    //disconnect from device


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now