0

I have a Windows forms application, where I copy files from my filemanager between forms and also to windows environment. I have no problem with copying files to any kind of folders, except desktop. On my development environment this function works fine. GetWindowText(handle, Buff, nChars). It returns 0 which I thought it means that no window is focused, so the focus is on the desktop. I regret not saving the source where I got the code.

The problem is on clients server, where the function returns 15, so I cannot determine whether the desktop is focused or not. Is there any function that would for sure return the same value anywhere if the desktop is focused? Thanks in advance.

EDIT: code to check the matching handles
Dim handle As IntPtr = GetForegroundWindow()
Dim shellWindows As ShellWindows = Nothing
shellWindows = New SHDocVw.ShellWindows()

For Each window As InternetExplorer In shellWindows
If window.HWND = CInt(handle) Then
Do something
End If

Neyc
  • 1
  • 1
  • Maybe you could be interested to: ***GetActiveWindow*** and ***GetDesktopWindow*** https://learn.microsoft.com/it-it/windows/win32/api/winuser/nf-winuser-getactivewindow , https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdesktopwindow and to the following questions on SO https://stackoverflow.com/questions/466354/how-can-i-tell-if-a-window-has-focus-win32-api and https://stackoverflow.com/questions/115868/how-do-i-get-the-title-of-the-current-active-window-using-c – Diego D Jul 27 '22 at 09:47
  • 1
    GetWindowText has nothing to do with focus. – Klaus Gütter Jul 27 '22 at 09:47
  • @DiegoDeVita Thanks for suggestions, I eventually found a good source here as well: https://www.pinvoke.net/default.aspx/user32.GetActiveWindow The handle I get from function GetActiveWindow() is always 0, so I use function GetForegroundWindow(), but when I check if this handle matches with shellwindows handle, they never match. – Neyc Jul 27 '22 at 13:19
  • I managed to get it work by [this](https://stackoverflow.com/a/17712961/11446031) answer. – Neyc Jul 29 '22 at 06:25

0 Answers0