VideoHelp Forum




+ Reply to Thread
Results 1 to 8 of 8
  1. Member
    Join Date
    Oct 2006
    Location
    Malaysia
    Search Comp PM
    Hi..
    I've got a question about SendMessage API (in context of capturing webcam image)..
    Below is the code for capturing image from a webcam.

    I am wondering, what does SendMessage(hwdc, 1034, 0, 0) do..? When I change the number to 1033, it doesn't work.. Does anybody know where i can find out what all the numbers in the SendMessage command mean..? I guess its part of SendMessage API...
    Thanks..

    Code:
    'Module1
    Public Const ws_child As Long = &H40000000
    Public Const ws_visible As Long = &H10000000
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long
    
    
    
    'Code
    Dim hwdc As Long
    Dim startcap As Boolean
    Private Sub cmdCapture_Click()
    Dim temp As Long
    
      hwdc = capCreateCaptureWindow("Dixanta Vision System", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
      If (hwdc <> 0) Then
        temp = SendMessage(hwdc, 1034, 0, 0)
        temp = SendMessage(hwdc, 1074, 1, 0)
        temp = SendMessage(hwdc, 1076, 30, 0)
        startcap = True
        Else
        MsgBox ("No Webcam found")
      End If
    End Sub
    
    Private Sub cmdClose_Click()
    Dim temp As Long
    If startcap = True Then
    temp = SendMessage(hwdc, 1035, 0&, 0&)
    startcap = False
    End If
    End Sub
    
    Private Sub cmdVideoFormat_Click()
     Dim temp As Long
     If startcap = True Then
      temp = SendMessage(hwdc, 1065, 0&, 0&)
    End If
    End Sub
    Quote Quote  
  2. Member ChrissyBoy's Avatar
    Join Date
    Feb 2003
    Location
    Yorkshire!
    Search Comp PM
    Well SendMessage is simply defined as:

    Code:
    Syntax
    
    LRESULT SendMessage(          HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam
    );
    Parameters
    
    hWnd
    [in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
    Msg
    [in] Specifies the message to be sent.
    wParam
    [in] Specifies additional message-specific information.
    lParam
    [in] Specifies additional message-specific information.
    The Msg param is the "message" to send to a window. Msg is a number and numbers 0-1024 are defined by the system (like cut, paste etc). Numbers higher than 1024 are defined by the application. In your case it is defined by avicap32.dll. So 1034, will correspond to a specific constant in avicap32.dll and so when it gets that value as a message (from the application you are writing) it will do something appropriate.

    So what are these user defined Msg constants for avicap32.dll? Well this is what i found:



    Code:
    		public const int WM_USER = 1024;
    
    		public const int WM_CAP_CONNECT = 1034;
    		public const int WM_CAP_DISCONNECT = 1035;
    		public const int WM_CAP_GET_FRAME = 1084;
    		public const int WM_CAP_COPY = 1054;
    
    		public const int WM_CAP_START = WM_USER;
    
    		public const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41;
    		public const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;
    		public const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
    		public const int WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44;
    		public const int WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45;
    		public const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46;
    		public const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
    Which basically means that 1034 is WM_CAP_CONNECT which you can assume gets the dll to "connect". So clearly you can't just send any old number. It has to match to the above constants and those constants need to equate to a function you would like to do.

    Hope that helps.
    SVCD2DVD v2.5, AVI/MPEG/HDTV/AviSynth/h264->DVD, PAL->NTSC conversion.
    VOB2MPG PRO, Extract mpegs from your DVDs - with you in control!
    Quote Quote  
  3. Member
    Join Date
    Oct 2006
    Location
    Malaysia
    Search Comp PM
    I see.. So, if I understand corectly, SendMessage is used to interface or to communicate between the current window and avicap32.dll rite..?
    Quote Quote  
  4. Member ChrissyBoy's Avatar
    Join Date
    Feb 2003
    Location
    Yorkshire!
    Search Comp PM
    In short - yes.
    SVCD2DVD v2.5, AVI/MPEG/HDTV/AviSynth/h264->DVD, PAL->NTSC conversion.
    VOB2MPG PRO, Extract mpegs from your DVDs - with you in control!
    Quote Quote  
  5. Member
    Join Date
    Sep 2006
    Location
    United States
    Search Comp PM
    Not exactly.

    MS Docs say, "The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message."

    A message is never sent to a DLL. It's sent to a window. Now, the window may have been created by a function in the DLL, and the DLL may be responsible for controlling that window, but technically the message is sent to the window. Not the DLL.
    Quote Quote  
  6. Member ChrissyBoy's Avatar
    Join Date
    Feb 2003
    Location
    Yorkshire!
    Search Comp PM
    Quite true. I was keeping my second answer brief...
    SVCD2DVD v2.5, AVI/MPEG/HDTV/AviSynth/h264->DVD, PAL->NTSC conversion.
    VOB2MPG PRO, Extract mpegs from your DVDs - with you in control!
    Quote Quote  
  7. Sorry to butt in but:

    Shouldn't the code in the original post use WM_CAP_CONNECT instead of 1034? It makes the code more readable, and more importantly, should the actual value (1034) ever need to change, the code that uses it won't. Two big reason to use symbolic constants instead of their values
    Quote Quote  
  8. Member
    Join Date
    Sep 2006
    Location
    United States
    Search Comp PM
    VB coders generally don't care about such things.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!