1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Windows Message Handling

Discussion in 'Win32' started by coderzone, Dec 11, 2008.

  1. coderzone

    coderzone Super Moderator


    Windows communicate with the application by sending messages. There are many Windows messages and each message is represented by a unique integer value.In WINDOWS.H there are standard names for these messages.

    There are some common Windows messages like:-

    Messages are always accompanied by other values that contain additional,related in formation.This information includes things like cursor or mouse coordinates etc.Windows interacts with your programs through messages.Specifically each time when event occurs a message is sent to program which identifies the event. As there are large number of messages so it not necessary for the program to respond allthe messages so MFC has a default message handler. In a normal Windows program your program's window procedure receives each message and also any additional information which is related to that message .Inside the window procedure,a large switch statement determines what type of message has been received and then processes it accordingly.While using MFC responding messages is much easier.

    MFC provides a set of predefined message handler functions that your program may implement. If your program implements one of these handlers then that function will be called whenever its associated message is received.When a message has an additional information associated to it this information will be passed to message handler as an argument.

    To respond to a message ,your program must perform these three steps:-

    1. The message macro corresponding to the message must be added to your program's message map.

    2. The prototype for the message handler must be added to the window class that will process the message.

    3. Implement the message handler associated with the message.

    Adding Message Macros

    MFC message macros have the same name as standard window messages,except that they all begin with ON_ and end with a set of parentheses.There is one exception to this rule: the WM_COMMAND message uses ON_COMMAND for its message macro. This is because WM_COMMAND is a rather special windows message and it requires unique treatement by MFC.

    Here are some MFC message macros:-


    Each message that your program responds to must be associated with a message handler. All message handlers are members of the CWND class, and may be overridden by your program. As a general rule name of the message handler is constructed using the name of the message preceded by ON. For example , the handler for WM_CHAR IS OnChar(),the handler for WM_LBUTTONDOWN is OnLButtonDown().

    To respond to the message one must add the message handler to the window class that your program defines and that is done by including its prototype in the class declaration.

    Implementing Message Handlers

    Implementing message handlers depends on two things:-

    1.Nature of the message.

    2.Meaning of the message for your program.
    Scripting and slymart like this.
  2. shabbir

    shabbir Administrator Staff Member

  3. rajeev_rsd

    rajeev_rsd New Member

    Good Explaination, add some code example.
  4. slymart

    slymart New Member

    message are precised, context to a beginer. Thanks alot man.
  5. JECOB

    JECOB New Member

    Hi evryone,

    Good expriaratins is don't missing text and simple wordings.
  6. slymart

    slymart New Member

    Thanks obaid for the good explanation.
  7. slymart

    slymart New Member

    What can one do to solve this window 32 message; "dll file missing"?
  8. Scripting

    Scripting John Hoder

    The most well written article i have read in this section! Hats off.

Share This Page