Page 3 of 4

Posted: Tue Jul 06, 2004 2:59 am
by Shannara
FYI: Following line does not work with PB 3.91: Line 155

Code: Select all

ImageGadget(#Image,window1X,window1Y, videoW, videoH,UseImage(71))
#image object is not initalized.

Posted: Tue Jul 06, 2004 12:08 pm
by Wolf
@Sparkie

Thanks for source, it's must work but is't good way.

I need to better way :?

Posted: Tue Jul 06, 2004 12:59 pm
by Wolf
Sparkie i find some link for you.

I think this links can help to we.



http://www.mcse.ms/message778768.html

http://www.vb-fun.de/cgi-bin/loadframe. ... 0273.shtml

http://forums.devarticles.com/archive/t-2221


http://www.dotnetsmart.com/SITEQMTDEQ23 ... Q6057.ASPX

http://dotnetjunkies.com/WebLog/princip ... 13855.aspx




I see in this links some good codes ( capDriverGetCaps or capGetStatus ,.... ).

Please look at this links its must help to you :wink:

Posted: Tue Jul 06, 2004 3:41 pm
by Sparkie
@Wolf

Thanks for the links. I'll take a look and see if I can find anything new. AFAIK, capDriverGetCaps and capGetStatus only work after the driver has been connected to a capture window. (Both messages require a handle to a capture window already connected to a driver.)

We need a way of getting the device status before connecting. I(we) must be overlooking something simple here. :?

but is this possible?

Posted: Sun Jul 11, 2004 6:18 am
by Jon
I want to know if I can access the web cam on another machine in my network??

Posted: Sun Jul 11, 2004 2:16 pm
by dmoc
Jon, check my recent link for one idea of how it may be done. I cannot remember if file mapping allows comms between machines but there are other methods and/or creating your own custom networked webcam server. Simplest method I can think of is to dump a pic to a shared folder.

viewtopic.php?t=11530

Posted: Tue Jul 13, 2004 12:21 pm
by Wolf
@Sparkie

Thanks for your info.

Sparkie i have now another problem, how can i detect user have webcam device installed or not ?

An way for check user use of webcam or not and if not exist show an message "Can't detect webcam device".

Thanks :wink:

Posted: Tue Jul 13, 2004 6:45 pm
by Sparkie
@Wolf:
Here's what I'm using to detect capture device. Is there a better way? Don't know ;) This is working for me in my project on WinXP with PB 3.91.

This may be a little messy as these are just sections plucked out of my code. Nothing runnable here, but it should be enough to give you a general idea of how do achieve your goal.

A procedure to handle capture device errors...

Code: Select all

Procedure MyWebcamErrorCallback(hwnd.l, nID.l, lpsz.l)
  If nID = #IDS_CAP_DRIVER_ERROR ; (= 418) there are more error messages available but for now i only use 418
    MessageRequester("Error", "Error connecting to capture device." + Chr(10)+Chr(13) + "Application will now close", #MB_ICONERROR)
    CloseWindow(#Window_0)
  Else
    MessageRequester("Error", "Unspecified capture device error (" + Str(nID) + ")", #MB_ICONERROR)
  EndIf
  
EndProcedure
Locate and ID all capture drivers...

Code: Select all

OpenLibrary(0, "C:\WINDOWS\system32\avicap32.dll") ; don't forget to CloseLibray(0) when finished

;- use this to enumerate and get driver info. I only have 1 VFW driver so I use driver 0
driverName$ = Space(256)
driverVer$ = Space(256)
*driverInfo = IsFunction(0, "capGetDriverDescriptionA")
webcam = #False
For driverID = 0 To 9
  If CallFunctionFast(*driverInfo, driverID, @driverName$, 256, @driverVer$, 256)
    ; you can select your driverID from here
    webcam = #True
    Debug driverID ; remove
    Debug driverName$ ; remove
    Debug driverVer$ ; remove
  EndIf
Next

If webcam
  ; A capture driver has been found. In a few lines down from
  ; here, we'll see if a capture device can be found (connected)
  useDriverID = 0 ; my one and only VFW driver
Else
  MyWebcamErrorCallback(0, #IDS_CAP_DRIVER_ERROR, 0)
EndIf
Set the capture device error callback procedure...

Code: Select all

;- define capture device error callback procedure
SendMessage_(handle_to_your_capture_window, #WM_CAP_SET_CALLBACK_ERRORA, 0, @MyWebcamErrorCallback())
Now we'll attempt to connect to a device. If it fails, it automatically goes to the MyWebcamErrorCallback(), otherwise you're goood to go :) ...

Code: Select all

If SendMessage_(handle_to_your_capture_window, #WM_CAP_DRIVER_CONNECT, useDriverID, 0)

Posted: Wed Jul 14, 2004 11:28 pm
by Wolf
Thanks Sparkie it's good way and work perfect for me :P

Thanks again.


Best regards

Icamplay

Posted: Thu Jul 15, 2004 6:20 pm
by chio
Guys contact www.icamplay.com and get his library. I was happily surprised of everything that it can do. Specially ease your code.

Be well,

Posted: Mon Jul 26, 2004 11:52 pm
by Wolf
@Sparkie

I when use your code for close "Video Source" window it not work.

I don't know why but it's possible i wrong join its to main window.

But when i check it see when we connect to webcam device program will be stop and then show "Video Source" window for it i can't do some code after or before this line. program stoped until we close that window .

What's problem ?

Best regards.

Posted: Tue Jul 27, 2004 12:45 am
by Sparkie
I'm not sure why the Video Source dialog is showing up for you Wolf. I have no problems here so if you'd like to post some of your code I'll be happy to take a look at it for you. :)

Posted: Tue Jul 27, 2004 1:00 pm
by Wolf
Sparkie Video Source window not show up for me but when my webcam is in use and i want use webcam device show up that window.

Here is my code:

Code: Select all


#WM_CAP_START = #WM_USER 
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10 
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11 
#WM_CAP_FILE_SAVEDIBA = #WM_CAP_START + 25 
#WM_CAP_GRAB_FRAME = #WM_CAP_START + 60 
#WM_CAP_STOP = #WM_CAP_START + 68 

Global hWndC 


Procedure SnapShot() 
  If OpenWindow(0,0,0,0,0,#PB_Window_SystemMenu,"test")
    
    If OpenLibrary(0, "avicap32.dll") 
      *capAddress = IsFunction(0, "capCreateCaptureWindowA") 
      hWndC = CallFunctionFast(*capAddress, "", #WS_CHILD, 10, 10, 320, 240, WindowID(0),1) 
      SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_GRAB_FRAME, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_FILE_SAVEDIBA, 0, "test.bmp") 
      SendMessage_(hWndC, #WM_CAP_STOP, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0) 
      DestroyWindow_(hWndC) 
      CloseLibrary(0) 
    EndIf 

  EndIf 
  
EndProcedure 

  
SnapShot()

If webcam is busy program stop on the this line:

SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)

Until we close Video Source window.

I create and use dll function for close this window but if use callfunction before this line program before run this line run that function and stop until end that function. if use it after this line program stop until we close that window and then run next lines.

Now with your error callback or way can we close this window when webcam is busy ?


Thanks :D

Posted: Tue Jul 27, 2004 4:01 pm
by Sparkie
Click here to see my previous post about the Video Source dialog. I know it's not exactly what you are looking for but it's all I have at this time. :cry:

If I find a better way, I come back and let you know. :)

Posted: Tue Jul 27, 2004 11:57 pm
by Wolf
I before this test it but don't work for me. if it must work maybe i wrong add that lines to my code.

I now add it again please check it's true ?

Code: Select all

#WM_CAP_START = #WM_USER 
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10 
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11 
#WM_CAP_FILE_SAVEDIBA = #WM_CAP_START + 25 
#WM_CAP_GRAB_FRAME = #WM_CAP_START + 60 
#WM_CAP_STOP = #WM_CAP_START + 68 
#WM_CAP_SET_CALLBACK_ERRORA = #WM_CAP_START + 2 ; define your callback constant 
#IDS_CAP_DRIVER_ERROR = 418  ; Driver specific error message 


Global hWndC 

Procedure myWindowCallback(hwnd, msg, wParam, lParam) 
  Shared dlgClosed 
  result = #PB_ProcessPureBasicEvents 
  
  ; handle video source dialog (here we close it by sending Escape key) 
  ; kind of messy right now but it seems to work 
  
  If hwnd = WindowID(0) And msg = #WM_KILLFOCUS And driverConnected = #False 
    hDlg = FindWindowEx_(0, 0, "#32770", "Video Source") ; get the handle to the dialog 
  EndIf 
  
  If hDlg <> 0 And driverConnected = #False 
    If dlgClosed = #False 
      dlgClosed = #True ; this ensures we send Escape key one time only 
      keybd_event_(#VK_ESCAPE, 0, 0, 0) 
      keybd_event_(#VK_ESCAPE, 0, #KEYEVENTF_KEYUP, 0) 
    EndIf 
  EndIf 
  
  ProcedureReturn result 
EndProcedure


Procedure MyCapErrorCallback(hwnd.l, nId.l, lpsz.l) 
  If nId = #IDS_CAP_DRIVER_ERROR 
    MessageRequester("Error", "Error connecting to capture device." + Chr(10)+Chr(13) + "Application will now close", #MB_ICONERROR) 
    CloseWindow(0) 
  Else 
    MessageRequester("Error", "Unspecified capture device error (" + Str(nId) + ")", #MB_ICONERROR) 
  EndIf 
EndProcedure



Procedure SnapShot() 
  If OpenWindow(0,0,0,0,0,#PB_Window_SystemMenu,"test") 
    
    If OpenLibrary(0, "avicap32.dll") 
      *capAddress = IsFunction(0, "capCreateCaptureWindowA") 
      hWndC = CallFunctionFast(*capAddress, "", #WS_CHILD, 10, 10, 320, 240, WindowID(0),1) 
      SendMessage_(hWndC, #WM_CAP_SET_CALLBACK_ERRORA, 0, @MyCapErrorCallback())   
      SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_GRAB_FRAME, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_FILE_SAVEDIBA, 0, "test.bmp") 
      SendMessage_(hWndC, #WM_CAP_STOP, 0, 0) 
      SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0) 
      DestroyWindow_(hWndC) 
      CloseLibrary(0) 
    EndIf 
    
  EndIf 
  
EndProcedure 

  
SnapShot() 

When i run this code not close video source window for me if webcam is in busy.

What's problem?