原文:https://answers.unrealengine.com/questions/162868/how-can-i-add-window-message.html
Implement the IWindowsMessageHandler interface and register it with FWindowsApplication::AddMessageHandler(). Don't forget to remove it when you don't need it anymore. Also note that this is only for Windows, so you should only use it in code that is wrapped in #if PLATFORM_WINDOWS.
#if PLATFORM_WINDOWS class FMyWindowsMessageHandler : public IWindowsMessageHandler { public: virtual bool ProcessMessage(HWND hwnd, uint32 msg, WPARAM wParam, LPARAM lParam, int32& OutResult) override { // Handle your messages here } } #endif #if PLATFORM_WINDOWS TSharedPtr<GenericApplication> GenericApplication = FSlateApplication::Get().GetPlatformApplication(); FWindowsApplication* WindowsApplication = (FWindowsApplication*)GenericApplication.Get(); WindowsApplication->AddMessageHandler(MyMessageHandler); //... WindowsApplication->RemoveMessageHandler(MyMessageHandler); #endif