반응형
http://www.winprog.org/tutorial/message_loop.html
사이트 이름은 theForger's Win32 API Programming Tutorial
잘나와있다.
What is a Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); }
- The message loop calls
GetMessage()
, which looks in your message queue. If the message queue is empty your program basically stops and waits for one (it Blocks). - When an event occures causing a message to be added to the queue (for example the system registers a mouse click)
GetMessages()
returns a positive valueindicating there is a message to be processed, and that it has filled in the members of theMSG
structure we passed it. It returns0
if it hitsWM_QUIT
, and a negative value if an error occured. - We take the message (in the
Msg
variable) and pass it toTranslateMessage()
, this does a bit of additional processing, translating virtual key messages into character messages. This step is actually optional, but certain things won't work if it's not there. - Once that's done we pass the message to
DispatchMessage()
. WhatDispatchMessage()
does is take the message, checks which window it is for and then looks up the Window Procedure for the window. It then calls that procedure, sending as parameters the handle of the window, the message, andwParam
andlParam
. - In your window procedure you check the message and it's parameters, and do whatever you want with them! If you aren't handling the specific message, you almost always call
DefWindowProc()
which will perform the default actions for you (which often means it does nothing). - Once you have finished processing the message, your windows procedure returns,
DispatchMessage()
returns, and we go back to the beginning of the loop.
반응형
'나머지 > 일상다반사' 카테고리의 다른 글
부자증세에 대한 개인적인 의견 (2) | 2012.12.10 |
---|---|
할부원금 37만원짜리 옵티머스 뷰2 나왔네요. (3) | 2012.11.10 |
메뉴바생성 (0) | 2012.09.12 |
갤럭시3 버스트 샷으롬나든 GIF 파일 (0) | 2012.09.02 |
스마트폰을 사볼까...? (0) | 2012.08.08 |