   [ C ] Single threaded window manager input
  Basically, I wrote a small window manager for my game engine, and its function could be compared to Java's container and component functionality. Now, the only problem is, I need to think of an efficient scheme for requesting input from the user. Unlike Java which is multithreaded, I can't open another thread and halt the main one until the other thread terminates. My loop is simplified as follows:1. Poll input devices, put together events and states.2. Check which window is focused, and which component of the window is focused.3. If a window is focused, push a WM message onto that window's stack.3a. Interact with components or WM buttons if appropriate event is received.3b. Push additional messages onto the window if certain actions are performed.4. Draw windows.My main problem is, if I try to gather information, such asint number = WindowAskingUserForInput();in which, I can create a new window with a text box for the user to enter a response into inside WindowAskingUserForInput(), and everything is great. But, the problem is, the code that calls the function cannot wait for the input, because the user will never see said window, as the window is drawn later on, and input will be gathered elsewhere. So arbitrarily requesting information like this is out until I find a good way to do it. I've thought of callback functions, which is messy, especially if some information is gathered only if a condition is true, or if multiple pieces of information need to be inputted in a single function. I've thought of passing writable pointers to the window, which suffers the previous ailments. Last option I can think of is somehow have the function requiring data be called every loop iteration to check if the information is ready to be processed. But, that could be messy as well.So, I welcome any suggestions. Will post code if needed.
  The standard approach to this is to use an event-based model; one way to implement events is using callback functions. As you note this isn't a perfect solution, but it is the most flexible and general that avoids threading (at least that I know of).That said - with callbacks, organization of your input handling code shouldn't really be all that big of a deal. It's really the same as writing for WinForms or any other window management toolkit. If you're not already familiar with it, I'd suggest reading up on the Model/View/Controller pattern for ideas on how to organize the code so that things stay cleanly separated without loss of functionality.   ;  Thanks for the suggestion, I suppose I'll take the callback route, and look at code samples to see how I should form my user input gathering around it. Just to clarify, when I say input, I mean the user typing in a value or such, as opposed to key presses and mouse events and the like.   