|
-
March 18th, 2004, 03:01 AM
#1
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
-
March 18th, 2004, 03:50 AM
#2
-
March 18th, 2004, 04:20 AM
#3
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)
-
March 18th, 2004, 04:28 AM
#4
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.
-
March 18th, 2004, 07:31 AM
#5
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
-
March 18th, 2004, 07:44 AM
#6
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...
-
March 18th, 2004, 07:44 AM
#7
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.
-
March 18th, 2004, 08:03 AM
#8
Can you give me a sample?
What is the difference between them?
Fulu Tao
-
March 18th, 2004, 11:23 PM
#9
WM_USER may already be in use by pre-defined window classes ("EDIT", "STATIC", etc.), while WM_APP is not.
-
March 18th, 2004, 11:31 PM
#10
I see
Thanks
Fulu Tao
-
March 19th, 2004, 12:19 AM
#11
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
-
March 19th, 2004, 12:38 AM
#12
[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
-
March 19th, 2004, 01:18 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|