Everything2
Near Matches
Ignore Exact
Full Text
Everything2

MSG

created by c3w

(thing) by Toxick (3.4 wk) (print)   ?   (I like it!) Wed Nov 28 2001 at 20:00:08

First of all, let me say that I love Asian cuisine. I've eaten enough General Tso's Chicken to choke a horse, and Egg Fu Yung and Hunan Shrimp is not far behind. But, I'm also a computer geek, and Asian food has nothing to do with this writeup.

MSG is a C structure in the Windows API which describes message information from a thread's message queue.

This struct is very important to the Windows Programmer because it is with the MSG struct that the programmer can handle user events. Most GUI's are event driven - and you must handle these events so that your software behaves in an expected manner. For instance, when you click on a button in a dialog box, the user probably has a pretty good idea what is supposed to happen next. It is the job of the programmer to capture that button click event, and then fulfill the user's expectations. In order to capture the events as they come in, the programmer must pass a pointer to the MSG struct to Windows, which will subsequently allow you to handle the event (or call a handler function) from your Window Procedure function. A Window Procedure function, or WndProc, is a callback function which often contains an enormous switch block that can determine which event (button click, scrollbar adjustment, keydown, timer event, etc) needs to be handled. If the event doesn't have custom behavior, it is ignored, and the DefWindowProc handler will be called.

The struct is defined thus:

typedef struct tagMSG
{
    HWND hWnd;
    UINT message;
    WPARAM wParam;
    LPARAM lParam;
    DWORD dwTime;
    POINT pt;
} MSG;

The HWND in the first field contains the handle to the window that is to receive the message. This is important, because the application needs to know which window's WndProc function is being called. Usually, you want an event to affect your window in some way, so having a handle to the window is not really a bad idea.

The second field is a UINT (an unsigned integer) which refers to the actual code value of the message. This message field is what is checked by the switch block mentioned above. The Windows API has a whole bunch of constants defined for nearly every conceivable message. You can also register your own custom messages by calling the RegisterWindowMessage function. These constants are typically assigned with a WM_ prefix followed by a descriptive title. WM_INITDIALOG for instance, is used when a Dialog Box is ready to be initialized. WM_LBUTTONDOWN is used when the user presses down on the Left Mouse Button.

The wParam and lParam parameters are extra information. Most controls are more sophisticated than a simple button click, and require a little more information from the operation system. If the user enters data into a textbox, for instance, you may need some way of knowing what that data was. Or if the user selects an item from a dropdown menu or a listbox, you need someway of indexing the user's selection. The exact meaning of the wParam and lParam parameters varies from message to message.

the dwTime and pt parameters are a simple timestamp, and cursor location respectively. I've never had to use this information while writing a program, but I'm sure there's at least one programmer out there who's grateful for it.

Headaches and asthma attacks notwithstanding, I need MSG to survive.


printable version
chaos

monosodium glutamate /msg umami Spine-vaporizing Chinese death sauce
The secret message node An easy way to make not-so-good food much better Chinese Restaurant Syndrome Madison Square Garden
Chatterbox Kentucky Fried Chicken General Tso's chicken food is a drug
The Truth Behind Doritos Flavors Falling in love with your best friend egg foo yung secret herbs and spices
Instant Messenger message .au #everything
Papain taste bud ICQ Rottweiler
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Look at this mess the Death Borg made!
The Black Rider
Mad Libs
Robert Rodriguez
Steve Wozniak
Selected Ambient Works II
angel hair
The semi fictional life of every real woman
Fingers slick with mythos
Iraqi Republican Guard
Wildfire
This program has performed an illegal operation and will be shut down
Interpretations of the lyrics to American Pie
How to survive a science fair
New Writeups
Glowing Fish
Tualatin River(place)
The Jacket
Words of Advice(idea)
keepinitreal
Why buy the cow when you can get the milk for free?(idea)
John_Fox
Good Intentions Gone Wrong(person)
Cuckowski
Slavonic Princess(poetry)
Heitah
Posthumous Oscar(thing)
ignis_glaciesque
University of South Florida(place)
ignis_glaciesque
Flogstaskriket(idea)
liveforever
Caesar's last breath(idea)
dagnyswaggart
she wants to believe(personal)
antigravpussy
he doesn't know, but her eyes widen too far(thing)
dagnyswaggart
Wild tides guard her secrets(poetry)
Lord Brawl
Caesar's last breath(poetry)
locke baron
Forgotten things in space(fiction)
sitaraika
Colours(idea)
Everything 2 is brought to you by the letter C and The Everything Development Company