Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application not working properly when minimized to tray

Status
Not open for further replies.

chipig

Technical User
Nov 8, 2007
205
CA
I'm doing an application that minimizes to the system tray on closing or minimizing.For some reason the application do not respond to keyboard event when it's minimized or closed to the system tray.It's working fine as long as the main window is visible.


Basically it's a VB application connected to a microcontroller via USB.When I turn a rotary encoder it turns the volume up.

Here is part of my code:

Code:
 Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Const KEYEVENTF_KEYUP As Long = &H2


Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        ' The user did not click the context menu's Exit command Shrink to the tray
        e.Cancel = True
        Me.Hide()
        Me.ShowInTaskbar = False
        ContextMenuStrip1.Enabled = True
        NotifyIcon1.Visible = True

    End Sub

    '*****************************************************************
    ' on read event...
    '*****************************************************************
    Public Sub OnRead(ByVal pHandle As Integer)
        ' first byte is the report ID, e.g. BufferIn(0)
        ' the other bytes are the data from the microcontroller...
        ' read the data (don't forget, pass the whole array)...

        If hidRead(pHandle, BufferIn(0)) Then

            USB_Receive_Box.Text = BufferIn(2)

            'Volume up
            Try

                If BufferIn(2) = 45 Then
                    timer1.Enabled = False 
                    Call keybd_event(Keys.VolumeUp, 0, 0, 0)
                    timer1.Enabled = True  'repart le timer
                End If
            Catch ex As Exception

            End Try


            Try
                'Volume down
                If BufferIn(2) = 46 Then
                    timer1.Enabled = False 
                    Call keybd_event(Keys.VolumeDown, 0, 0, 0)
                    timer1.Enabled = True   'repart le timer
                End If
            Catch ex As Exception

            End Try

        End If

    End Sub
 

Looks like VB.NET to me - you may want to ask in another Forum (for VB.NET)

Have fun.

---- Andy
 
It's visual basic 2010 express.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top