Finding the HWND which has the focus
When a user selects a file , I want to know which Window has the current focus .
Just to explain, I am providing a scnearios.
1) User selects abc.txt on the Desktop
2) User selects xyz.doc in the Explorer.
Though both files have the LVM_SELECTED flag set, I want to get the handle of the window in which the file has been selected.
I tried with GetForegroundWindow, and GetGUIThreadInfo , but its not working.
Any sort of help would be appreicated
Sujay
Re: Finding the HWND which has the focus
is this what you seek?:
Code:
HWND hFocusWnd = GetFocus();
GetFocus()
Re: Finding the HWND which has the focus
I dont think it shall do.
Intially I thought of this, but if you see selecting a file on the desktop , need the windows of the Listview of the destkop , not just the desktop.
After that I want to compare the two desktop handles and accordingly let the user know.
Re: Finding the HWND which has the focus
Quote:
and GetGUIThreadInfo , but its not working
"It's not working" explains not much. A code would do a lot better.
Re: Finding the HWND which has the focus
Quote:
Originally Posted by
sujayg
After that I want to compare the two desktop handles and accordingly let the user know.
What are you hoping to let the user know?
Re: Finding the HWND which has the focus
Quote:
Originally Posted by
Arjay
What are you hoping to let the user know?
Let me explain the situation . I think it would be better than the technical terms .
1) User selects abc.txt on the Desktop
2) User selects xyz.doc in the Explorer.
If the user presses Ctrl+C, the file xyz.doc gets copied ONLY . That is Windows copies only the file which has the current focus .
How does Windows knows which one has the current focus? I have do this programatically .
Re: Finding the HWND which has the focus
Windows knows it because only one window has the focus at a time, and the window in focus gets the copy command and it places it's contents inside the clipboard, and second app gets it by pasting operation from clipboard.
Re: Finding the HWND which has the focus
You are right.
For example, if one has to get the desktop HWND, one has to find the handle of the Syslistview32 within the Program Manager .
In my case I want to compare the HWND's and see which HWND has the focus
Re: Finding the HWND which has the focus
Quote:
Originally Posted by
sujayg
Let me explain the situation . I think it would be better than the technical terms .
1) User selects abc.txt on the Desktop
2) User selects xyz.doc in the Explorer.
If the user presses Ctrl+C, the file xyz.doc gets copied ONLY . That is Windows copies only the file which has the current focus .
How does Windows knows which one has the current focus? I have do this programatically .
Windows knows this because the listcontrol receives the CTRL+C message and the control itself knows which item(s) has been selected.
If you tell us what you are actually trying to accomplish we may be able to suggest a solution.
Re: Finding the HWND which has the focus
Hi Arjay,
I want to find the path of the selected file.
The user can select a file in the desktop and also on the explorer.
But I want to get the path of the file which has the focus.
Sujay
Re: Finding the HWND which has the focus
The hwnd to the window in focus isn't going to help because the best you can do is get the hwnd to the listcontrol containing the selected file, but not the selected file itself.
What you need to do is to register for a shell change event. This will tell you when items have been selected or deselected. See this link http://msdn.microsoft.com/en-us/libr...20(VS.85).aspx. At the bottom of the link there is another link to an sdk sample called "Change Notify Watcher Sample". Once you get the notification you should be able to retrieve the path of the selected item with IShellLink:GetPath.