RE: Problems implementing the IMessageFilter to filter keypress events
- From: "Tobin" <Tobin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Oct 2005 07:56:04 -0700
After posting I realized that's a lot of code to wade through, below I've
gleaned out the applicable code segments:
Imports System.Data.SqlServerCe
Imports System.Data.SqlServerCe.SqlCeException
Imports System.Xml
Imports System.Reflection
Imports System.io
Imports System.text
Imports CMClient.Utility
Imports CMClient.DB.ClientConfig
Imports OpenNETCF.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Public Class frmMain
Inherits System.Windows.Forms.Form
Implements IMessageFilter
Friend WithEvents cmdSync As System.Windows.Forms.Button
Friend WithEvents cmdRec As System.Windows.Forms.Button
Friend WithEvents cmdRet As System.Windows.Forms.Button
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Implements IMessageFilter.PreFilterMessage
Dim WM_KEYUP As Integer = &H101
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode
If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
MsgBox("f1 key pressed")
Return True
End If
Return False
End Function 'PreFilterMessage
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Add any initialization after the InitializeComponent() call
OpenNETCF.Windows.Forms.ApplicationEx.AddMessageFilter(Me)
End Sub
End Class 'MyMainForm
"Tobin" wrote:
> I'm having problems getting the IMessageFilter implementation working. I
> want to intercept keypress events using the IMessageFilter. Below is the
> code I'm using for a form in VB.NET 2003. The IMessageFilter code is never
> hit when I run the applicaiton. Any suggestions are appreciated. The form
> load and the messagefilter function are the bottom two routines below.
>
> Thanks in advance to anyone who takes the time to look at this.
>
> Tobin
>
> VS2003
> .NET framework 1.1
> Windows CE 4.1
> OpenNETCF Smart Device Framework 1.4
>
>
> Imports System.Data.SqlServerCe
> Imports System.Data.SqlServerCe.SqlCeException
> Imports System.Xml
> Imports System.Reflection
> Imports System.io
> Imports System.text
> Imports CMClient.Utility
> Imports CMClient.DB.ClientConfig
> Imports OpenNETCF.Windows.Forms
> Imports Microsoft.WindowsCE.Forms
>
> Public Class frmMain
> Inherits System.Windows.Forms.Form
> Implements IMessageFilter
> Friend WithEvents cmdSync As System.Windows.Forms.Button
> Friend WithEvents cmdRec As System.Windows.Forms.Button
> Friend WithEvents cmdRet As System.Windows.Forms.Button
>
> #Region " Windows Form Designer generated code "
>
> Private Sub cmdSync_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdSync.Click
> Sync()
> End Sub
>
> Private Sub Sync()
> Dim Reader As SqlServerCe.SqlCeDataReader
> System.Windows.Forms.Cursor.Current =
> System.Windows.Forms.Cursors.WaitCursor
> Try
> SyncClient()
> System.Windows.Forms.Cursor.Current =
> System.Windows.Forms.Cursors.Default
> Catch err As SqlServerCe.SqlCeException
> ShowErrors(err)
> Finally
>
> End Try
> End Sub
>
> Public Function SyncClient()
>
> 'create the database if necassary
> createDB()
>
> 'download new title information & update invoice information
> SyncData()
>
> End Function
>
> Private Sub SyncData()
>
> Dim rdaoledbconnectstring As String = oConfig.ServerConnect
>
> ' Initialize the RDA object.
> Dim rda As SqlCeRemoteDataAccess = Nothing
>
> Try
>
> rda = New SqlCeRemoteDataAccess
> rda.InternetUrl = oConfig.SQLAgent
> rda.LocalConnectionString =
> "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=" & oConfig.DataSource
>
> rda.Pull("Title", "SELECT * FROM Title WHERE duns = " &
> oConfig.DUNS, rdaoledbconnectstring, _
> RdaTrackOption.TrackingOnWithIndexes)
>
> rda.Pull("Item", "SELECT * FROM Item WHERE duns = " &
> oConfig.DUNS & " AND store = " & oConfig.Store & " AND rec_date <
> '2000-01-01'", _
> rdaoledbconnectstring, RdaTrackOption.TrackingOnWithIndexes)
>
> 'this pulls nothing, but it sets up the returns table to push
> all data back
> rda.Pull("Returns", "SELECT * FROM returns WHERE ret_date >
> GETDATE() AND 1 = 2", rdaoledbconnectstring,
> RdaTrackOption.TrackingOnWithIndexes)
>
> MsgBox("Pull operation completed", MsgBoxStyle.Information,
> "Pull")
>
> Catch err As SqlCeException
> ShowErrors(err)
> Finally
> rda.Dispose()
> End Try
>
> End Sub
>
> Private Sub createDB()
>
> ' if database does not exist, create one
> If File.Exists(oConfig.DataSource) Then
> File.Delete(oConfig.DataSource)
>
> Dim sqlEngine As New SqlCeEngine("Data Source=" & oConfig.DataSource)
> sqlEngine.CreateDatabase()
>
> 'Dim Conn As New SqlCeConnection("Data Source=\My
> Documents\CMClient.sdf")
>
> 'Dim cmd As New SqlCeCommand("CREATE TABLE Title(pkid int Primary
> Key NOT NULL, duns int, store int, title nvarchar(50), " & _
> ' "issue int, BiPad int, UPC int, prod_category int, ean int,
> author nvarchar(50), publisher nvarchar(50), inactive bit)", Conn)
> 'Conn.Open()
> 'cmd.ExecuteNonQuery()
>
> ''cmd.CommandText = "CREATE TABLE Items(tote_id nvarchar(20), FKtote
> int, fktitle int, qty int, rec_qty int)"
> ''cmd.ExecuteNonQuery()
>
> ''cmd.CommandText = "CREATE TABLE Returns(fktitle int, qty int)"
> ''cmd.ExecuteNonQuery()
>
> 'Conn.Close()
>
> End Sub
>
> Private Sub cmdRec_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdRec.Click
> Receive()
> End Sub
>
> Private Sub Receive()
> ' Create an instance of the secondary form
> Dim MyForm As frmReceiving = New frmReceiving
>
> ' Bring the modal dialog to the front
> MyForm.ShowDialog()
>
> ' Upon return dispose the secondary form instance
> MyForm.Dispose()
> End Sub
>
> Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdExit.Click
> ExitCegMag()
> End Sub
>
> Private Sub ExitCegMag()
> Me.Close()
> End Sub
>
> Private Sub Returns()
> ' Create an instance of the secondary form
> Dim MyForm As frmRecMenu = New frmRecMenu
>
> ' Bring the modal dialog to the front
> MyForm.ShowDialog()
>
> ' Upon return dispose the secondary form instance
> MyForm.Dispose()
>
> End Sub
>
> Private Sub frmMain_KeyUp(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
>
> Select Case e.KeyCode
> Case Keys.F1 'data sync
> Sync()
> Case Keys.F2 'receiving
> Receive()
> Case Keys.F3 'returns
> Returns()
> Case Keys.F7 'exit
> ExitCegMag()
> End Select
>
> End Sub
>
> Protected Overrides Sub OnClosing(ByVal e As
> System.ComponentModel.CancelEventArgs)
> oConfig.Dispose()
> oConfig = Nothing
> Me.Dispose()
> End Sub
>
> Private Sub cmdRet_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdRet.Click
> Returns()
> End Sub
>
> Public Function PreFilterMessage(ByRef m As Message) As Boolean
> Implements IMessageFilter.PreFilterMessage
>
> Dim WM_KEYUP As Integer = &H101
> Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode
>
> If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
> MsgBox("f1 key pressed")
> Return True
> End If
> Return False
> End Function 'PreFilterMessage
>
> Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Add any initialization after the InitializeComponent() call
> OpenNETCF.Windows.Forms.ApplicationEx.AddMessageFilter(Me)
> End Sub
> End Class 'MyMainForm
>
>
>
>
>
>
>
.
- Follow-Ups:
- Re: Problems implementing the IMessageFilter to filter keypress events
- From: Paul G. Tobey [eMVP]
- Re: Problems implementing the IMessageFilter to filter keypress events
- References:
- Prev by Date: Re: Problem with using ConnectionManager API on Win CE (pocket pc)
- Next by Date: Re: Problems implementing the IMessageFilter to filter keypress events
- Previous by thread: Problems implementing the IMessageFilter to filter keypress events
- Next by thread: Re: Problems implementing the IMessageFilter to filter keypress events
- Index(es):