systan
asked on
get the path of an opened window before paste
Get the path of an opened window before paste;
Sample,
When I paste files to desktop, it message > The path before paste
is: C:\Documents and Settings\Administrator\Des ktop\
When I paste files to my documents folder, it message > The path before paste
is: C:\Documents and Settings\Administrator\My Documents\
Sample,
When I paste files to desktop, it message > The path before paste
is: C:\Documents and Settings\Administrator\Des
When I paste files to my documents folder, it message > The path before paste
is: C:\Documents and Settings\Administrator\My Documents\
ShellBrowserWindow has HWND property. You could compare handle from GetForegroundWindow with it.
ASKER
Don't know how to apply, please help, a code snippet would be great.
ASKER
GetForegroundWindow Can't handle it, even GetLastActivePopup.
There must be a way to get the current or last folder opened.
There must be a way to get the current or last folder opened.
ASKER
//Shell32 is located in Interop.Shell32 assembly
Shell32.ShellClass shell = new ShellClass();
//Shellwindows is located in SHDocVw.dll under C:\windows
ShellWindows shellWindows = (ShellWindows)shell.Window s();
foreach (ShellBrowserWindow shellWindow in shellWindows)
{
//This is the object that holds Explorer window information.
ShellFolderView view = (ShellFolderView)shellWind ow.Documen t;
//Get ALL currently active windows path
MessageBox.Show(view.Focus edItem.Pat h);
}
The problem is, is ALL, it list all, BUT I want to get ONLY the last active window.
Please, someone, help, it's very impossible that a longtime experts here did not encounter this.
I already provided the code snippet, just a little line to solve the problem.
Shell32.ShellClass shell = new ShellClass();
//Shellwindows is located in SHDocVw.dll under C:\windows
ShellWindows shellWindows = (ShellWindows)shell.Window
foreach (ShellBrowserWindow shellWindow in shellWindows)
{
//This is the object that holds Explorer window information.
ShellFolderView view = (ShellFolderView)shellWind
//Get ALL currently active windows path
MessageBox.Show(view.Focus
}
The problem is, is ALL, it list all, BUT I want to get ONLY the last active window.
Please, someone, help, it's very impossible that a longtime experts here did not encounter this.
I already provided the code snippet, just a little line to solve the problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Error 1 The name 'WinEventProc' does not exist in the current context ?
ASKER
Ok, I've made some research, here it is;
http://social.msdn.microsoft.com/Forums/en/vcmfcatl/thread/0dbbc02e-cfd1-4183-a252-c1e9d6166fd8
http://social.msdn.microsoft.com/Forums/en/clr/thread/c04e343f-f2e7-469a-8a54-48ca84f78c28
http://ctp.social.msdn.microsoft.com/Forums/en-US/winforms/thread/30ae2081-17ed-497a-942e-efb75bca6295
The problem is?, it only gets the title of the window by getText, i'LL try to see if there is a fix, please help also.
Please note, that I am getting the LAST/current path of last/current explored window.
Thanks
http://social.msdn.microsoft.com/Forums/en/vcmfcatl/thread/0dbbc02e-cfd1-4183-a252-c1e9d6166fd8
http://social.msdn.microsoft.com/Forums/en/clr/thread/c04e343f-f2e7-469a-8a54-48ca84f78c28
http://ctp.social.msdn.microsoft.com/Forums/en-US/winforms/thread/30ae2081-17ed-497a-942e-efb75bca6295
The problem is?, it only gets the title of the window by getText, i'LL try to see if there is a fix, please help also.
Please note, that I am getting the LAST/current path of last/current explored window.
Thanks
ASKER
I think I got it,
thank you
thank you
Looks like I forgot to paste code for the event handler :o( . Sorry abuot that. Here it is:
static void WinEventProc(
IntPtr hWinEventHook, uint eventType,IntPtr hwnd, int idObject, int idChild,
uint dwEventThread, uint dwmsEventTime)
{
if (eventType == EVENT_SYSTEM_FOREGROUND)
{
int pid;
Process[] pc = Process.GetProcessesByName("explorer");
uint processID = 0;
uint threadID = GetWindowThreadProcessId(hwnd, out processID);
foreach (Process p in pc)
{
if (p.Id == processID) m_explHwnd = hwnd;
}
}
}
ASKER
This gets the path, BUT gets the last opened windows, if you switch from another windows to another?, the last windows opened still detected.
private string s;
private void button1_Click(object sender, EventArgs e)
{
//Shell32 is located in Interop.Shell32 assembly
Shell32.ShellClass shell = new ShellClass();
//Shellwindows is located in SHDocVw.dll under C:\windows
ShellWindows shellWindows = (ShellWindows)shell.Window
//Don't know how to apply this to shellWindow
////////IntPtr activeHwnd = GetForegroundWindow();
foreach (ShellBrowserWindow shellWindow in shellWindows)
{
//this is the path
s= shellWindow.LocationURL;
//This is the object that holds Explorer window information.
ShellFolderView view = (ShellFolderView)shellWind
//Add error handling and null checks here
foreach (FolderItem item in view.SelectedItems())
{
MessageBox.Show(item.Path.
}
}
label1.Text = s;
}