CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2003
    Location
    China
    Posts
    39

    How to define my ow message in SDK?

    I want to use a message defined by myself in SDK.How can i deal with it?I think it is good like this:
    SendMessage( hWnd,WM_MY_MESSAGE,wParam,lParam) ;
    where should i define the WM_MY_MESSAGE?
    Fulu Tao

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  3. #3
    Join Date
    Dec 2002
    Posts
    35
    You can define your message as WM_APP + X where X < 0x4000.
    like er
    Code:
    #define WM_MY_MESSAGE  (WM_APP + 0)
    #define WM_MY_MESSAGE2  (WM_APP + 1)

  4. #4
    Join Date
    Jul 2003
    Posts
    116
    which sdk are you talking about, are you developing your own SDK and want to include this message???
    if so then anywhere where this message is used
    just #define MYMSG WM_APP+ 1000

    also see RegisterWindowMEssage() in MSDN and an article from Joseph M NewCOmer about defining message strings using GUIDs but sometimes i think thats a waste of the GUIDs

    BTW the same approach goes for any custom messages.

  5. #5
    Join Date
    Jul 2003
    Location
    China
    Posts
    39

    Thanks a lot

    Thanks a lot!!!
    I have solved this problem.In fact it is because of my mistake in understanding the Message Sysytem in windows programmming. I have done it like this:#define WM_MY_MESSAGE WM_USER + 1000
    .......In the WINPROC function
    case WM_MY_MESSAGE:
    .......do your action code here
    Fulu Tao

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Thanks a lot

    Originally posted by iamahorse
    I have done it like this:#define WM_MY_MESSAGE WM_USER + 1000
    Just a small remark...in general you can use both 'WM_USER' or 'WM_APP' for user-defined messages. However, you should rather use 'WM_APP' as a base for your user-defined messages since it provides less problems. Windows itself uses the range 'WM_USER + x' for several messages therefore you can run into conflict problems pretty easy...

  7. #7
    Join Date
    Jul 2003
    Posts
    116
    I have done it like this:#define WM_MY_MESSAGE WM_USER + 1000
    WM_USER is obsolete now, either use WM_APP as the limit or use RegisterWindowMessage() in MSDN for a safe processing of ur msg in the wndProc(), or use that GUID appproach if you want "only your message" to be processed by your wnproc.

  8. #8
    Join Date
    Jul 2003
    Location
    China
    Posts
    39

    Can you give me a sample?

    What is the difference between them?
    Fulu Tao

  9. #9
    Join Date
    Dec 2002
    Posts
    35
    WM_USER may already be in use by pre-defined window classes ("EDIT", "STATIC", etc.), while WM_APP is not.

  10. #10
    Join Date
    Jul 2003
    Location
    China
    Posts
    39

    I see

    Thanks
    Fulu Tao

  11. #11
    Join Date
    Jul 2003
    Posts
    116
    using WM_APP range is a bit safer, but it may happen that someother application might also be sending messages of the same ID as yours,
    who knows u are using WM_APP+100
    someone else is using the same WM_APP+100 and sending or posting this message as a broadcast....

    so theres a very rare chance for any ambigous message processing, but to be on the safer side always register a message before sending or posting.
    cheers

  12. #12
    Join Date
    Jul 2003
    Location
    China
    Posts
    39
    [but to be on the safer side always register a message before sending or posting.]
    I look the function

    RegisterWindowMessage() in the MSDN ,it says:
    Only use RegisterWindowMessage when more than one application must process the same message.
    an application can use any integer in the range WM_USER through 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)
    Is that means we should not define the message in the way differ from using the WM_USER?
    Fulu Tao

  13. #13
    Join Date
    Jul 2003
    Posts
    116
    OPB iamahorse

    Is that means we should not define the message in the way differ from using the WM_USER?
    the decision is all yours, it depends on your strategy and design.
    to say "we should not" is a heavy statement cos its there to use. again i wud say the decision is on you that how do u want your application to respond, all the above described ways are right but different in optimisation levels, u have to decide to which level you need to go
    check this this will clear a few things.
    Last edited by siawos; March 19th, 2004 at 01:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured