Which window has the focus [modified]
-
I have to return the path of the selected file , EITHER in the Desktop or in the Windows Explorer. I can get the path of the selected file both on the Windows Explorer and the desktop My problem is that I am unable to find which window has the current focus 1) The user has selected a file on the desktop 2) The user has selected a file in the Windows explorer. ( So this has the focus now ) How do I programatically find that out I am using the following code HWND hWndDesktop = GetDesktopHandle(); // Gets the handle of the SyslistView32 window DWORD dwThread = ::GetWindowThreadProcessId(hWndDesktop, NULL); GUITHREADINFO gtf ; gtf.cbSize = sizeof(GUITHREADINFO); BOOL b = GetGUIThreadInfo(dwThread, >f); if(hWndDesktop == gtf.hwndFocus) { // this window currently has the focus } But I am getting different handles for hWndDesktop and gtf.hwndFocus . Please let me know if I am missing something EDIT I am trying to get the Window handle across processes . Thanks Sujay
modified on Friday, December 4, 2009 12:40 AM
-
I have to return the path of the selected file , EITHER in the Desktop or in the Windows Explorer. I can get the path of the selected file both on the Windows Explorer and the desktop My problem is that I am unable to find which window has the current focus 1) The user has selected a file on the desktop 2) The user has selected a file in the Windows explorer. ( So this has the focus now ) How do I programatically find that out I am using the following code HWND hWndDesktop = GetDesktopHandle(); // Gets the handle of the SyslistView32 window DWORD dwThread = ::GetWindowThreadProcessId(hWndDesktop, NULL); GUITHREADINFO gtf ; gtf.cbSize = sizeof(GUITHREADINFO); BOOL b = GetGUIThreadInfo(dwThread, >f); if(hWndDesktop == gtf.hwndFocus) { // this window currently has the focus } But I am getting different handles for hWndDesktop and gtf.hwndFocus . Please let me know if I am missing something EDIT I am trying to get the Window handle across processes . Thanks Sujay
modified on Friday, December 4, 2009 12:40 AM
Use
GetFocus
to get the handle to the window that has the focus.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Use
GetFocus
to get the handle to the window that has the focus.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Use
GetFocus
to get the handle to the window that has the focus.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Superman, Does the GetTopWindow help in this regard ? Or, What about using File Change Notification[^] to get the changes user made in file system ? Not sure these are relevant for the OP.
modified on Friday, December 4, 2009 1:37 AM
-
I have to return the path of the selected file , EITHER in the Desktop or in the Windows Explorer. I can get the path of the selected file both on the Windows Explorer and the desktop My problem is that I am unable to find which window has the current focus 1) The user has selected a file on the desktop 2) The user has selected a file in the Windows explorer. ( So this has the focus now ) How do I programatically find that out I am using the following code HWND hWndDesktop = GetDesktopHandle(); // Gets the handle of the SyslistView32 window DWORD dwThread = ::GetWindowThreadProcessId(hWndDesktop, NULL); GUITHREADINFO gtf ; gtf.cbSize = sizeof(GUITHREADINFO); BOOL b = GetGUIThreadInfo(dwThread, >f); if(hWndDesktop == gtf.hwndFocus) { // this window currently has the focus } But I am getting different handles for hWndDesktop and gtf.hwndFocus . Please let me know if I am missing something EDIT I am trying to get the Window handle across processes . Thanks Sujay
modified on Friday, December 4, 2009 12:40 AM
i have tried what u have done . that GetFocus function is retirning is NULL when iam calling in thread. so, that i tried one more function GetForegroundWindow(); this also returns HWND.
CWnd \*wnd=NULL; HWND hWnd = NULL; CString strwndName; while (1) { hWnd=::GetFocus(); if(hWnd==NULL) hWnd=GetForegroundWindow(); GetWindowText(hWnd,strwndName.GetBuffer(),20); //displaying in edit box. dlg->m\_ed1.SetWindowText(strwndName); }
just try it.. it will be work...
Regards, Srinivas