winapi - Win32: C++: How do I re-focus on Parent Window after clicking in a child window? -


in win32 cpp program, have defined child window display various text strings using like:

hnd_to_this_ch_window = createwindow(                          l"edit",l"some initial text", ws_visible | ws_child | es_left,                           position_of_this_window_x,                                       position_of_this_window_y,                         textout_default_width,                                   textout_default_height,                          handle_to_my_parent_window, null,                                                 hinstance_variable_used_by_create_window,                          null ) 

my problem if click mouse select text in 1 of such child windows (to, say, copy somewhere), focus of application goes child window , keypresses used handled through main windows callback (with case wm_keydown:) captured child window, appear inputted characters. magic function call have focus go parent (so wm_keydown) can work again? hoping click on main window's title bar , take normal, isn't working (because, obviously, program lacking logic).

handle wm_killfocus message in window procedure of window want focus, , restore focus using setfocus function. if want focus window clicked, handle wm_lbuttondown message.

lresult callback mywndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam) {     // restore focus when lost.     if (msg == wm_killfocus) {         setfocus(hwnd);         // msg handled, return zero.         return 0;     }     // or when window clicked.     if (msg == wm_lbuttondown) {         setfocus(hwnd);         // msg handled, return zero.         return 0;     }     return defwindowproc(hwnd, msg, wparam, lparam); } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -