Author Topic: Webcams in QB64?!? More likely than you think!  (Read 4512 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Webcams in QB64?!? More likely than you think!
« on: October 02, 2020, 03:29:55 pm »
So, any friends want to help tackle this and make it work to show more than 2 frames?

  [ You are not allowed to view this attachment ]  

Code: QB64: [Select]
  1. '$CONSOLE:ONLY
  2. '_DEST _CONSOLE
  3. 'Window Style Constants
  4. CONST WS_BORDER = &H00800000
  5. CONST WS_CAPTION = &H00C00000
  6. CONST WS_CHILD = &H40000000
  7. CONST WS_CHILDWINDOW = WS_CHILD
  8. CONST WS_CLIPCHILDREN = &H02000000
  9. CONST WS_CLIPSIBLINGS = &H04000000
  10. CONST WS_DISABLED = &H08000000
  11. CONST WS_DLGFRAME = &H00400000
  12. CONST WS_GROUP = &H00020000
  13. CONST WS_HSCROLL = &H00100000
  14. CONST WS_ICONIC = &H20000000
  15. CONST WS_MAXIMIZE = &H01000000
  16. CONST WS_MAXIMIZEBOX = &H00010000
  17. CONST WS_MINIMIZE = &H20000000
  18. CONST WS_MINIMIZEBOX = &H00020000
  19. CONST WS_OVERLAPPED = &H00000000
  20. CONST WS_POPUP = &H80000000
  21. CONST WS_SIZEBOX = &H00040000
  22. CONST WS_SYSMENU = &H00080000
  23. CONST WS_TABSTOP = &H00010000
  24. CONST WS_THICKFRAME = &H00040000
  25. CONST WS_TILED = &H00000000
  26. CONST WS_VISIBLE = &H10000000
  27. CONST WS_VSCROLL = &H00200000
  28. CONST WS_TILEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  29. CONST WS_POPUPWINDOW = WS_POPUP OR WS_BORDER OR WS_SYSMENU
  30. CONST WS_OVERLAPPEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  31. '------------------------------------------------------------------------------------------------------------------------------
  32. 'Capture Driver Constants
  33. CONST WM_CAP_START = &H0400
  34. CONST WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
  35. CONST WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
  36. CONST WM_CAP_EDIT_COPY = WM_CAP_START + 30
  37. CONST WM_CAP_GRAB_FRAME = WM_CAP_START + 60
  38. CONST WM_CAP_SET_SCALE = WM_CAP_START + 53
  39. CONST WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
  40. CONST WM_CAP_SET_PREVIEW = WM_CAP_START + 50
  41. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  42. CONST WM_CAP_STOP = WM_CAP_START + 68
  43. CONST WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14
  44. CONST WM_CAP_GET_STATUS = WM_CAP_START + 54
  45. CONST WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
  46. CONST WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
  47. '------------------------------------------------------------------------------------------------------------------------------
  48. 'Window Pos Constants
  49. CONST SWP_ASYNCWINDOWPOS = &H4000
  50. CONST SWP_DEFERERASE = &H2000
  51. CONST SWP_DRAWFRAME = &H0020
  52. CONST SWP_FRAMECHANGED = &H0020
  53. CONST SWP_HIDEWINDOW = &H0080
  54. CONST SWP_NOACTIVATE = &H0010
  55. CONST SWP_NOCOPYBITS = &H0100
  56. CONST SWP_NOMOVE = &H0002
  57. CONST SWP_NOOWNERZORDER = &H0200
  58. CONST SWP_NOREDRAW = &H0008
  59. CONST SWP_NOREPOSITION = &H0200
  60. CONST SWP_NOSENDCHANGING = &H0400
  61. CONST SWP_NOSIZE = &H0001
  62. CONST SWP_NOZORDER = &H0004
  63. CONST SWP_SHOWWINDOW = &H0040
  64. '------------------------------------------------------------------------------------------------------------------------------
  65. TYPE CapDriverCaps
  66.     DeviceIndex AS _UNSIGNED INTEGER
  67.     HasOverlay AS _BYTE
  68.     HasDlgVideoSource AS _BYTE
  69.     HasDlgVideoFormat AS _BYTE
  70.     HasDlgVideoDisplay AS _BYTE
  71.     CaptureInitialized AS _BYTE
  72.     DriverSuppliesPalettes AS _BYTE
  73.     hVideoIn AS LONG
  74.     hVideoOut AS LONG
  75.     hVideoExtIn AS LONG
  76.     hVideoExtOut AS LONG
  77.  
  78. TYPE POINTAPI
  79.     x AS LONG
  80.     y AS LONG
  81.  
  82. TYPE CapStatus
  83.     ImageWidth AS _UNSIGNED INTEGER
  84.     ImageHeight AS _UNSIGNED INTEGER
  85.     LiveWindow AS _BYTE
  86.     OverlayWindow AS _BYTE
  87.     Scale AS _BYTE
  88.     Scroll AS POINTAPI
  89.     UsingDefaultPalette AS _BYTE
  90.     AudioHardware AS _BYTE
  91.     CapFileExists AS _BYTE
  92.     CurrentVideoFrame AS LONG
  93.     CurrentVideoFramesDropped AS LONG
  94.     CurrentWaveSamples AS LONG
  95.     CurrentTimeElapsedMS AS LONG
  96.     PalCurrent AS LONG
  97.     CapturingNow AS _BYTE
  98.     Return AS LONG
  99.     NumVideoAllocated AS _UNSIGNED INTEGER
  100.     NumAudioAllocated AS _UNSIGNED INTEGER
  101.  
  102.     FUNCTION CreateCaptureWindow& ALIAS capCreateCaptureWindowA (lpszWindowName AS STRING, BYVAL dwStyle AS _OFFSET, BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL nWidth AS INTEGER, BYVAL nHeight AS INTEGER, BYVAL hwndParent AS _INTEGER64, BYVAL nId AS INTEGER)
  103.     FUNCTION GetDriverDescription%% ALIAS capGetDriverDescriptionA (BYVAL wDriverIndex AS _UNSIGNED INTEGER, BYVAL lpszName AS _OFFSET, BYVAL cbName AS INTEGER, BYVAL lpszVer AS _OFFSET, BYVAL cbVer AS INTEGER)
  104.  
  105.     FUNCTION SendMessage& ALIAS SendMessageA (BYVAL hWnd AS LONG, BYVAL Msg AS _UNSIGNED INTEGER, BYVAL wParam AS LONG, BYVAL lParam AS _OFFSET)
  106.     FUNCTION SetWindowPos%% (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _UNSIGNED INTEGER)
  107.  
  108. DIM childWin AS LONG
  109.  
  110. DIM captureWinText AS STRING
  111. captureWinText = "My Capture Window" + CHR$(0)
  112. DIM childID AS INTEGER
  113. childWin = CreateCaptureWindow(captureWinText, WS_VISIBLE, 0, 0, 640, 480, _WINDOWHANDLE, childID)
  114. PRINT childWin
  115.  
  116. PRINT "Connecting Driver:", , SendMessage(childWin, WM_CAP_DRIVER_CONNECT, 0, 0)
  117. DIM DeviceName AS STRING
  118. DIM DeviceVersion AS STRING
  119.  
  120. 'FOR wIndex = 0 TO 10
  121. DeviceName = SPACE$(80)
  122. DeviceVersion = SPACE$(80)
  123. PRINT "Getting Driver Description:", GetDriverDescription(wIndex, _OFFSET(DeviceName), LEN(DeviceName), _OFFSET(DeviceVersion), LEN(DeviceVersion))
  124. PRINT DeviceName, DeviceVersion
  125. 'NEXT
  126.  
  127. DIM driverCaps AS CapDriverCaps
  128. driverCaps.DeviceIndex = 0
  129. PRINT "Getting Driver Capability:", SendMessage(childWin, WM_CAP_DRIVER_GET_CAPS, LEN(driverCaps), _OFFSET(driverCaps))
  130.  
  131. DIM capstatus AS CapStatus
  132. PRINT "Setting Format:", SendMessage(childWin, WM_CAP_DLG_VIDEOFORMAT, 0, 0)
  133. PRINT "Setting Preview Scale:", SendMessage(childWin, WM_CAP_SET_SCALE, -1, 0)
  134. PRINT "Setting Preview Rate:", SendMessage(childWin, WM_CAP_SET_PREVIEWRATE, 66, 0)
  135. PRINT "Setting Preview:", , SendMessage(childWin, WM_CAP_SET_PREVIEW, -1, 0)
  136. 'PRINT "Getting Status:", SendMessage(childWin, WM_CAP_GET_STATUS, LEN(capstatus), _OFFSET(capstatus))
  137. 'PRINT SetWindowPos(childWin, 0, 0, 0, capstatus.ImageWidth, capstatus.ImageHeight, SWP_NOZORDER OR SWP_NOMOVE)
  138.  
  139. PRINT "Disconnecting Driver:", SendMessage(childWin, WM_CAP_DRIVER_DISCONNECT, 0, 0)
Shuwatch!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #1 on: October 02, 2020, 03:57:38 pm »
Hi. Perfect work. What function call camera setup dialog? This is my attempt. It works now, it do more frames, but camera setup dialog is still here:

Code: QB64: [Select]
  1. '$CONSOLE:ONLY
  2. '_DEST _CONSOLE
  3. 'Window Style Constants
  4. CONST WS_BORDER = &H00800000
  5. CONST WS_CAPTION = &H00C00000
  6. CONST WS_CHILD = &H40000000
  7. CONST WS_CHILDWINDOW = WS_CHILD
  8. CONST WS_CLIPCHILDREN = &H02000000
  9. CONST WS_CLIPSIBLINGS = &H04000000
  10. CONST WS_DISABLED = &H08000000
  11. CONST WS_DLGFRAME = &H00400000
  12. CONST WS_GROUP = &H00020000
  13. CONST WS_HSCROLL = &H00100000
  14. CONST WS_ICONIC = &H20000000
  15. CONST WS_MAXIMIZE = &H01000000
  16. CONST WS_MAXIMIZEBOX = &H00010000
  17. CONST WS_MINIMIZE = &H20000000
  18. CONST WS_MINIMIZEBOX = &H00020000
  19. CONST WS_OVERLAPPED = &H00000000
  20. CONST WS_POPUP = &H80000000
  21. CONST WS_SIZEBOX = &H00040000
  22. CONST WS_SYSMENU = &H00080000
  23. CONST WS_TABSTOP = &H00010000
  24. CONST WS_THICKFRAME = &H00040000
  25. CONST WS_TILED = &H00000000
  26. CONST WS_VISIBLE = &H10000000
  27. CONST WS_VSCROLL = &H00200000
  28. CONST WS_TILEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  29. CONST WS_POPUPWINDOW = WS_POPUP OR WS_BORDER OR WS_SYSMENU
  30. CONST WS_OVERLAPPEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  31. '------------------------------------------------------------------------------------------------------------------------------
  32. 'Capture Driver Constants
  33. CONST WM_CAP_START = &H0400
  34. CONST WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
  35. CONST WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
  36. CONST WM_CAP_EDIT_COPY = WM_CAP_START + 30
  37. CONST WM_CAP_GRAB_FRAME = WM_CAP_START + 60
  38. CONST WM_CAP_SET_SCALE = WM_CAP_START + 53
  39. CONST WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
  40. CONST WM_CAP_SET_PREVIEW = WM_CAP_START + 50
  41. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  42. CONST WM_CAP_STOP = WM_CAP_START + 68
  43. CONST WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14
  44. CONST WM_CAP_GET_STATUS = WM_CAP_START + 54
  45. CONST WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
  46. CONST WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
  47. '------------------------------------------------------------------------------------------------------------------------------
  48. 'Window Pos Constants
  49. CONST SWP_ASYNCWINDOWPOS = &H4000
  50. CONST SWP_DEFERERASE = &H2000
  51. CONST SWP_DRAWFRAME = &H0020
  52. CONST SWP_FRAMECHANGED = &H0020
  53. CONST SWP_HIDEWINDOW = &H0080
  54. CONST SWP_NOACTIVATE = &H0010
  55. CONST SWP_NOCOPYBITS = &H0100
  56. CONST SWP_NOMOVE = &H0002
  57. CONST SWP_NOOWNERZORDER = &H0200
  58. CONST SWP_NOREDRAW = &H0008
  59. CONST SWP_NOREPOSITION = &H0200
  60. CONST SWP_NOSENDCHANGING = &H0400
  61. CONST SWP_NOSIZE = &H0001
  62. CONST SWP_NOZORDER = &H0004
  63. CONST SWP_SHOWWINDOW = &H0040
  64. '------------------------------------------------------------------------------------------------------------------------------
  65. TYPE CapDriverCaps
  66.     DeviceIndex AS _UNSIGNED INTEGER
  67.     HasOverlay AS _BYTE
  68.     HasDlgVideoSource AS _BYTE
  69.     HasDlgVideoFormat AS _BYTE
  70.     HasDlgVideoDisplay AS _BYTE
  71.     CaptureInitialized AS _BYTE
  72.     DriverSuppliesPalettes AS _BYTE
  73.     hVideoIn AS LONG
  74.     hVideoOut AS LONG
  75.     hVideoExtIn AS LONG
  76.     hVideoExtOut AS LONG
  77.  
  78. TYPE POINTAPI
  79.     x AS LONG
  80.     y AS LONG
  81.  
  82. TYPE CapStatus
  83.     ImageWidth AS _UNSIGNED INTEGER
  84.     ImageHeight AS _UNSIGNED INTEGER
  85.     LiveWindow AS _BYTE
  86.     OverlayWindow AS _BYTE
  87.     Scale AS _BYTE
  88.     Scroll AS POINTAPI
  89.     UsingDefaultPalette AS _BYTE
  90.     AudioHardware AS _BYTE
  91.     CapFileExists AS _BYTE
  92.     CurrentVideoFrame AS LONG
  93.     CurrentVideoFramesDropped AS LONG
  94.     CurrentWaveSamples AS LONG
  95.     CurrentTimeElapsedMS AS LONG
  96.     PalCurrent AS LONG
  97.     CapturingNow AS _BYTE
  98.     RETURN AS LONG
  99.     NumVideoAllocated AS _UNSIGNED INTEGER
  100.     NumAudioAllocated AS _UNSIGNED INTEGER
  101.  
  102.     FUNCTION CreateCaptureWindow& ALIAS capCreateCaptureWindowA (lpszWindowName AS STRING, BYVAL dwStyle AS _OFFSET, BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL nWidth AS INTEGER, BYVAL nHeight AS INTEGER, BYVAL hwndParent AS _INTEGER64, BYVAL nId AS INTEGER)
  103.     FUNCTION GetDriverDescription%% ALIAS capGetDriverDescriptionA (BYVAL wDriverIndex AS _UNSIGNED INTEGER, BYVAL lpszName AS _OFFSET, BYVAL cbName AS INTEGER, BYVAL lpszVer AS _OFFSET, BYVAL cbVer AS INTEGER)
  104.  
  105.     FUNCTION SendMessage& ALIAS SendMessageA (BYVAL hWnd AS LONG, BYVAL Msg AS _UNSIGNED INTEGER, BYVAL wParam AS LONG, BYVAL lParam AS _OFFSET)
  106.     FUNCTION SetWindowPos%% (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _UNSIGNED INTEGER)
  107.  
  108. DIM childWin AS _INTEGER64
  109.  
  110. DIM captureWinText AS STRING
  111. captureWinText = "My Capture Window" + CHR$(0)
  112. DIM childID AS _INTEGER64
  113. childWin = CreateCaptureWindow(captureWinText, WS_VISIBLE, 0, 0, 640, 480, _WINDOWHANDLE, childID)
  114. PRINT childWin
  115.  
  116. PRINT "Connecting Driver:", , SendMessage(childWin, WM_CAP_DRIVER_CONNECT, 0, 0)
  117. DIM DeviceName AS STRING * 80
  118. DIM DeviceVersion AS STRING * 80
  119.  
  120. 'FOR wIndex = 0 TO 10
  121. 'DeviceName = SPACE$(80)
  122. 'DeviceVersion = SPACE$(80)
  123. PRINT "Getting Driver Description:", GetDriverDescription(wIndex, _OFFSET(DeviceName), LEN(DeviceName), _OFFSET(DeviceVersion), LEN(DeviceVersion))
  124. PRINT DeviceName, DeviceVersion
  125. 'NEXT
  126.  
  127. DIM driverCaps AS CapDriverCaps
  128. driverCaps.DeviceIndex = 0
  129.  
  130.  
  131.  
  132.  
  133.  
  134. PRINT "Getting Driver Capability:", SendMessage(childWin, WM_CAP_DRIVER_GET_CAPS, LEN(driverCaps), _OFFSET(driverCaps))
  135.  
  136. DIM capstatus AS CapStatus
  137.  
  138.     PRINT "Setting Format:", SendMessage(childWin, WM_CAP_DLG_VIDEOFORMAT, 0, 0)
  139.     PRINT "Setting Preview Scale:", SendMessage(childWin, WM_CAP_SET_SCALE, -1, 0)
  140.     PRINT "Setting Preview Rate:", SendMessage(childWin, WM_CAP_SET_PREVIEWRATE, 66, 0)
  141.  
  142.     PRINT "Setting Preview:", , SendMessage(childWin, WM_CAP_SET_PREVIEW, -1, 0)
  143.     PRINT "Getting Status:", SendMessage(childWin, WM_CAP_GET_STATUS, LEN(capstatus), _OFFSET(capstatus))
  144.     'PRINT SetWindowPos(childWin, 0, 0, 0, capstatus.ImageWidth, capstatus.ImageHeight, SWP_NOZORDER OR SWP_NOMOVE)
  145.  
  146.  
  147. PRINT "Disconnecting Driver:", SendMessage(childWin, WM_CAP_DRIVER_DISCONNECT, 0, 0)
  148.  
  149.  
  150.  

  [ You are not allowed to view this attachment ]  
« Last Edit: October 02, 2020, 04:04:18 pm by Petr »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Webcams in QB64?!? More likely than you think!
« Reply #2 on: October 02, 2020, 06:39:25 pm »
Well, it looks like for this implementation, one needs to have one of the dialog boxes open to keep the preview refreshing. Until I figure out something different, here is a GIF I made from a desktop recording so you can see how it looks:

  [ You are not allowed to view this attachment ]  

And the current code:
Code: QB64: [Select]
  1. '$CONSOLE:ONLY
  2. '_DEST _CONSOLE
  3. 'Window Style Constants
  4. CONST WS_BORDER = &H00800000
  5. CONST WS_CAPTION = &H00C00000
  6. CONST WS_CHILD = &H40000000
  7. CONST WS_CHILDWINDOW = WS_CHILD
  8. CONST WS_CLIPCHILDREN = &H02000000
  9. CONST WS_CLIPSIBLINGS = &H04000000
  10. CONST WS_DISABLED = &H08000000
  11. CONST WS_DLGFRAME = &H00400000
  12. CONST WS_GROUP = &H00020000
  13. CONST WS_HSCROLL = &H00100000
  14. CONST WS_ICONIC = &H20000000
  15. CONST WS_MAXIMIZE = &H01000000
  16. CONST WS_MAXIMIZEBOX = &H00010000
  17. CONST WS_MINIMIZE = &H20000000
  18. CONST WS_MINIMIZEBOX = &H00020000
  19. CONST WS_OVERLAPPED = &H00000000
  20. CONST WS_POPUP = &H80000000
  21. CONST WS_SIZEBOX = &H00040000
  22. CONST WS_SYSMENU = &H00080000
  23. CONST WS_TABSTOP = &H00010000
  24. CONST WS_THICKFRAME = &H00040000
  25. CONST WS_TILED = &H00000000
  26. CONST WS_VISIBLE = &H10000000
  27. CONST WS_VSCROLL = &H00200000
  28. CONST WS_TILEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  29. CONST WS_POPUPWINDOW = WS_POPUP OR WS_BORDER OR WS_SYSMENU
  30. CONST WS_OVERLAPPEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  31. '------------------------------------------------------------------------------------------------------------------------------
  32. 'Capture Driver Constants
  33. CONST WM_CAP_START = &H0400
  34. CONST WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
  35. CONST WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
  36. CONST WM_CAP_EDIT_COPY = WM_CAP_START + 30
  37. CONST WM_CAP_GRAB_FRAME = WM_CAP_START + 60
  38. CONST WM_CAP_SET_SCALE = WM_CAP_START + 53
  39. CONST WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
  40. CONST WM_CAP_SET_PREVIEW = WM_CAP_START + 50
  41. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  42. CONST WM_CAP_STOP = WM_CAP_START + 68
  43. CONST WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14
  44. CONST WM_CAP_GET_STATUS = WM_CAP_START + 54
  45. CONST WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
  46. CONST WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
  47. CONST WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44
  48. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  49. '------------------------------------------------------------------------------------------------------------------------------
  50. 'Window Pos Constants
  51. CONST SWP_ASYNCWINDOWPOS = &H4000
  52. CONST SWP_DEFERERASE = &H2000
  53. CONST SWP_DRAWFRAME = &H0020
  54. CONST SWP_FRAMECHANGED = &H0020
  55. CONST SWP_HIDEWINDOW = &H0080
  56. CONST SWP_NOACTIVATE = &H0010
  57. CONST SWP_NOCOPYBITS = &H0100
  58. CONST SWP_NOMOVE = &H0002
  59. CONST SWP_NOOWNERZORDER = &H0200
  60. CONST SWP_NOREDRAW = &H0008
  61. CONST SWP_NOREPOSITION = &H0200
  62. CONST SWP_NOSENDCHANGING = &H0400
  63. CONST SWP_NOSIZE = &H0001
  64. CONST SWP_NOZORDER = &H0004
  65. CONST SWP_SHOWWINDOW = &H0040
  66. '------------------------------------------------------------------------------------------------------------------------------
  67. TYPE CapDriverCaps
  68.     DeviceIndex AS _UNSIGNED INTEGER
  69.     HasOverlay AS _BYTE
  70.     HasDlgVideoSource AS _BYTE
  71.     HasDlgVideoFormat AS _BYTE
  72.     HasDlgVideoDisplay AS _BYTE
  73.     CaptureInitialized AS _BYTE
  74.     DriverSuppliesPalettes AS _BYTE
  75.     hVideoIn AS LONG
  76.     hVideoOut AS LONG
  77.     hVideoExtIn AS LONG
  78.     hVideoExtOut AS LONG
  79.  
  80. TYPE POINTAPI
  81.     x AS LONG
  82.     y AS LONG
  83.  
  84. TYPE CapStatus
  85.     ImageWidth AS _UNSIGNED INTEGER
  86.     ImageHeight AS _UNSIGNED INTEGER
  87.     LiveWindow AS _BYTE
  88.     OverlayWindow AS _BYTE
  89.     Scale AS _BYTE
  90.     Scroll AS POINTAPI
  91.     UsingDefaultPalette AS _BYTE
  92.     AudioHardware AS _BYTE
  93.     CapFileExists AS _BYTE
  94.     CurrentVideoFrame AS LONG
  95.     CurrentVideoFramesDropped AS LONG
  96.     CurrentWaveSamples AS LONG
  97.     CurrentTimeElapsedMS AS LONG
  98.     PalCurrent AS LONG
  99.     CapturingNow AS _BYTE
  100.     RETURN AS LONG
  101.     NumVideoAllocated AS _UNSIGNED INTEGER
  102.     NumAudioAllocated AS _UNSIGNED INTEGER
  103.  
  104.     FUNCTION CreateCaptureWindow& ALIAS capCreateCaptureWindowA (lpszWindowName AS STRING, BYVAL dwStyle AS _OFFSET, BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL nWidth AS INTEGER, BYVAL nHeight AS INTEGER, BYVAL hwndParent AS _INTEGER64, BYVAL nId AS INTEGER)
  105.     FUNCTION GetDriverDescription%% ALIAS capGetDriverDescriptionA (BYVAL wDriverIndex AS _UNSIGNED INTEGER, BYVAL lpszName AS _OFFSET, BYVAL cbName AS INTEGER, BYVAL lpszVer AS _OFFSET, BYVAL cbVer AS INTEGER)
  106.  
  107.     FUNCTION SendMessage& ALIAS SendMessageA (BYVAL hWnd AS LONG, BYVAL Msg AS _UNSIGNED INTEGER, BYVAL wParam AS LONG, BYVAL lParam AS _OFFSET)
  108.     FUNCTION SetWindowPos%% (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _UNSIGNED INTEGER)
  109.  
  110. DIM childWin AS _INTEGER64
  111.  
  112. DIM captureWinText AS STRING
  113. captureWinText = "My Capture Window" + CHR$(0)
  114. DIM childID AS _INTEGER64
  115. childWin = CreateCaptureWindow(captureWinText, WS_CHILD OR WS_VISIBLE, 0, 0, 640, 480, _WINDOWHANDLE, childID)
  116.  
  117. a = SendMessage(childWin, WM_CAP_DRIVER_CONNECT, 0, 0)
  118. DIM DeviceName AS STRING
  119. DIM DeviceVersion AS STRING
  120.  
  121. DeviceName = SPACE$(80)
  122. DeviceVersion = SPACE$(80)
  123. a = GetDriverDescription(wIndex, _OFFSET(DeviceName), LEN(DeviceName), _OFFSET(DeviceVersion), LEN(DeviceVersion))
  124.  
  125. DIM driverCaps AS CapDriverCaps
  126. driverCaps.DeviceIndex = 0
  127.  
  128. a = SendMessage(childWin, WM_CAP_DRIVER_GET_CAPS, LEN(driverCaps), _OFFSET(driverCaps))
  129.  
  130. a = SendMessage(childWin, WM_CAP_DLG_VIDEOFORMAT, 0, 0)
  131.     a = SendMessage(childWin, WM_CAP_DLG_VIDEOSOURCE, 0, 0)
  132.     a = SendMessage(childWin, WM_CAP_SET_SCALE, -1, 0)
  133.     a = SendMessage(childWin, WM_CAP_SET_PREVIEWRATE, 16.7, 0)
  134.     a = SendMessage(childWin, WM_CAP_SET_PREVIEW, -1, 0)
  135.     _LIMIT 60
  136. PRINT "Disconnecting Driver:", SendMessage(childWin, WM_CAP_DRIVER_DISCONNECT, 0, 0)
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Webcams in QB64?!? More likely than you think!
« Reply #3 on: October 02, 2020, 07:40:34 pm »
My joy is immeasurable. Here is a link to a video I made with my code:




The current code:
Code: QB64: [Select]
  1. '$CONSOLE:ONLY
  2. '_DEST _CONSOLE
  3. 'Window Style Constants
  4. CONST WS_BORDER = &H00800000
  5. CONST WS_CAPTION = &H00C00000
  6. CONST WS_CHILD = &H40000000
  7. CONST WS_CHILDWINDOW = WS_CHILD
  8. CONST WS_CLIPCHILDREN = &H02000000
  9. CONST WS_CLIPSIBLINGS = &H04000000
  10. CONST WS_DISABLED = &H08000000
  11. CONST WS_DLGFRAME = &H00400000
  12. CONST WS_GROUP = &H00020000
  13. CONST WS_HSCROLL = &H00100000
  14. CONST WS_ICONIC = &H20000000
  15. CONST WS_MAXIMIZE = &H01000000
  16. CONST WS_MAXIMIZEBOX = &H00010000
  17. CONST WS_MINIMIZE = &H20000000
  18. CONST WS_MINIMIZEBOX = &H00020000
  19. CONST WS_OVERLAPPED = &H00000000
  20. CONST WS_POPUP = &H80000000
  21. CONST WS_SIZEBOX = &H00040000
  22. CONST WS_SYSMENU = &H00080000
  23. CONST WS_TABSTOP = &H00010000
  24. CONST WS_THICKFRAME = &H00040000
  25. CONST WS_TILED = &H00000000
  26. CONST WS_VISIBLE = &H10000000
  27. CONST WS_VSCROLL = &H00200000
  28. CONST WS_TILEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  29. CONST WS_POPUPWINDOW = WS_POPUP OR WS_BORDER OR WS_SYSMENU
  30. CONST WS_OVERLAPPEDWINDOW = WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
  31. '------------------------------------------------------------------------------------------------------------------------------
  32. 'Capture Driver Constants
  33. CONST WM_CAP_START = &H0400
  34. CONST WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
  35. CONST WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
  36. CONST WM_CAP_EDIT_COPY = WM_CAP_START + 30
  37. CONST WM_CAP_GRAB_FRAME = WM_CAP_START + 60
  38. CONST WM_CAP_SET_SCALE = WM_CAP_START + 53
  39. CONST WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
  40. CONST WM_CAP_SET_PREVIEW = WM_CAP_START + 50
  41. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  42. CONST WM_CAP_STOP = WM_CAP_START + 68
  43. CONST WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14
  44. CONST WM_CAP_GET_STATUS = WM_CAP_START + 54
  45. CONST WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
  46. CONST WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
  47. CONST WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44
  48. CONST WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
  49. CONST WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43
  50. CONST WM_CAP_SEQUENCE = WM_CAP_START + 62
  51. CONST WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
  52. CONST WM_CAP_GRAB_FRAME_NOSTOP = WM_CAP_START + 61
  53. CONST WM_CAP_FILE_SET_CAPTURE_FILE = WM_CAP_START + 20
  54. CONST WM_CAP_SINGLE_FRAME = WM_CAP_START + 70
  55. CONST WM_CAP_SET_AUDIOFORMAT = WM_CAP_START + 35
  56. '------------------------------------------------------------------------------------------------------------------------------
  57. 'Window Pos Constants
  58. CONST SWP_ASYNCWINDOWPOS = &H4000
  59. CONST SWP_DEFERERASE = &H2000
  60. CONST SWP_DRAWFRAME = &H0020
  61. CONST SWP_FRAMECHANGED = &H0020
  62. CONST SWP_HIDEWINDOW = &H0080
  63. CONST SWP_NOACTIVATE = &H0010
  64. CONST SWP_NOCOPYBITS = &H0100
  65. CONST SWP_NOMOVE = &H0002
  66. CONST SWP_NOOWNERZORDER = &H0200
  67. CONST SWP_NOREDRAW = &H0008
  68. CONST SWP_NOREPOSITION = &H0200
  69. CONST SWP_NOSENDCHANGING = &H0400
  70. CONST SWP_NOSIZE = &H0001
  71. CONST SWP_NOZORDER = &H0004
  72. CONST SWP_SHOWWINDOW = &H0040
  73. '------------------------------------------------------------------------------------------------------------------------------
  74. CONST WAVE_FORMAT_PCM = 1
  75. TYPE CapDriverCaps
  76.     DeviceIndex AS _UNSIGNED INTEGER
  77.     HasOverlay AS _BYTE
  78.     HasDlgVideoSource AS _BYTE
  79.     HasDlgVideoFormat AS _BYTE
  80.     HasDlgVideoDisplay AS _BYTE
  81.     CaptureInitialized AS _BYTE
  82.     DriverSuppliesPalettes AS _BYTE
  83.     hVideoIn AS LONG
  84.     hVideoOut AS LONG
  85.     hVideoExtIn AS LONG
  86.     hVideoExtOut AS LONG
  87.  
  88. TYPE POINTAPI
  89.     x AS LONG
  90.     y AS LONG
  91.  
  92. TYPE CapStatus
  93.     ImageWidth AS _UNSIGNED INTEGER
  94.     ImageHeight AS _UNSIGNED INTEGER
  95.     LiveWindow AS _BYTE
  96.     OverlayWindow AS _BYTE
  97.     Scale AS _BYTE
  98.     Scroll AS POINTAPI
  99.     UsingDefaultPalette AS _BYTE
  100.     AudioHardware AS _BYTE
  101.     CapFileExists AS _BYTE
  102.     CurrentVideoFrame AS LONG
  103.     CurrentVideoFramesDropped AS LONG
  104.     CurrentWaveSamples AS LONG
  105.     CurrentTimeElapsedMS AS LONG
  106.     PalCurrent AS LONG
  107.     CapturingNow AS _BYTE
  108.     RETURN AS LONG
  109.     NumVideoAllocated AS _UNSIGNED INTEGER
  110.     NumAudioAllocated AS _UNSIGNED INTEGER
  111.  
  112. TYPE WAVEFORMATEX
  113.     FormatTag AS INTEGER
  114.     Channels AS INTEGER
  115.     SamplesPerSec AS LONG
  116.     AvgBytesPerSec AS LONG
  117.     BlockAlign AS INTEGER
  118.     BitsPerSample AS INTEGER
  119.     cbSize AS INTEGER
  120.  
  121.  
  122.     FUNCTION CreateCaptureWindow& ALIAS capCreateCaptureWindowA (lpszWindowName AS STRING, BYVAL dwStyle AS _OFFSET, BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL nWidth AS INTEGER, BYVAL nHeight AS INTEGER, BYVAL hwndParent AS _INTEGER64, BYVAL nId AS INTEGER)
  123.     FUNCTION GetDriverDescription%% ALIAS capGetDriverDescriptionA (BYVAL wDriverIndex AS _UNSIGNED INTEGER, BYVAL lpszName AS _OFFSET, BYVAL cbName AS INTEGER, BYVAL lpszVer AS _OFFSET, BYVAL cbVer AS INTEGER)
  124.  
  125.     FUNCTION SendMessage& ALIAS SendMessageA (BYVAL hWnd AS LONG, BYVAL Msg AS _UNSIGNED INTEGER, BYVAL wParam AS LONG, BYVAL lParam AS _OFFSET)
  126.     FUNCTION SetWindowPos%% (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _UNSIGNED INTEGER)
  127.  
  128. DIM childWin AS _INTEGER64
  129.  
  130. DIM captureWinText AS STRING
  131. captureWinText = "Webcam API Test" + CHR$(0)
  132. DIM childID AS _INTEGER64
  133. childWin = CreateCaptureWindow(captureWinText, WS_VISIBLE, 0, 0, 640, 480, _WINDOWHANDLE, childID)
  134. _TITLE "Webcam API Test"
  135. PRINT childWin
  136.  
  137. a = SendMessage(childWin, WM_CAP_DRIVER_CONNECT, 0, 0)
  138. DIM DeviceName AS STRING * 80
  139. DIM DeviceVersion AS STRING * 80
  140.  
  141. 'FOR wIndex = 0 TO 10
  142. 'DeviceName = SPACE$(80)
  143. 'DeviceVersion = SPACE$(80)
  144. a = GetDriverDescription(wIndex, _OFFSET(DeviceName), LEN(DeviceName), _OFFSET(DeviceVersion), LEN(DeviceVersion))
  145. 'PRINT DeviceName, DeviceVersion
  146. 'NEXT
  147.  
  148. DIM driverCaps AS CapDriverCaps
  149. driverCaps.DeviceIndex = 0
  150.  
  151. a = SendMessage(childWin, WM_CAP_DRIVER_GET_CAPS, LEN(driverCaps), _OFFSET(driverCaps))
  152.  
  153. 'DIM capstatus AS CapStatus
  154.  
  155. 'a = SetWindowPos(childWin, 0, 0, 0, capstatus.ImageWidth, capstatus.ImageHeight, SWP_NOZORDER OR SWP_NOMOVE)
  156. DIM filename AS STRING
  157. filename = "Video.avi" + CHR$(0)
  158. DIM wave AS WAVEFORMATEX
  159. wave.FormatTag = WAVE_FORMAT_PCM
  160. wave.Channels = 2
  161. wave.SamplesPerSec = 44100
  162. wave.AvgBytesPerSec = 176400
  163. wave.BlockAlign = 4
  164. wave.BitsPerSample = 16
  165. wave.cbSize = 0
  166. a = SendMessage(childWin, WM_CAP_SET_SCALE, -1, 0)
  167. a = SendMessage(childWin, WM_CAP_SET_PREVIEWRATE, 16.7, 0)
  168. a = SendMessage(childWin, WM_CAP_SET_PREVIEW, -1, 0)
  169. a = SendMessage(childWin, WM_CAP_DLG_VIDEOFORMAT, 0, 0)
  170. a = SendMessage(childWin, WM_CAP_DLG_VIDEOSOURCE, 0, 0)
  171. a = SendMessage(childWin, WM_CAP_FILE_SET_CAPTURE_FILE, 0, _OFFSET(filename))
  172. a = SendMessage(childWin, WM_CAP_SET_AUDIOFORMAT, LEN(wave), _OFFSET(wave))
  173. a = SendMessage(childWin, WM_CAP_SEQUENCE, 0, 0)
  174.     a = SendMessage(childWin, WM_CAP_GRAB_FRAME_NOSTOP, 0, 0)
  175.     _LIMIT 60
  176. PRINT "Disconnecting Driver:", SendMessage(childWin, WM_CAP_DRIVER_DISCONNECT, 0, 0)
« Last Edit: October 02, 2020, 07:57:22 pm by SpriggsySpriggs »
Shuwatch!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #4 on: October 02, 2020, 07:49:43 pm »
I like Pilsner Urquell, that's about as far as my understanding goes, but the ap looks pretty cool.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #5 on: October 02, 2020, 11:01:37 pm »
What the HELL went wrong in test 2? Did you code that one in FreeBASIC? :D

So practically speaking, what could this be used for?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Webcams in QB64?!? More likely than you think!
« Reply #6 on: October 02, 2020, 11:09:10 pm »
@Pete Awesome things, obviously. If someone else wants to take some time with the code I just posted in my API collection then they could turn it into a camera application that takes photos or records videos. They could even mess with some compression values and make smaller files from it. My code is simple right now but someone else can run with it and make something great.
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #7 on: October 02, 2020, 11:25:42 pm »
I mean I guess I could envision a game, played over Skype, with the QB64 app including a webcam, so both players could see each other, on the game screen. That's all I got.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Webcams in QB64?!? More likely than you think!
« Reply #8 on: October 02, 2020, 11:35:54 pm »
@Pete Also, part of my endeavor is to show everyone that the WinAPI is easier than they think. I churned out this webcam program in one day. Took several days of research, yes, but still only one day of coding.
Shuwatch!

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #9 on: October 03, 2020, 03:39:12 am »
Well done mr Spriggs! Hats of to you sir! VERY COOL
« Last Edit: October 03, 2020, 03:40:31 am by Unseen Machine »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #10 on: October 03, 2020, 05:07:35 am »
Great Job!!!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Webcams in QB64?!? More likely than you think!
« Reply #11 on: October 03, 2020, 07:20:42 am »
OOOoo  this looks nice.

Next hat trick.  Make a zoom like interface with encryption end to end.  For two way video.  Got to get the audio working too.