what is message loop how mfc does it internally?
Answers were Sorted based on User's Feedback
Answer / sonali dongare
In Window programming Message is the main communication.The
messaes are stored in message queue.
the way you retrieve messages from the Message Queue is by
creating a Message Loop. A Message Loop is a loop that
checks for messages in the Message Queue. once a message is
received, the Message Loop dispatches the message by
calling a Message Handler, a function designed to help the
Message Loop at processing the message.
Message loop ends when WM_QUIT messae is retrived.In Mfc
WinMain is the entry point.since mfc uses event driven
programming model The Incoming messages enter in the
message queue window procedure process that messages and
send to window ,winmain create that window and enter into
message loop ,retrive messages and dispatches them to
window procedure.Messages wait in message queue untill they
are retrived.In order to retrive and dispatch the message
winmain execute simple while loop that call
GetMessage,TranslateMessage and DispathMessage API
Functions .GetMessage retrive message from message
queue ,TranslateMessage convert keyboard message to WM_CHAR
message and DispatchMessage dispatch messages to Window
procedure. Message loop end when it retrived WM_QUIT
message.
Is This Answer Correct ? | 40 Yes | 3 No |
Answer / mvs ravi kumar
Generally Windows programming is an event driven
programming. As and when something happens the some
message will be posted into message loop.
First of all, WinMain is the function which is being called
in windows application. This WinMain calls Initinstance of
that application and then enters the message loop.
Suppose take the case of SDI/MDI Application:
In SDI application messages are first sent it MainFrame
class, if there is no message handle in MainFrame then the
same message will be directed to CView. In the same way if
there is a handle for the message in View then the message
will be handled in the view other wise it will be directed
to CDocument. If there is message handle for the message
in Document then that handler function will be called
otherwise the message will be sent to CDocTemplate Class.
Then the message will be posed to another view if another
view exists otherwize the message will be sent to
DefWindowProc.
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / viresh chaudhari
The windows application enters the message loop within
Winmain to process various windows messages the OS posts to
a message queue.The message loop, "Loops" until its
receives a WM_QUIT message. It uses GetMessage and
PeekMessage to retrive messages and PostMessage to sent the
retrived messages to Windows procedure.
Is This Answer Correct ? | 8 Yes | 3 No |
Answer / manjinder
Message loop exists internally in the WinMain() which is
the default function given by the MFC framework. In the
WinMain() there is one function called Run() which is
running this message loop. There are two types of window
messages .
1)Command routing: These commands come from menus,toolbars
etc.
2) Windows messages: These messages occured when some child
control of view or dialog box is used.
Is This Answer Correct ? | 3 Yes | 2 No |
What four types of properties are supported by an ActiveX control?
Explain the flow of SDI application?
Which CPrintInfo member variable must be set for multiple page printouts?
1) How do you Destroy a Dialog Box ?
how does the UIThread and worker thread communicates and handle events
I want recent paper pattern for HP company?
What is the command routing in MFC framework?
Types of DLL's
1)How to change the size of a button at run time ?
What is socket?
How do you change the properties for a tree view control that is part of the CTreeView class?
How to access document object from view ?