MessageLoop

tain creates creates

MessageLoop
來自MSDN(原文)
-----------------------------------------------------------------------------------
Message Loop
The system automatically creates a message queue for each thread. If the thread creates one or more windows, a message loop must be provided; this message loop retrieves messages from the thread's message queue and dispatches them to the appropriate window procedures.
Because the system directs messages to individual windows in an application, a thread must create at least one window before starting its message loop. Most applications contain a single thread that creates windows. A typical application registers the window class for its main window, creates and shows the main window, and then starts its message loop — all in the WinMain function.
You create a message loop by using the GetMessage and DispatchMessage functions. If your application must obtain character input from the user, include the TranslateMessage function in the loop. TranslateMessage translates virtual-key messages into character messages.
-----------------------------------------------------------------------------------
翻譯
-----------------------------------------------------------------------------------
訊息循環
作業系統自動為每一個執行緒創建一個信息佇列。如果這個執行緒創建了一個或多個視窗,則你必須建立一個訊息循環。
你建立的這個訊息循環可以從訊息佇列裡面獲取訊息,然後傳送到合適的視窗進程中去。
因為作業系統要將訊息傳送給一個應用程式中單個的視窗,所以在開始建立訊息循環前,你的執行緒必須要創建個視窗。
大部分的應用程式都包含著一個執行緒,執行緒擁有著一個視窗。
最典型的應用程式包含了:註冊視窗類、創建視窗、顯示視窗,然後開始訊息循環——這都可以在WinMain函數裡按順序編寫。
創造一個訊息循環要使用GetMessage和DispatchMessage這兩個函式。
如果你的應用程式必須獲得用戶輸入的字元,那還需要TranslateMessage這個函式。
TranslateMessage可以將一個虛擬按鍵訊息轉化成字元訊息。

相關詞條

相關搜尋

熱門詞條

聯絡我們