How to list custom messages (RegisterWindowMessage) ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: How to list custom messages (RegisterWindowMessage) ?

  1. #1
    Alex Guest

    How to list custom messages (RegisterWindowMessage) ?


    Hi,

    I am currently working on a "scheduler" - I cannot rely on the NT Scheduler
    because the client might not use NT. I have to post/send custom messages
    to a few applications, like "DialNow" or "SendAlarm". I'm using RegisterWindowMessage
    in the scheduler to register for instance the "DialNow" message. But in order
    to get this message in another app I found out (through trial & error) that
    I have to re-register the same message in the app that's waiting for this
    message:

    m_lngMessage = RegisterWindowMessage("DIAL")
    and then
    Private Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
    wParam As Long, ByVal lParam As Long) As Long

    Select Case uMsg
    Case m_lngMessage
    frmClient.Cls
    frmClient.Print "Received 'DIAL' message " & Now
    WindowProc = CallWindowProc(lngOldWindowFunctionAddress, hwnd,
    uMsg, wParam, lParam)
    etc.

    because I need the handle (long) of the message (m_lngMessage). Is there
    any other way to do it ? Maybe I don't have to re-register the message in
    order to be able to listen to it...

    Is there a function which would list all the custom messages registered on
    the system ?

    Thanks,
    Alex.

  2. #2
    Mattias Sjögren Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Alex,

    >Is there any other way to do it ? Maybe I don't have to re-register the message in
    >order to be able to listen to it...


    No, you're doing it the way it should be done.


    >Is there a function which would list all the custom messages registered on the system ?


    I can't think of any function that does that. I know that Spy++ can
    somehow figure out the name of a registered message, but that might be
    done with undocumented functions.


    Mattias

    ____________________________________________
    Mattias Sjögren - mattiass @ hem.passagen.se
    http://hem.spray.se/mattias.sjogren/
    Docendo discimus

  3. #3
    Mattias Sjögren Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Alex,

    >Is there any other way to do it ? Maybe I don't have to re-register the message in
    >order to be able to listen to it...


    No, you're doing it the way it should be done.


    >Is there a function which would list all the custom messages registered on the system ?


    I can't think of any function that does that. I know that Spy++ can
    somehow figure out the name of a registered message, but that might be
    done with undocumented functions.


    Mattias

    ____________________________________________
    Mattias Sjögren - mattiass @ hem.passagen.se
    http://hem.spray.se/mattias.sjogren/
    Docendo discimus

  4. #4
    Mattias Sjögren Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Hi Eduardo,

    >GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >the name of the clipboard format. So I just test them. GetAtomName failed,
    >but GetClipboardFormatName returned the correct name.


    Ahh, cool. That's good to know... :-)


    Mattias

    ____________________________________________
    Mattias Sjögren - mattiass @ hem.passagen.se

  5. #5
    Mattias Sjögren Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Hi Eduardo,

    >GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >the name of the clipboard format. So I just test them. GetAtomName failed,
    >but GetClipboardFormatName returned the correct name.


    Ahh, cool. That's good to know... :-)


    Mattias

    ____________________________________________
    Mattias Sjögren - mattiass @ hem.passagen.se

  6. #6
    Eduardo A. Morcillo Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    > >Is there a function which would list all the custom messages registered
    on the system ?
    >
    > I can't think of any function that does that. I know that Spy++ can
    > somehow figure out the name of a registered message, but that might be
    > done with undocumented functions.


    Well, it's undocumented, but they use documented functions.

    RegisterWindowMessage returns a value in the range &HC000 through &HFFFF. I
    remembered other 2 functions that returns values in the same range: AddAtom,
    RegisterClipboardFormat, and I thought that, maybe, RegisterWindowMessage
    uses one of them to register the message.

    GetAtomName returns the name of an atom and GetClipboardFormatName returns
    the name of the clipboard format. So I just test them. GetAtomName failed,
    but GetClipboardFormatName returned the correct name.

    --
    Eduardo A. Morcillo
    http://www.domaindlx.com/e_morcillo



  7. #7
    Eduardo A. Morcillo Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    > >Is there a function which would list all the custom messages registered
    on the system ?
    >
    > I can't think of any function that does that. I know that Spy++ can
    > somehow figure out the name of a registered message, but that might be
    > done with undocumented functions.


    Well, it's undocumented, but they use documented functions.

    RegisterWindowMessage returns a value in the range &HC000 through &HFFFF. I
    remembered other 2 functions that returns values in the same range: AddAtom,
    RegisterClipboardFormat, and I thought that, maybe, RegisterWindowMessage
    uses one of them to register the message.

    GetAtomName returns the name of an atom and GetClipboardFormatName returns
    the name of the clipboard format. So I just test them. GetAtomName failed,
    but GetClipboardFormatName returned the correct name.

    --
    Eduardo A. Morcillo
    http://www.domaindlx.com/e_morcillo



  8. #8
    Alex Guest

    Re: How to list custom messages (RegisterWindowMessage) ?


    Yes, cool indeed. I'll give it a shot right now. Thanks.

    >>GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >>the name of the clipboard format. So I just test them. GetAtomName failed,
    >>but GetClipboardFormatName returned the correct name.

    >
    >Ahh, cool. That's good to know... :-)
    >
    >
    >Mattias
    >
    >____________________________________________
    >Mattias Sjögren - mattiass @ hem.passagen.se



  9. #9
    Alex Guest

    Re: How to list custom messages (RegisterWindowMessage) ?


    Yes, cool indeed. I'll give it a shot right now. Thanks.

    >>GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >>the name of the clipboard format. So I just test them. GetAtomName failed,
    >>but GetClipboardFormatName returned the correct name.

    >
    >Ahh, cool. That's good to know... :-)
    >
    >
    >Mattias
    >
    >____________________________________________
    >Mattias Sjögren - mattiass @ hem.passagen.se



  10. #10
    Alex Guest

    Re: How to list custom messages (RegisterWindowMessage) ?


    Sorry, but how did you do it ? All I could come up with is this code:

    Private Sub Command1_Click()

    Dim strFormat As String * 255
    Dim lngClipboardFormat As Long
    Dim lngClipboardFormatArray() As Long
    Dim lngAnswer As Long
    Dim intCounter As Integer

    'Open clipboard
    If OpenClipboard(Me.hwnd) > 0 Then
    'Start enumerating
    ReDim lngClipboardFormatArray(0)
    lngClipboardFormat = EnumClipboardFormats(0)
    'If we succeeded, continue:
    If lngClipboardFormat > 0 Then
    lngClipboardFormatArray(UBound(lngClipboardFormatArray)) = lngClipboardFormat
    ReDim Preserve lngClipboardFormatArray(UBound(lngClipboardFormatArray)
    + 1)
    Do While lngClipboardFormat <> 0
    lngClipboardFormat = EnumClipboardFormats(lngClipboardFormat)
    lngClipboardFormatArray(UBound(lngClipboardFormatArray))
    = lngClipboardFormat
    ReDim Preserve lngClipboardFormatArray(UBound(lngClipboardFormatArray)
    + 1)
    Loop
    'Formats are enumerated in the array. List them:
    For intCounter = 0 To UBound(lngClipboardFormatArray) - 1
    lngAnswer = GetClipboardFormatName(lngClipboardFormatArray(intCounter),
    strFormat, 256)
    If lngAnswer > 0 Then
    Debug.Print Left(strFormat, lngAnswer)
    End If
    Next intCounter
    End If
    CloseClipboard
    Erase lngClipboardFormatArray
    End If
    End Sub

    and it lists:
    DataObject
    Ole Private Data

    Maybe I'm missing the point here ???


    "Eduardo A. Morcillo" <edanmo@geocities.com> wrote:
    >> >Is there a function which would list all the custom messages registered

    >on the system ?
    >>
    >> I can't think of any function that does that. I know that Spy++ can
    >> somehow figure out the name of a registered message, but that might be
    >> done with undocumented functions.

    >
    >Well, it's undocumented, but they use documented functions.
    >
    >RegisterWindowMessage returns a value in the range &HC000 through &HFFFF.

    I
    >remembered other 2 functions that returns values in the same range: AddAtom,
    >RegisterClipboardFormat, and I thought that, maybe, RegisterWindowMessage
    >uses one of them to register the message.
    >
    >GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >the name of the clipboard format. So I just test them. GetAtomName failed,
    >but GetClipboardFormatName returned the correct name.
    >
    >--
    >Eduardo A. Morcillo
    >http://www.domaindlx.com/e_morcillo




  11. #11
    Alex Guest

    Re: How to list custom messages (RegisterWindowMessage) ?


    Sorry, but how did you do it ? All I could come up with is this code:

    Private Sub Command1_Click()

    Dim strFormat As String * 255
    Dim lngClipboardFormat As Long
    Dim lngClipboardFormatArray() As Long
    Dim lngAnswer As Long
    Dim intCounter As Integer

    'Open clipboard
    If OpenClipboard(Me.hwnd) > 0 Then
    'Start enumerating
    ReDim lngClipboardFormatArray(0)
    lngClipboardFormat = EnumClipboardFormats(0)
    'If we succeeded, continue:
    If lngClipboardFormat > 0 Then
    lngClipboardFormatArray(UBound(lngClipboardFormatArray)) = lngClipboardFormat
    ReDim Preserve lngClipboardFormatArray(UBound(lngClipboardFormatArray)
    + 1)
    Do While lngClipboardFormat <> 0
    lngClipboardFormat = EnumClipboardFormats(lngClipboardFormat)
    lngClipboardFormatArray(UBound(lngClipboardFormatArray))
    = lngClipboardFormat
    ReDim Preserve lngClipboardFormatArray(UBound(lngClipboardFormatArray)
    + 1)
    Loop
    'Formats are enumerated in the array. List them:
    For intCounter = 0 To UBound(lngClipboardFormatArray) - 1
    lngAnswer = GetClipboardFormatName(lngClipboardFormatArray(intCounter),
    strFormat, 256)
    If lngAnswer > 0 Then
    Debug.Print Left(strFormat, lngAnswer)
    End If
    Next intCounter
    End If
    CloseClipboard
    Erase lngClipboardFormatArray
    End If
    End Sub

    and it lists:
    DataObject
    Ole Private Data

    Maybe I'm missing the point here ???


    "Eduardo A. Morcillo" <edanmo@geocities.com> wrote:
    >> >Is there a function which would list all the custom messages registered

    >on the system ?
    >>
    >> I can't think of any function that does that. I know that Spy++ can
    >> somehow figure out the name of a registered message, but that might be
    >> done with undocumented functions.

    >
    >Well, it's undocumented, but they use documented functions.
    >
    >RegisterWindowMessage returns a value in the range &HC000 through &HFFFF.

    I
    >remembered other 2 functions that returns values in the same range: AddAtom,
    >RegisterClipboardFormat, and I thought that, maybe, RegisterWindowMessage
    >uses one of them to register the message.
    >
    >GetAtomName returns the name of an atom and GetClipboardFormatName returns
    >the name of the clipboard format. So I just test them. GetAtomName failed,
    >but GetClipboardFormatName returned the correct name.
    >
    >--
    >Eduardo A. Morcillo
    >http://www.domaindlx.com/e_morcillo




  12. #12
    Eduardo A. Morcillo Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    > Maybe I'm missing the point here ???

    A little. You are enumerating formats available in the clipboard instead of
    getting message names!

    Try this:

    Dim lCustomMessage As Long
    Dim sMessageName As String

    CustomMessage = RegisterWindowMessage("MyCustomMessage")

    sMessageName = String$(256, 0)
    sMessageName = Left$(sMessageName, _

    GetClipboardFormatName(lCustomMessage, _
    sMessageName, _
    Len(sMessageName)))

    MsgBox sMessageName

    You can get the name but you can't enumerate them.

    --
    Eduardo A. Morcillo
    http://www.domaindlx.com/e_morcillo



  13. #13
    Eduardo A. Morcillo Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    > Maybe I'm missing the point here ???

    A little. You are enumerating formats available in the clipboard instead of
    getting message names!

    Try this:

    Dim lCustomMessage As Long
    Dim sMessageName As String

    CustomMessage = RegisterWindowMessage("MyCustomMessage")

    sMessageName = String$(256, 0)
    sMessageName = Left$(sMessageName, _

    GetClipboardFormatName(lCustomMessage, _
    sMessageName, _
    Len(sMessageName)))

    MsgBox sMessageName

    You can get the name but you can't enumerate them.

    --
    Eduardo A. Morcillo
    http://www.domaindlx.com/e_morcillo



  14. #14
    Karl E. Peterson Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Hi Alex --

    > Is there a function which would list all the custom messages registered on
    > the system ?


    With Eduardo's *excellent* tip, I worked up the following:

    Private Declare Function GetClipboardFormatName Lib "user32" Alias
    "GetClipboardFormatNameA" (ByVal wFormat As Long, ByVal lpString As String, ByVal
    nMaxCount As Long) As Long

    Public Event RegisteredMessage(ByVal Name As String, ByVal Value As Long, Cancel
    As Boolean)

    Public Sub EnumRegisteredMessages()
    Dim i As Long
    Dim msg As String
    Dim nRet As Long
    Dim Cancel As Boolean
    Const BufLen = 256

    ' Prepare variables prior to loop
    msg = String$(BufLen, 0)
    Cancel = False

    ' Loop through all possible values
    For i = &HC000& To &HFFFF&
    nRet = GetClipboardFormatName(i, msg, BufLen)
    If nRet Then
    RaiseEvent RegisteredMessage(Left$(msg, nRet), i, Cancel)
    If Cancel Then Exit For
    End If
    Next i

    ' Provide notice we're done
    RaiseEvent RegisteredMessage("", 0, Cancel)
    End Sub

    That's just downright slick!

    Later... Karl
    --
    http://www.mvps.org/vb




  15. #15
    Karl E. Peterson Guest

    Re: How to list custom messages (RegisterWindowMessage) ?

    Hi Alex --

    > Is there a function which would list all the custom messages registered on
    > the system ?


    With Eduardo's *excellent* tip, I worked up the following:

    Private Declare Function GetClipboardFormatName Lib "user32" Alias
    "GetClipboardFormatNameA" (ByVal wFormat As Long, ByVal lpString As String, ByVal
    nMaxCount As Long) As Long

    Public Event RegisteredMessage(ByVal Name As String, ByVal Value As Long, Cancel
    As Boolean)

    Public Sub EnumRegisteredMessages()
    Dim i As Long
    Dim msg As String
    Dim nRet As Long
    Dim Cancel As Boolean
    Const BufLen = 256

    ' Prepare variables prior to loop
    msg = String$(BufLen, 0)
    Cancel = False

    ' Loop through all possible values
    For i = &HC000& To &HFFFF&
    nRet = GetClipboardFormatName(i, msg, BufLen)
    If nRet Then
    RaiseEvent RegisteredMessage(Left$(msg, nRet), i, Cancel)
    If Cancel Then Exit For
    End If
    Next i

    ' Provide notice we're done
    RaiseEvent RegisteredMessage("", 0, Cancel)
    End Sub

    That's just downright slick!

    Later... Karl
    --
    http://www.mvps.org/vb




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center