Yes, you must always allocate memory if you intend to read from or write to it. A pointer declaration does not allocate any memory, it is just a single variable that can be used to address individual items. But the memory space to hold the items must be allocated before you use the pointer.
Hi. How can I retrieve the HWND of a control inside CDialog, and this control has the focus ? To get the next HWND control I can use GetNextWindow[^], but I can retrieve the HWND of the next or previous control that has the focus ...
GetForegroundWindow and GetActiveWindow are the goto functions.
GetActiveWindow give you the active window of your app if it was activated and topmost.
GetForegroundWindow function is the special function specifically designed for obtaining windows from other processes. It is the windows system topmost window, so if a window has focus it will be that window.
All windows recieving focus get WM_SETFOCUS messages and those losing it receive WM_KILLFOCUS messages which is the other way to track focus changes.
6.) You will need to make sure that the process setting the text is of greater or equal integrity levels. For example... a process running at medium level cannot set the text in a window owned by a process running at high integrity level.
GetForegroundWindow doesn't give a rats if your dialog has focus or not. At a guess you have the dialog in modal mode and the message queue is shutdown and your code isn't executing when it isn't focused
It is quite specific it's the window that's currently getting input regardless of its relationship to the calling thread (aka your little APP). It has two choices the focus window (or the windows that contains the focus window depends on class) or null if the desktop itself has focus.
The call they have closed down is its sister call SetForegroundWindow() to steal focus from another process (unless that process has explicitly given permission via AllowSetForegroundWindow) because lots of web browser popups were abusing it.