dzEventsMagic

dzt

Active Member
Licensed User
Did you ever miss a B4PPC control event? This is the answer.

This library allows you to add more (missed) events to B4PPC controls.

Based on excellent code of the ".NET Compact Framework Team" found here http://blogs.msdn.com/netcfteam/archive/2005/05/20/420551.aspx

Needs .NET 2.0 (don't forget MyApp.EXE.config file)

DLLs for desktop and device among with sample project (source and exe) are attached.

Windows Events list can be found here http://wiki.winehq.org/List_Of_Windows_Messages and here http://www.autohotkey.com/docs/misc/SendMessageList.htm

A useful windows spy application (Winspector) can be downloaded here http://www.windows-spy.com/

Sample code used to move a label on a form while pressing arrow keys
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Globals[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]App_Start[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Add dzEventsMagic object and name it dzem[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.New1([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Form1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], true)[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Hook WM_KEYDOWN message[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]256[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[SIZE=2][FONT=Courier New]  Form1.Show[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Form1_Close[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]256[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]dzem_MagicEvent[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Left Arrow[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]37 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]    label1.Text = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"LEFT"[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] label1.Left > [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]      label1.Left = label1.Left - [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Up Arrow[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]38 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]    label1.Text = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"UP"[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] label1.Top > [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]      label1.Top = label1.Top - [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Right Arrow[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]39 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]    label1.Text = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"RIGHT"[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] label1.left < Form1.Width - label1.Width [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]      label1.Left = label1.Left + [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Down Arrow[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]40 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]    label1.Text = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"DOWN"[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] label1.Top < Form1.Height - label1.Height [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]      label1.Top = label1.Top + [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT][/SIZE]
 

Attachments

  • dzEVentsMagic.zip
    60.6 KB · Views: 550

Cableguy

Expert
Licensed User
Longtime User
From what I could see, with this lib we can now raise an event upon a key stroke, correct?
 

dzt

Active Member
Licensed User
One more sample. A completely locked TextBox

B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000000]Globals[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000000]App_Start[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Add dzEventsMagic object and name it dzem[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Set by default ReturnHandled parameter to true[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'just not to let message to reach the Hooked control[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.New1([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"TextBox1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], true)[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Hook WM_KEYDOWN message[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]256[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_CHAR[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]258[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_PASTE[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]770[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_CLEAR[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]771[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_CUT[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]768[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
 
[SIZE=2][FONT=Courier New]  Form1.Show[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000000]Form1_Close[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]256[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]258[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]770[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]771[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]768[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#000000]dzem_MagicEvent[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]  dzem.ReturnHandled = True[/FONT][/SIZE]
 
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Allow Arrow Keys only[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'if dzem.msg = WM_KEYDOWN[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.msg = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]256[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]    'if the key is an arrow key[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]    If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]37 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]38 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]39 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]OR[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.wParam = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]40 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]      'Let the TextBox1 control to handle these keys[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]      dzem.ReturnHandled = False[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]   End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT][/SIZE]
[/COLOR][/SIZE][/FONT]
 

Attachments

  • test4.sbp
    1.4 KB · Views: 111
Last edited:

dzt

Active Member
Licensed User
Search using Google for every message of your interest (See message lists in my first post). Usually the first hit is an MSDN article describing the message.

Or/And download and install Winspector (see also my first post). Run it, and drag (while pressing CTRL key) the red circle with a cross to a control or window to see it's messsges. Detailed instructions here http://www.windows-spy.com/features/findwindow.shtml
 

dzt

Active Member
Licensed User
And... one more sample. A clickable label showing how to add mouse events to controls using dzEventsMagic.

B4X:
[SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2]Globals[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Label1Clicked[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2]App_Start[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Add dzEventsMagic object and name it dzem[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'Set by default ReturnHandled parameter to false[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#008000]  'so the message can be farther processed [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]  dzem.New1([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Label1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], false)[/SIZE][/FONT]
 
 
[FONT=Courier New][COLOR=#008000][SIZE=2]  'Hook WM_LBUTTONDOWN[/SIZE][/COLOR][/FONT]
[SIZE=2][FONT=Courier New]  dzem.Hook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]513[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New])[/FONT][/SIZE]
 
[SIZE=2][COLOR=#008000][FONT=Courier New]  'WM_LBUTTONUP[/FONT][/COLOR][/SIZE]
[SIZE=2][FONT=Courier New]  dzem.Hook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]514[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New])[/FONT][/SIZE]
 
[SIZE=2][FONT=Courier New]  Label1Clicked = false[/FONT][/SIZE]
 
 
[SIZE=2][FONT=Courier New]  Form1.Show[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[SIZE=2][COLOR=#0000ff][FONT=Courier New]S[/FONT][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][FONT=Courier New]ub [/FONT][/COLOR][/SIZE][SIZE=2][FONT=Courier New]Form1_Close[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]513[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New])[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]  dzem.UnHook([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]514[/COLOR][/SIZE][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[SIZE=2][COLOR=#0000ff][FONT=Courier New]Sub [/FONT][/COLOR][/SIZE][SIZE=2][FONT=Courier New]dzem_MagicEvent[/FONT][/SIZE]
[SIZE=2][COLOR=#008000][FONT=Courier New]  'WM_LBUTTONDOWN[/FONT][/COLOR][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] dzem.msg = [/SIZE][SIZE=2][COLOR=#800080]513 [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    label1.Color = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]128[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    label1.FontSize = [/FONT][/SIZE][SIZE=2][COLOR=#800080][FONT=Courier New]12[/FONT][/COLOR][/SIZE]
[SIZE=2][FONT=Courier New]    Label1Clicked = true[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
 
 
[SIZE=2][COLOR=#008000][FONT=Courier New]  'WM_LBUTTONUP[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=#008000][FONT=Courier New]  'This message fires for the Label only in PC[/FONT][/COLOR][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] dzem.msg = [/SIZE][SIZE=2][COLOR=#800080]514 [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    label1.Color = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]255[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    label1.FontSize = [/FONT][/SIZE][SIZE=2][COLOR=#800080][FONT=Courier New]9[/FONT][/COLOR][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[SIZE=2][COLOR=#008000][FONT=Courier New]'Tip. In PPC WM_LBUTTONUP is received by the form, not the label[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=#008000][FONT=Courier New]'So we catch Form MouseUp event to release label[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][FONT=Courier New]Sub [/FONT][/COLOR][/SIZE][SIZE=2][FONT=Courier New]Form1_MouseUp (x,y)[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] Label1Clicked [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    Label1Clicked = false[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]    label1.Color = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]255[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New]    label1.FontSize = [/FONT][/SIZE][SIZE=2][COLOR=#800080][FONT=Courier New]9[/FONT][/COLOR][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][/FONT][SIZE=2][COLOR=#0000ff][FONT=Courier New]If[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][FONT=Courier New]End Sub[/FONT][/COLOR][/SIZE]
 

Attachments

  • test4.sbp
    1.4 KB · Views: 85
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hello Dimitris
Perhaps you are already aware of it, the label move demo works only under the condition that no input controls (numerical UpDn, Textbox, Image button) are on that form. MagicEvent does not fire in presence of input controls.
Cheers
Robert
 

dzt

Active Member
Licensed User
Hello Robert (at the Country of the Rising Sun :)),

agraham is right.

But in that case, you can hook your controls instead of the form.

See attached sample with Button, NumUpDown and TextBox.
It works in the right way only on the device, because on desktop, Button and NumUpDown never receives a WM_KEYDOWN message for Arrow Keys (and Tab key). They are handled by the application itself.

Cheers
 

Attachments

  • test7.sbp
    2.3 KB · Views: 68

alfcen

Well-Known Member
Licensed User
Longtime User
Haisai Dimitris (in the land of great ancient history:))

Okinawa is officially part of Japan, but in heart of the native people these islands are still the Ryukyu Kingdom (without a king, of course). Haisai is the Okinawan work for "hello" or "Good Day" or "G'Day, mate" downunder.

Thanks so much for taking the trouble to enclose the source comprehensively explaining the workaround. I do respect your in-depth system knowledge which is magnitudes ahead of my rusty brain.

Out of this rust another question please: can your DLL add mouse_down and mouse_up events to an image button?

Cheers and arigato!




Hi agraham
thanks a lot for your thoughts!
 

dzt

Active Member
Licensed User
Haisai Robert,

I'm a little bit jealous about your place to live. I never visited these lands, but I'm thinking now, why not arrange a holiday trip for the next year?

alfcen said:
can your DLL add mouse_down and mouse_up events to an image button

Of course, sample follows.
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Globals
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]App_Start
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'Add an image to ImageButton1
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'For example someone's avatar :-)
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'ImageButton1.Image = "sisyou.jpg"
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'Add dzEventsMagic object and name it dzem
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'Set by default ReturnHandled parameter to false
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'so the message can be farther processed 
[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]  dzem.New1([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"ImageButton1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], false)

[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'Hook WM_LBUTTONDOWN
[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]513[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])

[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_LBUTTONUP
[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]  dzem.Hook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]514[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])

  Form1.Show
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Form1_Close
  dzem.UnHook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]513[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
  dzem.UnHook([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]514[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff] 
Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]dzem_MagicEvent
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]  'WM_LBUTTONDOWN
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] dzem.msg = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]513[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]    'Add visual effects for MouseDown
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]    'or do enything you want...[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]ImageButton1.FontSize = [/SIZE][SIZE=2][COLOR=#800080]12
[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][/FONT][SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000][FONT=Courier New]  'WM_LBUTTONUP[/FONT]
[/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] dzem.msg = [/SIZE][SIZE=2][COLOR=#800080]514[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][/FONT][SIZE=2][COLOR=#008000][FONT=Courier New]    'Add visual effects for MouseUp[/FONT]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][FONT=Courier New]    'or do enything you want...[/FONT]
[/COLOR][/SIZE][SIZE=2][FONT=Courier New]    ImageButton1.FontSize = [/FONT][/SIZE][SIZE=2][COLOR=#800080][FONT=Courier New]9[/FONT]
[/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT]
 

Attachments

  • test8.sbp
    1.2 KB · Views: 71

alfcen

Well-Known Member
Licensed User
Longtime User
Haisai Dimitris,
I hope you are in the mood for an apology. I just noticed your reply to my query regarding events for the image button.
And sample code included. Fabulous!
Your accommodation for your vacation on Okinawa is free :)
Cheers
Robert
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Dimitris,

Actually I needed 4 Image Buttons to accommodate telescope slewing into 4 directions. Thanks to your sample files I constructed a simple control pad with your dzEventsMagic.dll and believe that I gradually understand the concept. Your dll is magic, indeed!

The source code is attached for your reference and for the other forum friends.

In the real application, the telescope slews as long as you keep an image button pressed (mouse down). Upon release (mouse up) the scope aborts slewing.

The telescope is controlled wirelessly with Bluetooth. Any cable less at the scope is a great relief and one trap less :)

Thanks a lot!

Robert
 

Attachments

  • ImageButton.zip
    15.7 KB · Views: 51

Erel

B4X founder
Staff member
Licensed User
Longtime User
Too bad I don't have a telescope to test the complete project ;)
You should always try to avoid duplicating code.
Instead of the four emImgButt????_MagicEvent subs you could use AddEvent to handle the four events with a single sub:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButtLeft"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],MagicEvent,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButt_Magic"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButtRight"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],MagicEvent,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButt_Magic"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButtDown"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],MagicEvent,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButt_Magic"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]AddEvent[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButtUp"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],MagicEvent,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"emImgButt_Magic"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]Form1.Show[/FONT][/SIZE]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]emImgButt_Magic[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]name = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]StrToUpper[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]StrAt[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])) & [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]SubString[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]StrLength[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])-[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]If [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2].msg = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]513 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2]CenterText([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]" Slewing "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] & name)[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Else [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sender[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2].msg = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]514 [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2] CenterText([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]" Aborted "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] & name)[/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT][/SIZE]
 

alfcen

Well-Known Member
Licensed User
Longtime User
>You should always try to avoid duplicating code.
I do like that, Erel. In fact, the real app is made of 4200 lines of code, the exe is 1.2MB :)

Well, it' does not only control a scope in four directions. It transceives data to the hand control, spirals into an object, has a weather station, is network, GPS and Bluetooth enabled, has a polar alignment assistant, an observation site database with Google Earth KML support and a quite a large database of celestrial objects, incl. exoplanets, binary stars, asteroids and comets for which position and physical ephemerides are calculated. However, slew control works for Celestron NexStar GoTo scopes only. And now it comes... all written in YOUR Basic4PPC, and now also including dzt's magic events. That is really amazing! Thanks so much, Erel and Dimitris!

Next comes voice command control, text-to-speech, well, you must have dreams to continue looking at thousands of lines of code :)
 

dzt

Active Member
Licensed User
One more sample.

How to get X,Y coordinates of mouse down (or tap) and mouse up events on a control (for example Image control), using dzEventsMagic and BitWise library.

See attached code file.
 

Attachments

  • test9.sbp
    1.8 KB · Views: 82
Last edited:
Top