Click to See Complete Forum and Search --> : How to define my ow message in SDK?


iamahorse
March 18th, 2004, 03:01 AM
:confused: 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?

Andreas Masur
March 18th, 2004, 03:50 AM
[Moved thread]

imthesponge
March 18th, 2004, 04:20 AM
You can define your message as WM_APP + X where X < 0x4000.
like er

#define WM_MY_MESSAGE (WM_APP + 0)
#define WM_MY_MESSAGE2 (WM_APP + 1)

siawos
March 18th, 2004, 04:28 AM
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 :rolleyes:

BTW the same approach goes for any custom messages.

iamahorse
March 18th, 2004, 07:31 AM
:) 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

Andreas Masur
March 18th, 2004, 07:44 AM
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...

siawos
March 18th, 2004, 07:44 AM
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.

iamahorse
March 18th, 2004, 08:03 AM
What is the difference between them?

imthesponge
March 18th, 2004, 11:23 PM
WM_USER may already be in use by pre-defined window classes ("EDIT", "STATIC", etc.), while WM_APP is not.

iamahorse
March 18th, 2004, 11:31 PM
:D Thanks

siawos
March 19th, 2004, 12:19 AM
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

iamahorse
March 19th, 2004, 12:38 AM
[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?:confused:

siawos
March 19th, 2004, 01:18 AM
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 (http://flounder.com/messages.htm) this will clear a few things.