type
status
date
slug
summary
tags
category
icon
password

system event queue | application event queue

  1. System Event Queue: The system event queue is managed by the operating system itself. It handles system-level events, such as hardware interrupts (like input from a mouse or keyboard), system notifications, and other OS-level actions. The system event queue acts as a central dispatcher, processing the events it receives, and deciding which application event queue to place them in based on the target of the event. For instance, a mouse click event on a specific application window will be routed to that application's event queue.
  1. Application Event Queue: Each application that is running on the system has its own event queue. These queues handle events that are specifically targeted to the application. This includes user input events that occur within the application's windows, messages sent from other applications or the system, and internal events generated by the application itself. Once an event is placed in an application's event queue, it's up to the application to handle that event appropriately.
For an event, the journey is something like this: the hardware generates an interrupt that is caught by the OS. The OS processes this interrupt and generates an event that is placed in the system event queue. The OS then removes the event from the system queue and, based on the target of the event, places it into the appropriate application event queue. The application then retrieves this event from its queue and processes it.

Main Message Loop

The main message loop in a Win32 application is a continuous loop that retrieves and dispatches messages until the application receives a quit message. A simple example of the main message loop might look like this:

TranslateMessage

This function is used for keyboard input translation. It takes as its argument a pointer to a MSG structure that contains message information about key-down and key-up events. TranslateMessage() translates virtual-key messages into character messages.
For instance, when you press a key on your keyboard, the system creates a WM_KEYDOWN message. If TranslateMessage() is called with that message, it generates a new WM_CHAR message which includes the character code of the key that was pressed. This WM_CHAR message is then posted back to the application's message queue, to be picked up in the next iteration of the message loop.
💡
The TranslateMessage function in the Win32 API is primarily used to translate virtual-key messages into character messages. When you pass a non-keyboard event (i.e., a message not related to a key press or release) to TranslateMessage, it simply ignores the message and nothing happens.

DispatchMessage

This function dispatches a message to the window procedure associated with the window that the message is targeted at. It takes as its argument a pointer to a MSG structure that contains the message to be dispatched.
The DispatchMessage() function is responsible for invoking the window procedure, where the actual processing of the message occurs. This can involve a wide variety of actions, depending on the message and the application's implementation of the window procedure.
Each window instance must has its own event process function: the signature of this event process function is LRESULT CALLBACK(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam). This function returns 0 if it did process the function passed in, otherwise it calls DefWindowProc to let windows core to handle. A simple implementation could look like this:
 
Wide Character Types - What We Need Them For?C++ Virtual Table Implementation Details
Zack Yang
Zack Yang
Just a humble bounty hunter🥷
公告
type
status
date
slug
summary
tags
category
icon
password
Hey there, welcome to my blog 👋
-- 这个博客写些什么 --
定期技术分享🤖
不定期发疯文学🤡