Avatar of IT-Factory
IT-FactoryFlag for Belgium

asked on 

Get active window on Windows Mobile 6.5

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
Smartphone ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
IT-Factory
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

How do you activate the scanning of barcode?
Avatar of IT-Factory
IT-Factory
Flag of Belgium image

ASKER

 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

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

>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)
Avatar of IT-Factory
IT-Factory
Flag of Belgium image

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of IT-Factory
IT-Factory
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of IT-Factory
IT-Factory
Flag of Belgium image

ASKER

this works for me
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo