<s>
The	O
message	B-General_Concept
loop	I-General_Concept
is	O
an	O
obligatory	O
section	O
of	O
code	O
in	O
every	O
program	B-Application
that	O
uses	O
a	O
graphical	B-Application
user	I-Application
interface	I-Application
under	O
Microsoft	B-Application
Windows	I-Application
.	O
</s>
<s>
Windows	O
programs	O
that	O
have	O
a	O
GUI	B-Application
are	O
event-driven	B-Application
.	O
</s>
<s>
Windows	O
maintains	O
an	O
individual	O
message	B-Operating_System
queue	I-Operating_System
for	O
each	O
thread	B-Operating_System
that	O
has	O
created	O
a	O
window	O
.	O
</s>
<s>
Usually	O
only	O
the	O
first	O
thread	B-Operating_System
creates	O
windows	O
.	O
</s>
<s>
Windows	O
places	O
messages	B-Architecture
into	O
that	O
queue	O
whenever	O
mouse	O
activity	O
occurs	O
on	O
that	O
thread	B-Operating_System
's	O
window	O
,	O
whenever	O
keyboard	O
activity	O
occurs	O
while	O
that	O
window	O
has	O
focus	O
,	O
and	O
at	O
other	O
times	O
.	O
</s>
<s>
A	O
process	O
can	O
also	O
add	O
messages	B-Architecture
to	O
its	O
own	O
queue	O
.	O
</s>
<s>
To	O
accept	O
user	O
input	O
,	O
and	O
for	O
other	O
reasons	O
,	O
each	O
thread	B-Operating_System
with	O
a	O
window	O
must	O
continuously	O
retrieve	O
messages	B-Architecture
from	O
its	O
queue	O
,	O
and	O
act	O
on	O
them	O
.	O
</s>
<s>
This	O
is	O
the	O
message	B-General_Concept
loop	I-General_Concept
.	O
</s>
<s>
There	O
usually	O
is	O
a	O
message	B-General_Concept
loop	I-General_Concept
in	O
the	O
main	B-Language
program	I-Language
,	O
which	O
runs	O
on	O
the	O
main	O
thread	B-Operating_System
,	O
and	O
additional	O
message	B-General_Concept
loop	I-General_Concept
in	O
each	O
created	O
modal	O
dialog	O
.	O
</s>
<s>
Messages	B-Architecture
for	O
every	O
window	O
of	O
the	O
process	O
pass	O
through	O
its	O
message	B-Operating_System
queue	I-Operating_System
,	O
and	O
are	O
handled	O
by	O
its	O
message	B-General_Concept
loop	I-General_Concept
.	O
</s>
<s>
A	O
message	B-General_Concept
loop	I-General_Concept
is	O
one	O
kind	O
of	O
event	B-General_Concept
loop	I-General_Concept
.	O
</s>
<s>
A	O
basic	O
message	B-General_Concept
loop	I-General_Concept
appears	O
as	O
follows	O
:	O
</s>
<s>
It	O
is	O
conventional	O
for	O
the	O
event	B-General_Concept
loop	I-General_Concept
to	O
call	O
TranslateMessage	O
on	O
each	O
message	O
which	O
can	O
translate	O
virtual	O
keystrokes	O
into	O
strings	O
.	O
</s>
<s>
The	O
message	B-General_Concept
loop	I-General_Concept
must	O
call	O
DispatchMessage	O
.	O
</s>
<s>
The	O
message	B-General_Concept
loop	I-General_Concept
does	O
not	O
directly	O
act	O
on	O
the	O
messages	B-Architecture
that	O
it	O
handles	O
.	O
</s>
<s>
Code	O
can	O
also	O
send	O
messages	B-Architecture
directly	O
to	O
a	O
window	O
procedure	O
.	O
</s>
<s>
These	O
are	O
called	O
nonqueued	O
messages	B-Architecture
.	O
</s>
<s>
A	O
strict	O
message	B-General_Concept
loop	I-General_Concept
is	O
not	O
the	O
only	O
option	O
.	O
</s>
<s>
Code	O
elsewhere	O
in	O
the	O
program	B-Application
can	O
also	O
accept	O
and	O
dispatch	O
messages	B-Architecture
.	O
</s>
<s>
WaitMessage	O
allows	O
a	O
thread	B-Operating_System
to	O
sleep	O
until	O
a	O
message	O
is	O
in	O
the	O
queue	O
.	O
</s>
<s>
Modern	O
graphical	B-Application
interface	I-Application
frameworks	B-Application
,	O
such	O
as	O
Windows	B-Application
Forms	I-Application
,	O
Windows	B-Device
Presentation	I-Device
Foundation	I-Device
,	O
MFC	O
,	O
Delphi	B-Language
,	O
Qt	B-Language
,	O
and	O
others	O
do	O
not	O
require	O
applications	O
to	O
code	O
a	O
Windows	O
message	B-General_Concept
loop	I-General_Concept
,	O
because	O
they	O
automatically	O
route	O
events	O
such	O
as	O
key	O
presses	O
and	O
mouse	O
clicks	O
to	O
their	O
appropriate	O
handlers	O
as	O
defined	O
within	O
the	O
framework	O
.	O
</s>
<s>
However	O
,	O
each	O
framework	O
implements	O
a	O
message	B-General_Concept
loop	I-General_Concept
somewhere	O
,	O
and	O
the	O
message	B-General_Concept
loop	I-General_Concept
can	O
usually	O
be	O
accessed	O
or	O
replaced	O
when	O
more	O
direct	O
control	O
is	O
required	O
.	O
</s>
