[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Why doesn't this work (sendmessage

Robert

8/29/2010 3:51:00 PM

Hi,

Is there a reason why I can't send and receive a messages with a
negative number using SendMessage?

The Windows common controls use negative notification messages and
I've never had a problem receiving those, so the problem has to be
with the Sending side of things.

What am I missing?

Thanks


'**** FORM1 ****'
Option Explicit

Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA"
( _
ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any
_
) As Long

Private Declare Function SetWindowSubclass Lib "comctl32" ( _
ByVal hWnd As Long, ByVal pfnSubclass As Long, _
ByVal uIdSubclass As Long, ByVal dwRefData As Long _
) As Long

Private Declare Function DefSubclassProc Lib "comctl32" ( _
ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long _
) As Long

Private Declare Function RemoveWindowSubclass Lib "comctl32" ( _
ByVal hWnd As Long, ByVal pfnSubclass As Long, _
ByVal uIdSubclass As Long _
) As Long

Friend Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Select Case uMsg
Case -2049
Debug.Print "-2049"
Case Else
WndProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
End Select
End Function

Private Sub Form_Load()
Call SetWindowSubclass(Me.hWnd, AddressOf Module1.WndProc,
ObjPtr(Me), 0&)
Call SendMessage(Me.hWnd, -2049, ByVal 0&, ByVal 0&)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call RemoveWindowSubclass(Me.hWnd, AddressOf Module1.WndProc, _
ObjPtr(Me))
End Sub

'**** MODULE1 ****'
Option Explicit

Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long, _
ByVal uIdSubclass As Form1, ByVal dwRefData As Long _
) As Long

WndProc = uIdSubclass.WndProc(hWnd, uMsg, wParam, lParam)
End Function
11 Answers

(nobody)

8/29/2010 4:21:00 PM

0

"Robert" <noname@noserver.com> wrote in message
news:anuk769doofbdtd04tnohui1oi3q6agci7@4ax.com...
> Call SendMessage(Me.hWnd, -2049, ByVal 0&, ByVal 0&)

What is the constant for -2049? I already looked at the common controls
constants, but couldn't find a corresponding constant. Here are the list of
notification constants:


//====== WM_NOTIFY codes (NMHDR.code values)
==================================

#define NM_FIRST (0U- 0U) // generic to all controls
#define NM_LAST (0U- 99U)

#define LVN_FIRST (0U-100U) // listview
#define LVN_LAST (0U-199U)

// Property sheet reserved (0U-200U) - (0U-299U) - see prsht.h

#define HDN_FIRST (0U-300U) // header
#define HDN_LAST (0U-399U)

#define TVN_FIRST (0U-400U) // treeview
#define TVN_LAST (0U-499U)

#define TTN_FIRST (0U-520U) // tooltips
#define TTN_LAST (0U-549U)

#define TCN_FIRST (0U-550U) // tab control
#define TCN_LAST (0U-580U)

// Shell reserved (0U-580U) - (0U-589U)

#define CDN_FIRST (0U-601U) // common dialog (new)
#define CDN_LAST (0U-699U)

#define TBN_FIRST (0U-700U) // toolbar
#define TBN_LAST (0U-720U)

#define UDN_FIRST (0U-721) // updown
#define UDN_LAST (0U-740)
#if (_WIN32_IE >= 0x0300)
#define MCN_FIRST (0U-750U) // monthcal
#define MCN_LAST (0U-759U)

#define DTN_FIRST (0U-760U) // datetimepick
#define DTN_LAST (0U-799U)

#define CBEN_FIRST (0U-800U) // combo box ex
#define CBEN_LAST (0U-830U)

#define RBN_FIRST (0U-831U) // rebar
#define RBN_LAST (0U-859U)
#endif

#if (_WIN32_IE >= 0x0400)
#define IPN_FIRST (0U-860U) // internet address
#define IPN_LAST (0U-879U) // internet address

#define SBN_FIRST (0U-880U) // status bar
#define SBN_LAST (0U-899U)

#define PGN_FIRST (0U-900U) // Pager Control
#define PGN_LAST (0U-950U)

#endif

#if (_WIN32_IE >= 0x0500)
#ifndef WMN_FIRST
#define WMN_FIRST (0U-1000U)
#define WMN_LAST (0U-1200U)
#endif
#endif

#if (_WIN32_WINNT >= 0x0501)
#define BCN_FIRST (0U-1250U)
#define BCN_LAST (0U-1350U)
#endif


Tom Shelton

8/29/2010 4:47:00 PM

0

on 8/29/2010, Robert supposed :
> Hi,
>
> Is there a reason why I can't send and receive a messages with a
> negative number using SendMessage?
>
> The Windows common controls use negative notification messages and
> I've never had a problem receiving those, so the problem has to be
> with the Sending side of things.
>

I think you may have a problem with sign. Windows Messages are
unsigned values - some of them look negative to VB.CLASSIC, because it
does not support an unsigned type. What windows is seeing is going to
be:

Dim b As Long
b = CLng("&H" & Hex$(-2049))

Which is the value: 63487

Which is &HF7FF and in fact, when that hex value is assigned to a vb
long, you get 63487.

So, my guess is that the value you are receiving is 63487, since that
is under the value of 65536.

--
Tom Shelton


(nobody)

8/29/2010 5:32:00 PM

0

"Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
news:i5e2v6$m5p$1@news.eternal-september.org...
> on 8/29/2010, Robert supposed :
>> Hi,
>>
>> Is there a reason why I can't send and receive a messages with a
>> negative number using SendMessage?
>>
>> The Windows common controls use negative notification messages and
>> I've never had a problem receiving those, so the problem has to be
>> with the Sending side of things.
>>
>
> I think you may have a problem with sign. Windows Messages are unsigned
> values - some of them look negative to VB.CLASSIC, because it does not
> support an unsigned type. What windows is seeing is going to be:
>
> Dim b As Long
> b = CLng("&H" & Hex$(-2049))
>
> Which is the value: 63487
>
> Which is &HF7FF and in fact, when that hex value is assigned to a vb
> long, you get 63487.
>
> So, my guess is that the value you are receiving is 63487, since that is
> under the value of 65536.

Incorrect. The parameter is As Long, so -2049 gets sign extended to 32-Bit,
and would be &HFFFFF7FF.


Tom Shelton

8/29/2010 8:45:00 PM

0

Nobody was thinking very hard :
> "Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
> news:i5e2v6$m5p$1@news.eternal-september.org...
>> on 8/29/2010, Robert supposed :
>>> Hi,
>>>
>>> Is there a reason why I can't send and receive a messages with a
>>> negative number using SendMessage?
>>>
>>> The Windows common controls use negative notification messages and
>>> I've never had a problem receiving those, so the problem has to be
>>> with the Sending side of things.
>>>
>>
>> I think you may have a problem with sign. Windows Messages are unsigned
>> values - some of them look negative to VB.CLASSIC, because it does not
>> support an unsigned type. What windows is seeing is going to be:
>>
>> Dim b As Long
>> b = CLng("&H" & Hex$(-2049))
>>
>> Which is the value: 63487
>>
>> Which is &HF7FF and in fact, when that hex value is assigned to a vb long,
>> you get 63487.
>>
>> So, my guess is that the value you are receiving is 63487, since that is
>> under the value of 65536.
>
> Incorrect. The parameter is As Long, so -2049 gets sign extended to 32-Bit,
> and would be &HFFFFF7FF.

Yes... I realized that as I was driving away from my home just a few
minutes after posing. For some reason, I was thinking in 16-bit 2's
complement rather then 32-bit.

Anyway, the number the op is looking for is really 4294965247

--
Tom Shelton


Robert

8/30/2010 4:00:00 AM

0

On Sun, 29 Aug 2010 14:44:51 -0600, Tom Shelton
<tom_shelton@comcast.invalid> wrote:

>Nobody was thinking very hard :
>> "Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
>> news:i5e2v6$m5p$1@news.eternal-september.org...
>>> on 8/29/2010, Robert supposed :
>>>> Hi,
>>>>
>>>> Is there a reason why I can't send and receive a messages with a
>>>> negative number using SendMessage?
>>>>
>>>> The Windows common controls use negative notification messages and
>>>> I've never had a problem receiving those, so the problem has to be
>>>> with the Sending side of things.
>>>>
>>>
>>> I think you may have a problem with sign. Windows Messages are unsigned
>>> values - some of them look negative to VB.CLASSIC, because it does not
>>> support an unsigned type. What windows is seeing is going to be:
>>>
>>> Dim b As Long
>>> b = CLng("&H" & Hex$(-2049))
>>>
>>> Which is the value: 63487
>>>
>>> Which is &HF7FF and in fact, when that hex value is assigned to a vb long,
>>> you get 63487.
>>>
>>> So, my guess is that the value you are receiving is 63487, since that is
>>> under the value of 65536.
>>
>> Incorrect. The parameter is As Long, so -2049 gets sign extended to 32-Bit,
>> and would be &HFFFFF7FF.
>
>Yes... I realized that as I was driving away from my home just a few
>minutes after posing. For some reason, I was thinking in 16-bit 2's
>complement rather then 32-bit.
>
>Anyway, the number the op is looking for is really 4294965247

That's the number I want any language that has unsigned 32 bit
integers, to think I am sending.

I actually want to send -2049

To put it in context:

For reasons* which become less compelling by the hour, I'm writing a
Win32 style control in VB6 (i.e. The window is created with
CreateWindowEx and the api is all windows messages).

-2049 is just the constant I'd picked to represent a left button click
following the common controls convention of using negative numbers to
define notifications.

If it was a C header the definition would be:

#define CVN_FIRST (0U-2048U)
#define CVN_BUTTONCLICK (CVN_FIRST-1)

Which should translate to VB6 as:

Public Const CVN_FIRST = -2048&
Public Const CVN_BUTTONCLICK = CVN_FIRST - 1

Control Code:

If (SendMessage(m_hwndParent, CVN_BUTTONCLICK, ByVal 0&, nmhti) then
...
End if

The message isn't being received by the parent at all. Surely Windows
doesn't care (or know) that I'm sending a signed vb long rather than a
UINT.

Robert

*The main reason being that I wanted to see if I could.

Robert

8/30/2010 4:35:00 AM

0

Oh bugger, I've just realised that I'm getting this completely wrong.

I'm talking about notification messdages so CVN_BUTTONCLICK would be
contained in the code field of an NMHDR structure received in the
lParam of a WM_NOTIFY message.

Please pretend this thread never happened.

Robert

Tony Toews

8/30/2010 5:44:00 AM

0

On Mon, 30 Aug 2010 05:34:56 +0100, Robert <noname@noserver.com>
wrote:

>Oh bugger, I've just realised that I'm getting this completely wrong.
<snip>
>Please pretend this thread never happened.

Remarkable how many times I've typed up a question and realized I was
a moron at the bottom. Thankfully before I posted. <smile>

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...

Robert

8/30/2010 6:07:00 AM

0

On Mon, 30 Aug 2010 05:34:56 +0100, Robert <noname@noserver.com>
wrote:

>Oh bugger, I've just realised that I'm getting this completely wrong.
>
>I'm talking about notification messdages so CVN_BUTTONCLICK would be
>contained in the code field of an NMHDR structure received in the
>lParam of a WM_NOTIFY message.
>
>Please pretend this thread never happened.
>
>Robert

And here's what I should have been doing.

'Helper function

Private Function Notify(ByVal code as long, _
ByRef hdr as NMHDR) as long)
hdr.hwndfrom = m_hwnd
hdr.idFrom = GetDlgCtrlID(m_hwnd)
hdr.code = code
Notify = SendMessage(GetParent(m_hwnd), WM_NOTIFY, ByVal 0&, hdr)
End Function

'Calling code

Dim itemclick as NMITEMCLICK
itemclick.iItem = iItem
'(fill in other fields)

If (Notify(CVN_ITEMCLICK, itemclick.hdr)) Then
...
End If

'Control parent code

Case WM_NOTIFY
Dim hdr As NMHDR
CopyMemory hdr, ByVal lParam, LenB(hdr)
If (hdr.hwndFrom = m_hwnd) Then
Select Case hdr.code
Case CVN_ITEMCLICK
Dim itemclick As NMITEMCLICK
CopyMemory itemclick, ByVal lParam, LenB(itemclick)
Debug.Print "ITEMCLICK:", itemclick.iItem
End Select
End If

Mike Williams

8/30/2010 9:34:00 AM

0

"Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
news:i5egtl$q5q$1@news.eternal-september.org...

> Yes... I realized that as I was driving away from my
> home just a few minutes after posing. For some reason,
> I was thinking in 16-bit 2's complement rather then 32-bit.

You shouldn't be doing hard sums whilst driving. It'll make your brain hurt
and you'll have an accident, which will make your brain hurt even more ;-)

Mike



Karl E. Peterson

9/1/2010 11:33:00 PM

0

Tom Shelton was thinking very hard :
> Yes... I realized that as I was driving away from my home
> just a few minutes after posing.
^^^^^^
Freudian slip, presumably? <eg>

--
..NET: It's About Trust!
http://vfre...