PDA

Click to See Complete Forum and Search --> : [RESOLVED] Button Simulation


pmd13
Jul 17th, 2009, 09:10 PM
I can't seem to find any solid information on this. I have this API that im building an app around that uses the camera, but it doesn't work unless i run the camera first. Instead of figuring out the camera API i was thinking of simulating a hardwarebutton being pressed that is associated with the camera. After it runs have another script close the camera.

i figured out what applicationkey is associated with it. I can disable it and what not.

OR i was also thinking which might be easier. A way to run camera.exe and close that after.

Much thanks!

petevick
Jul 18th, 2009, 01:15 AM
Hi,
just add a reference to the Microsoft.WindowsMobile.Forms assembly and then use the CameraCaptureDialog class

Dim ccd As New CameraCaptureDialog
ccd.Resolution = New Size(100, 200)
ccd.Mode = CameraCaptureMode.Still
ccd.ShowDialog()
If ccd.FileName <> String.Empty Then
PictureBox1.Image = New Bitmap(ccd.FileName)
End If


CameraCaptureDialog also supports video capture, which you can enable by setting the Mode property to CameraCaptureMode.VideoWithAudio

pmd13
Aug 5th, 2009, 02:39 AM
I can launch the camera fine. Thanks again. Now i need to get it to close itself after is opens up. How would i go about doing that? Where can i look for this type of stuff? im looking at the definitions and msdn but cant figure it out.


Thanks!

petevick
Aug 5th, 2009, 04:33 AM
Hi,
I don't think you can close it until the user cancels or takes a photo

Take a look here (http://www.code-magazine.com/article.aspx?quickid=0609051&page=3) for more help

pmd13
Aug 5th, 2009, 05:23 PM
I was looking around and I see people talking about closing programs by using FindWindow, which is "camera", then it finds the thread somehow and closes it. I can't seem to figure it out

petevick
Aug 6th, 2009, 12:50 AM
in that case, you need to use 'findwindow' API to find the camera window, and then 'sendmessage' to close the window.

Take a look at www.pinvoke.net for the API declarations.

I still don't know why you want to close it though - if the user takes a picture, they close it, and control returns to your program.

Findwindow API declaration is here (http://www.pinvoke.net/search.aspx?search=findwindow&namespace=[All]) and you need the one from coredll.

SendMessage is here (http://www.pinvoke.net/search.aspx?search=sendmessage&namespace=coredll) and you need to send it a WM_CLOSE

pmd13
Aug 10th, 2009, 09:32 PM
Thanks again! Those links you sent got me thinking to the right direction. The WM_Close couldn't work for some reason and using wm_destroy just crashed the app and it wouldnt load again properly.

I had to use Remote Spy to see the messages being sent to the camera when I closed it.

The reason why I had to automate the closing process was because I can't have my clients touching anything other than controls in a locked form. Plus its one less step they have to do anything if they have to restart the phone(its a kiosk phone).

Below is how I got it to work.


Declare Function FindWindow Lib "Coredll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Function SendMessage Lib "Coredll" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer

Private Sub LaunchCamera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LaunchCamera.Click

Dim ccd As New CameraCaptureDialog
CloserTimer.Enabled = True
ccd.ShowDialog()
End Sub
Private Sub CloseWindow()
Dim nWnd As Integer
Dim ceroIntPtr As New IntPtr(0)
Dim Wnd_name As String

Wnd_name = "Camera"
nWnd = FindWindow(Nothing, Wnd_name)
'show the info
If nWnd.Equals(ceroIntPtr) Then
MsgBox("App Not Running")
Else
SendMessage(nWnd, 111, 7000, 2080952128)
SendMessage(nWnd, 10, 0, 0)
SendMessage(nWnd, 47, 0, 806417032)
SendMessage(nWnd, 0, 0, 0)
SendMessage(nWnd, 0, 0, 0)
SendMessage(nWnd, 6, 0, 0)
SendMessage(nWnd, 47, 0, 806413656)
SendMessage(nWnd, 3, 0, 1703936)
SendMessage(nWnd, 5, 0, 19267824)
SendMessage(nWnd, 8, 0, 0)
SendMessage(nWnd, 281, 0, 3221225487)
SendMessage(nWnd, 282, 1, 0)
SendMessage(nWnd, 2, 0, 0)
End If
End Sub
Private Sub CloserTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloserTimer.Tick
CloserTimer.Enabled = False
CloseWindow()
End Sub