Results 1 to 7 of 7

Thread: [RESOLVED] Button Simulation

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Resolved [RESOLVED] Button Simulation

    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!

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Button Simulation

    Hi,
    just add a reference to the Microsoft.WindowsMobile.Forms assembly and then use the CameraCaptureDialog class

    Code:
    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
    Code:
    CameraCaptureMode.VideoWithAudio
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Button Simulation

    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!

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Button Simulation

    Hi,
    I don't think you can close it until the user cancels or takes a photo

    Take a look here for more help
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Button Simulation

    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

  6. #6
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Button Simulation

    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 and you need the one from coredll.

    SendMessage is here and you need to send it a WM_CLOSE
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Button Simulation

    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.

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width