dzEventsMagic example
Previous  

This is an example application using the dzEventMagic library that may be cut and pasted. It traps key messages and allows a label to be moved around a form with the arrow keys.

It requires a form named "Form1 to be created in the Form Designer and a Label control added. Place the label in the middle of the form.

It also requires a dzEventsMagic object named dzem to be created before running it.

Apologies for the small font. Helpmaker, used to create this helpfile, does strange things when changing and resizing fonts including removing colour. I thought it best to retain the familiar colour coding and tolerate the smaller font.

Sub Globals
      
End Sub

Sub App_Start
      'Add dzEventsMagic object and name it dzem
      dzem.New1("Form1", true)
      
      'Hook WM_KEYDOWN message
      dzem.Hook(256)
      
      Form1.Show
End Sub


Sub Form1_Close
      dzem.UnHook(256)
End Sub

Sub dzem_MagicEvent
      
      'Left Arrow
      If dzem.wParam = 37 Then
            label1.Text = "LEFT"
            If label1.Left > 0 Then
                  label1.Left = label1.Left - 1
            End If
      End If
      
      'Up Arrow
      If dzem.wParam = 38 Then
            label1.Text = "UP"
            If label1.Top > 0 Then
                  label1.Top = label1.Top - 1
            End If
      End If
      
      'Right Arrow
      If dzem.wParam = 39 Then
            label1.Text = "RIGHT"
            If label1.left < Form1.Width - label1.Width  Then
                  label1.Left = label1.Left + 1
            End If
      End If
      
      'Down Arrow
      If dzem.wParam = 40 Then
            label1.Text = "DOWN"
            If label1.Top < Form1.Height- label1.Height Then
                  label1.Top = label1.Top + 1
            End If
      End If
End Sub