WindowMessage library

agraham

Expert
Licensed User
Longtime User
Since dzt wrote the dzEventsMagic library and I (sort of) documented it Basic4ppc has moved on. As dzt seems to have vanished from the forum I decided that I would create a similar, but enhanced, internally simplified and mergeable, library to replace it.

So for those few of us who might want to intercept and send Window Messages here is library, source for merging, help and demo application.
 

Attachments

  • WindowMessage1.0.zip
    21.7 KB · Views: 218

Zenerdiode

Active Member
Licensed User
This is great, I've been wanting something like this for a while - but I think I ask too much anyway.

:sign0013: but can I most humbly say the help file does not work for me? I'm using XP SP2. I'm getting "The page cannot be displayed" messages.
 

Zenerdiode

Active Member
Licensed User
I'm sorry but I had completely disregarded that because I mistakingly thought it affected Windows Vista and above only. It was in Properties and once unblocked it never asks again. Thank You.
 

berndgoedecke

Active Member
Licensed User
Longtime User
WM_VSROLL and WM_HSCROLL for MDI Client

Hello Andrew,
in my curent Desktop-Project I use dzEvent_Magic to get x- and y- scroll position from the scrollbars, of an MDI Client, which is set to Autoscroll like this:

#Region BuildFormEx3
AddForm("Form3", "Report")
FormEx3.New2("Form3","Report",600,600)
AddImage("Form3", "ImageF", 580, 580, 20, 20)
FormEx3.AddControl("ImageF")
AddImage("Form3", "ImageB", 580, 560, 20, 20)
FormEx3.AddControl("ImageB")
AddImage("Form3", "ImageZF", 580, 540, 20, 20)
FormEx3.AddControl("ImageZF")
AddImage("Form3", "ImageZB", 580, 520, 20, 20)
FormEx3.AddControl("ImageZB")
AddImage("Form3", "VLinImage", 15, 0, 15, 15)
FormEx3.AddControl("VLinImage")
AddImage("Form3", "HLinImage", 0, 15, 15, 15)
FormEx3.AddControl("HLinImage")
FormEx3.StartPosition = 0
FormEx3.WindowState = 0
FormEx3.ImageLayout = 0
frm3obj.FromControl(FormEx3.ControlRef)
frm3obj.SetProperty("AutoScroll", True)
dzem.New1(FormEx3.ControlRef, False)
dzem.Hook(276) 'WM_HSCROLL
dzem.Hook(277) 'WM_VSCROLL

hscrollobj.value = frm3obj.GetProperty("HorizontalScroll") ' returns an HScrollProperties type
hscrollobj.SetProperty("LargeChange", 100)
vscrollobj.value = frm3obj.GetProperty("VerticalScroll") ' returns an VScrollProperties type
vscrollobj.SetProperty("LargeChange", 100)
#End Region

The events are catched by this Sub(It's from an example in the Forum I didn't fin again):
Sub dzem_MagicEvent ' notice we seem to get two events for every scoll action!
msg1 = dzem.msg
Select msg1
Case 276
If Htoggle Then
ScrX = hscrollobj.GetProperty("Value")
IDebug.Text = FormEx3.ClientAreaHeight 'ScrXMax -
IScrolX.Text = ScrX
VLinImage.Left = (ScrX/(FormEx3.ClientAreaWidth-15))
VLinImage.BringToFront
End If
Htoggle = Not(Htoggle)
Case 277
If Vtoggle Then
ScrY = vscrollobj.GetProperty("Value")
IScrolY.Text = ScrY
HLinImage.Top = (ScrY/(FormEx3.ClientAreaHeight-15))-1
HLinImage.BringToFront
End If
Vtoggle = Not(Vtoggle)
End Select
End Sub

Is it possible to realize it with WindowsMessageDesktop.dll too?
I put the whole Project to this post too. It's buggie but it has been compieled(Desktop)
To see the window you have to click the Menue "Report", "Neu"
It would be verry nice, if it is possible, because the dzt dll is not mergeable.

Best Regards

berndgoedecke
 

agraham

Expert
Licensed User
Longtime User
It would be verry nice, if it is possible, because the dzt dll is not mergeable.
That's the main reason I wrote this, so it could replace dzMagicEvents and be mergeable.
B4X:
[COLOR="blue"]dzem.New1(FormEx3.ControlRef, False)[/COLOR]
becomes
[COLOR="blue"]WinMSg.New1(FormEx3.ControlRef)
WinMsg.Start[/COLOR][COLOR="SeaGreen"] ' might be better to do this after setting the traps[/COLOR]

[COLOR="Blue"]dzem.Hook(276)[/COLOR] [COLOR="seagreen"]'WM_HSCROLL[/COLOR]
becomes
[COLOR="blue"]WinMsg.Trap(276)[/COLOR]

[COLOR="blue"]dzem.Hook(277)[/COLOR][COLOR="SeaGreen"] 'WM_VSCROLL[/COLOR]
becomes
[COLOR="blue"]WinMsg.Trap(277)[/COLOR]

[COLOR="blue"]Sub dzem_MagicEvent[/COLOR]
becomes
[COLOR="blue"]Sub WinMsg_TrapEvent[/COLOR]

[COLOR="Blue"]msg1 = dzem.msg[/COLOR]
becomes
[COLOR="blue"]msg1 = WinMsg.wMsg[/COLOR]

You must have a Form close event but you don't need to unhook each message
[COLOR="Blue"]Sub FormEx3_Close
    WinMsg.Stop
End Sub[/COLOR]
 

berndgoedecke

Active Member
Licensed User
Longtime User
Event does not fire.

Hello Agraham,
I've tried it in the way you have proposed, but the trap event wouldn't work.
:sign0085::sign0085:

Best regards
berndgoedecke
 

berndgoedecke

Active Member
Licensed User
Longtime User
Oh, Sorry. The wrong version

In the meantime a played around with the BigScreenDoor example from the Forum and there it computes, but I don't know why it do not work on the FormEx.

:sign0013:
 

agraham

Expert
Licensed User
Longtime User
I am afraid that your program is too big for me to see what is going on as there is too much code that I don't understand so I can't tell what should be happening.

However if you trap all the messages

WinMsg.New1(FormEx3.ControlRef)
WinMsg.TrapAll

and set a breakpoint

Sub WinMsg_TrapEvent
'msg1 = dzem.msg
msg1 = WinMsg.wMsg <-BREAKPOINT HERE

you will see that it does work so I don't know why you are not getting scroll messages.
 

berndgoedecke

Active Member
Licensed User
Longtime User
It was the wrong place

Hello Agraham,
i found it. If WindowMessage is added when FormEx is Shown, the WM_Hscroll
and WM_VScroll event fires.
Public Sub Form2Start
If Main.RINIT = False Then
Form2Init
End If
FormEx3.MaximumHeight = Min(IBY, Disp.Height-5)
FormEx3.MaximumWidth = Min(IBX+50, Disp.Width)
PMode = "RepEdit"
+#Region Lineal
FormEx2.Show
FormEx3.Show
FormEx3.Top = 0
FormEx3.Left = 0
FormEx3.Width = Main.FormEx1.ClientAreaWidth - (FormEx2.Width+10) 'PicW
FormEx3.Height = Main.FormEx1.ClientAreaHeight-5 'PicH
WinMSg.New1(FormEx3.ControlRef)
WinMsg.Trap(WM_HSCROLL)
WinMsg.Trap(WM_VSCROLL)
WinMsg.Start

FormEx3.Refresh
ImageB.Visible = True
ImageB.BringToFront
RBLine_Click
End Sub

:sign0060:

Big thanks for your help and interest.
Best Regards
berndgoedecke
 

agraham

Expert
Licensed User
Longtime User
If WindowMessage is added when FormEx is Shown, the WM_Hscroll and WM_VScroll event fires.
That makes sense! WindowMessage.New1 needs the window handle of the control it is given as messages for the control are sent to that window handle. If the control is not yet shown then it doesn't yet have a window handle so WindowMessage doesn't know which messages are for the control when it is eventually shown.

Looking at this for you I have found an architectural weakness in WindowMessage when several instances are used in one project. I probably need a bit of internal redesign and a new version.

EDIT: After further analysis it's actually only a problem if two instances try to trap on the same control so in practice it's probably OK.
 
Last edited:

berndgoedecke

Active Member
Licensed User
Longtime User
Another Question about WindowMessage.dll

Hello Agraham,
in the WindowMessage.dll I found Methods to Post an Send commands.
They are used with lparam as Int32 and String.
But what is about EM_GETSCROLLPOS = (WM_USER + 221) and EM_SETSCROLLPOS = (WM_USER + 222) ?
lparam is a point. I tried it with Dim Type (X,Y) Point and ScrX1 = WinMsg.SendMessageInt32(W3Hnd, EM_GETSCROLLPOS, 0, Point.X)

Without success.
Is it possible to set and get the scroll-position with WinMsg, without using DoorEx.objects?
Best Regards

berndgoedecke
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…