From: Larry Serflaten on

"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote
> Yes, that looks better and will try that.

That was a quick patch job of the linked code:

> > Select Case uMsg
> > Case WM_RBUTTONDOWN, WM_RBUTTONUP
> > If uMsg = WM_RBUTTONDOWN Then
> > uMsg = WM_LBUTTONDOWN
> > Else
> > uMsg = WM_LBUTTONUP
> > End If
> > End Select

You don't need the Select Case if you test for specific messages:


> > If uMsg = WM_RBUTTONDOWN Then
> > uMsg = WM_LBUTTONDOWN
> > ElseIf uMsg = WM_RBUTTONUP Then
> > uMsg = WM_LBUTTONUP
> > End If



From: RB Smissaert on
Had a go, but not so sure now the simple mouse-down to the form with
SendMessage
isn't the better option. Will keep it in mind though, maybe for another job.
If I were to use subclassing then where in the code I posted last (last
reply to Mike Williams)
would I hook and unhook?

RBS


"Larry Serflaten" <serflaten(a)usinternet.com> wrote in message
news:OG1OxoLJIHA.5684(a)TK2MSFTNGP06.phx.gbl...
>
> "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote
>> Yes, that looks better and will try that.
>
> That was a quick patch job of the linked code:
>
>> > Select Case uMsg
>> > Case WM_RBUTTONDOWN, WM_RBUTTONUP
>> > If uMsg = WM_RBUTTONDOWN Then
>> > uMsg = WM_LBUTTONDOWN
>> > Else
>> > uMsg = WM_LBUTTONUP
>> > End If
>> > End Select
>
> You don't need the Select Case if you test for specific messages:
>
>
>> > If uMsg = WM_RBUTTONDOWN Then
>> > uMsg = WM_LBUTTONDOWN
>> > ElseIf uMsg = WM_RBUTTONUP Then
>> > uMsg = WM_LBUTTONUP
>> > End If
>
>
>

From: Mike Williams on
"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message
news:uSYtHwLJIHA.5468(a)TK2MSFTNGP05.phx.gbl...

> If I were to use subclassing then where in the code
> I posted last (last reply to Mike Williams) would I
> hook and unhook?

For some tasks I would use a permanent hook so that hooking is turned on
when my app starts and off when it ends, or perhaps on when a Form loads and
off when it unloads, depending on exactly what it is I am doing. But in this
case since the normal Windows pop up menu fires just before the MouseUp
event runs you could use a temporary hook, turning the hook on in the
TextBox MouseDown event and off again in its MouseUp event.

By the way, in the code I posted last night I sent the TextBox two messages
whereas I really only needed to send one message to get both items. I don't
normally mess about much with TextBoxes and I didn't think it through
properly. It would have been easier to do this:

Private Sub Text1_MouseDown(Button As Integer, _
Shift As Integer, x As Single, y As Single)
Dim myPoints As Long, retVal As Long
Dim charpos As Long, lineNumber As Long
Dim x2 As Long, y2 As Long
x2 = ScaleX(x, vbTwips, vbPixels)
y2 = ScaleY(y, vbTwips, vbPixels)
myPoints = y2 * &H10000 + x2
retVal = SendMessage(Text1.hwnd, _
EM_CHARFROMPOS, 0&, ByVal myPoints)
charpos = (retVal And &HFFFF0000) \ &H10000
lineNumber = retVal And &HFFFF&
Caption = charpos & " " & lineNumber
End Sub

Mike


From: RB Smissaert on
> I sent the TextBox two messages whereas I really only needed to send
> one message to get both items

Yes, had noticed that and had altered that.
I think for now I will avoid the subclassing.

RBS


"Mike Williams" <mikea(a)whiskyandCoke.com> wrote in message
news:OUeCZKPJIHA.748(a)TK2MSFTNGP04.phx.gbl...
> "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message
> news:uSYtHwLJIHA.5468(a)TK2MSFTNGP05.phx.gbl...
>
>> If I were to use subclassing then where in the code
>> I posted last (last reply to Mike Williams) would I
>> hook and unhook?
>
> For some tasks I would use a permanent hook so that hooking is turned on
> when my app starts and off when it ends, or perhaps on when a Form loads
> and off when it unloads, depending on exactly what it is I am doing. But
> in this case since the normal Windows pop up menu fires just before the
> MouseUp event runs you could use a temporary hook, turning the hook on in
> the TextBox MouseDown event and off again in its MouseUp event.
>
> By the way, in the code I posted last night I sent the TextBox two
> messages whereas I really only needed to send one message to get both
> items. I don't normally mess about much with TextBoxes and I didn't think
> it through properly. It would have been easier to do this:
>
> Private Sub Text1_MouseDown(Button As Integer, _
> Shift As Integer, x As Single, y As Single)
> Dim myPoints As Long, retVal As Long
> Dim charpos As Long, lineNumber As Long
> Dim x2 As Long, y2 As Long
> x2 = ScaleX(x, vbTwips, vbPixels)
> y2 = ScaleY(y, vbTwips, vbPixels)
> myPoints = y2 * &H10000 + x2
> retVal = SendMessage(Text1.hwnd, _
> EM_CHARFROMPOS, 0&, ByVal myPoints)
> charpos = (retVal And &HFFFF0000) \ &H10000
> lineNumber = retVal And &HFFFF&
> Caption = charpos & " " & lineNumber
> End Sub
>
> Mike
>
>

From: Mike Williams on
"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message
news:uSYtHwLJIHA.5468(a)TK2MSFTNGP05.phx.gbl...

> Had a go, but not so sure now the simple mouse-down
> to the form with SendMessage isn't the better option.

It probably is the better option in this specific case. No sense messing
about with subclassing unless you really need to (which of course is the
case for some tasks, but not for this one). By the way, you might like to
send a left button down message in the TextBox's DblClick event as well if
you also wish to suppress the same menu that would otherwise appear on a
double click of the right mouse button.

Mike