MFC: How to set the focus to the previously focused window?
-
Hi, I need to set the focus to the window that had the focus before my dialog was first selected. To be more precise: as soon as the user clicks a button in my dialog, I want to set the focus to the window that had the focus before the user clicked in my dialog. I also want to be able to realize if that window has been closed in the meantime. What is the best way to achieve that? Thanks alot for any suggestions.
-
Hi, I need to set the focus to the window that had the focus before my dialog was first selected. To be more precise: as soon as the user clicks a button in my dialog, I want to set the focus to the window that had the focus before the user clicked in my dialog. I also want to be able to realize if that window has been closed in the meantime. What is the best way to achieve that? Thanks alot for any suggestions.
-
hi store the handle to window for the previous window in memory, recall this hwnd to set focus whenever you want. "I also want to be able to realize if that window has been closed" use IsWindowVisible option for this. Regards, A. Gopinath.
Hi, adding to Gopinath's point you can use FindWindow API also. Refer it in msdn. Regards msr
-
Hi, I need to set the focus to the window that had the focus before my dialog was first selected. To be more precise: as soon as the user clicks a button in my dialog, I want to set the focus to the window that had the focus before the user clicked in my dialog. I also want to be able to realize if that window has been closed in the meantime. What is the best way to achieve that? Thanks alot for any suggestions.
Erik wrote:
I want to set the focus to the window that had the focus
You can handle the
WM_SETFOCUS
message. One of its parameters is the handle to the window that has lost the keyboard focus.Erik wrote:
I also want to be able to realize if that window has been closed
You can use the
IsWindow()
function to determine if the window has been closed (i.e., destroyed).Best wishes, Hans
-
Erik wrote:
I want to set the focus to the window that had the focus
You can handle the
WM_SETFOCUS
message. One of its parameters is the handle to the window that has lost the keyboard focus.Erik wrote:
I also want to be able to realize if that window has been closed
You can use the
IsWindow()
function to determine if the window has been closed (i.e., destroyed).Best wishes, Hans
Hans Dietrich wrote:
You can use the
IsWindow()
function to determine if the window has been closed (i.e., destroyed).Although this works in the most of the case, it is not "safe": when a window is destroyed its handle becomes invalid and the is ID (the handle value) can be reused by the system for another subsequently created window. If you don't look at all that while happening,
IsWindow
may return TRUE, but the window may not be the one you intended. (I mean: "my name (handle) is the same of my grandfather, I was born after his death, and I live in what it was his house. But I'm not him"! But if you send a letter to him, I'll read it as mine and, hopefully, I can understand the misleading only from the context".)2 bugs found. > recompile ... 65534 bugs found. :doh: