Get active window on Windows Mobile 6.5

IT-Factory
IT-Factory used Ask the Experts™
on
I've created a application to scan barcodes on a Datalogic Elf Mobile Scanner.
Using vb.net 2008 pro

When I scan a barcode allways the same function is called. From that function I want to know which form is active or also good is to know which input control is active at the time of scanning.

The application has two input forms where they scan from, both forms are possibly opened but only one is active.

Depending on which is active I can do some logic on it.
e.g.
if form A is active put scanned barcode string into form1.txtinputbox1.text
if form B is active put scanned barcode string into form2.txtinputbox1.text
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
How do you activate the scanning of barcode?

Author

Commented:
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            hDcd = New DecodeHandle(DecodeDeviceCap.Exists Or DecodeDeviceCap.Barcode)
        Catch ex As Exception
            MessageBox.Show("Uitzondering opgetreden bij het laden van de Barcode scanner App Elf2RentFactory!", "Decorder error")
        End Try

        Dim reqType As DecodeRequest = CType(1, DecodeRequest) Or DecodeRequest.PostRecurring

        reqID = hDcd.PostRequestMsg(reqType, wndMsg, System.Convert.ToUInt32(Constants.WM_SCANNED))
end sub

    Public Sub SetDcdText(ByVal msgReqID As Integer)
        Dim cID As CodeId = CodeId.NoData
        Dim dcdData As String = String.Empty


        Try
            dcdData = Strings.Replace(hDcd.ReadString(msgReqID, cID), vbCr, "")
        Catch ex As Exception
            MessageBox.Show("Fout bij lezen Barcode")
            Exit Sub
        End Try

        Me.txtCodeId.Text = cID.ToString()
        myVerwerkScan(dcdData) 'this is the function called to do something with the scanned barcode
    End Sub

    Public Sub New()
        MyBase.New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        wndMsg = New WndMessageWindow(Me)
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If Not (hDcd Is Nothing) Then
            hDcd.CancelRequest(reqID)
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private Sub bttnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnScan.Click
         'manually activate barcode scan
          hDcd.SoftTrigger(DecodeInputType.Barcode, 5000)
    End Sub

    Private Sub txtDcdData_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDcdData.Validating
         
          myVerwerkScan(Me.txtDcdData.Text)
    End Sub

Open in new window

Most Valuable Expert 2012
Top Expert 2014

Commented:
>hDcd.SoftTrigger(DecodeInputType.Barcode, 5000)

Is the above being used to do the scanning? Why not return a string from the function and then

txtID.Text = hDcd.SoftTrigger(DecodeInputType.Barcode, 5000)
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Author

Commented:
Don't bother about getting the string, that works but I need to know which form is active to put the scanned string in the correct inputbox.

When a scan is performed first sub executed is:
    Protected Overrides Sub WndProc(ByRef msg As Message)
        Select Case msg.Msg
            Case Constants.WM_SCANNED
                Me.dlgParent.SetDcdText(msg.LParam.ToInt32())
        End Select
    End Sub

Open in new window


this invokes:
    Public Sub SetDcdText(ByVal msgReqID As Integer)
        Dim cID As CodeId = CodeId.NoData
        Dim dcdData As String = String.Empty


        Try
            dcdData = Strings.Replace(hDcd.ReadString(msgReqID, cID), vbCr, "")
        Catch ex As Exception
            MessageBox.Show("Fout bij lezen Barcode")
            Exit Sub
        End Try

        Me.txtCodeId.Text = cID.ToString()
        myVerwerkScan(dcdData)
    End Sub

Open in new window


within the sub myVerwerkScan(dcdData) I want to know where the focus is
found possible solution:
on activated event of each form I keep track of the currformname  and use that var as trigger.

    Private Sub Schade_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        Flags.currForm = Me.Name
        Form1.myGetListFoto()
    End Sub

Open in new window


detection:
    Public Sub SetDcdText(ByVal msgReqID As Integer)
        Dim cID As CodeId = CodeId.NoData
        Dim dcdData As String = String.Empty


        Try
            dcdData = Strings.Replace(hDcd.ReadString(msgReqID, cID), vbCr, "")
        Catch ex As Exception
            MessageBox.Show("Fout bij lezen Barcode")
            Exit Sub
        End Try

        Me.txtCodeId.Text = cID.ToString()

        If Flags.currForm = "Form1" Then
            myVerwerkScan(dcdData)
        Else
            If Flags.currForm = "Schade" Then
                myVerwerkFoto(dcdData)
            End If
        End If
    End Sub

Open in new window

Author

Commented:
this works for me

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial