Click to See Complete Forum and Search --> : slight confusion
Dman832
July 26th, 2005, 10:42 AM
I am working on a multithreaded app for windows using VC++. I was using this example: http://www.codeguru.com/forum/showthread.php?t=312453&goto=nextnewest
Can someone explain to me what this line does:
#define WM_UPDATE_CONTROL WM_APP + 0x10
Thanks.
D_Drmmr
July 26th, 2005, 12:33 PM
This is a preprocessor DEFINE statement. From MSDN:
When using DEFINE statements, all instances of that statement are replaced by the value of the statement during a preprocessing phase. The DEFINE statement can be used in an IF statement.
#define variable_name [variable_value]
Parameters
variable_name
The variable can include any characters that are not white space.
variable_value
Any characters can be used, but leading and trailing white space is truncated. White space characters should not be used, unless the entire variable is surrounded by double quotes. If the value is empty, the variable is set to an empty string.
So in the code "WM_UPDATE_CONTROL" will be replaced by "WM_APP + 0x10". 0x10 is the hexadecimal notation for 16. So the value that is used for this specific messge is set to some start value (WM_APP) plus 16. This is done to make sure that different messages don't receive the same number. If you add other messages yourself, you should make sure that the preprocessor defines all have a different value.
upashu2
July 28th, 2005, 01:49 AM
#define WM_UPDATE_CONTROL WM_APP + 0x10
This lines is used for defining a user-defined message. A user-defined message can be send to from one thread to another using PostMessage(). Every message (e.g. WM_MOUSEMOVE) is unsinged integer.
The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.
WM_APP is defined as : #define WM_APP 0x8000
There are five ranges of message numbers:
0 through WM_USER – 1 : Messages reserved for use by the system
WM_USER through 0x7FFF : Integer messages for use by private window classes
WM_APP through 0xBFFF : Messages available for use by applications
0xC000 through 0xFFFF :String messages for use by applications
Greater than 0xFFFF : Reserved by the system for future use.
Message numbers in WM_APP through 0xBFFF are available for application to use as private messages. Message in this range do not conflict with system messages.
Again to send message between two or more different process, message should be unique throughout system, for its we use a string message and RegisterWindowMessage() function to find out the unique message number for that session.
Again while sending message, sender should have a window handle of reciver. Sender may be any thread, worker or GUI. But reciever is window always (GUI thread) , since it should have a message queue to recieve a message and a message loop to process those message.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.