Can I call TranslateMessage inside the message callback?


I don't have the canonical message loop running, so is there a way I can call TranslateMessage (or its equivalent) inside my message proc handler?

Basically I need WM_CHAR messages and unless I can call TranslateMessage I'm not going to get those. Currently I have the message proc setup, but no message loop.

// Static window function called by Windows for message processing. Implementation // delegates message processing to MemberWndProc. LRESULT CALLBACK FxPlayerTiny::WindowsMsgStatic(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { msg = PeekMessage(&msg, HWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE); if (msg type is key down){ TranslateMessage(&msg); //DispatchMessage(&msg); -- needed? } else process msg normally }

My message proc handler is the first point of entry of messages, being setup in the following manner:

WNDCLASSEX wc; wc.lpfnWndProc = WindowsMsgStatic; .... RegisterClassEx(&wc);


At some point, in order to get a queued message, you must call a function like GetMessage or PeekMessage. Those functions yield MSG objects and it is those MSG objects that you must pass to TranslateMessage and DispatchMessage.

In the code in the original version of the question, you are trying to call TranslateMessage and DispatchMessage too late. You call them inside your window proc. You should call them at the point where you first receive the MSG object. In other words, call TranslateMessage and DispatchMessage straight after the call to PeekMessage or GetMessage.


  • Adobe AIR Native Extension TWAIN Image Scanner
  • why does not having ValidateRect cause a directx application to slow down tremendously??(c++)
  • How to correctly handle Windows messages from an MSFTEDIT_CLASS (RichEdit) control?
  • Resurrecting MFC/Visual Studio 6.0 project in VS2010
  • Strange behaviour of windows hooks
  • How to enable buttons when scroll bar hits bottom with Win32?
  • Produce a comma separated list using StringBuilder
  • Can Java comments be seen by decompiling?
  • ASP.NET MVC Error 500 When Pushed to Production Server
  • What is the difference between a CPU and a GPU oriented code?
  • Task processing status with a message queue
  • How to asynchronously apply function via Spark to subsets of dataframe?
  • How to encode U+FFFD in order to do a replace?
  • PHP loses mongoDB cursor despite long timeouts
  • Split an image into 64x64 chunks
  • Matrix as Applicative functor, which is not Monad
  • Controlling tab space in a using CSS?
  • How to convert text file automatically to graphviz dot file?
  • How to move object along the polygons
  • why lock_guard can get an already locked mutex by unique_lock?
  • ExtJS 4 Spring 3 file upload. Server sends bad response content type
  • User matching with current data
  • How to blur the specific part of image without using Render Script,as my minsdk is 14.
  • concatenating select menus into a single form input
  • Gerrit will not push. Error: No common ancestry
  • Netlink sockets and libnl - nl_recvmsgs_default returning -16 (EBUSY)
  • Timeout a query
  • Creating a C++ function that calls other Lua function
  • pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?
  • Python PIL to extract number from image
  • What's the syntax to inherit documentation from another indexer?
  • abstracting over a collection
  • Defined variables not working in javascript files when I use getScript
  • Can't remove headers after they are sent
  • Optimizing the print function in Matlab
  • How to synchronize jQuery dialog box to act like alert() of Javascript
  • C++ pointer value changes with static_cast
  • Security issues with PHP's Readfile method
  • WPF ICommand CanExecute(): RaiseCanExecuteChanged() or automatic handling via DispatchTimer?
  • Stop Bash Script if Hive Fails