0

Previously, I asked this question about returning the user to the previous window they were using, but I have found the solution, but it has created another problem. The function that determines the previous window will sometimes work (if a certain set of events happen that I cannot recreate at will, but happens randomly). At some point it goes 2 windows back, sometimes 1 window back. It does this because the taskbar is in the way first, and then there is the window.

So, in order to fix this, I have determined that I should keep going through the previous windows until I get to a window that is not the taskbar, however, I do not know how to determine the IntPtr of the taskbar.

I have tried:

IntPtr taskBarWnd = FindWindow("Shell_TrayWnd", null);

But it doesn't seem to work. If I call MessageBox.Show(taskBarWnd.ToInt64().ToString()), I get 131258, but when I do:

IntPtr thisWnd = GetForegroundWindow();
IntPtr lastWnd = GetWindow(thisWnd, 2);

It is referencing the taskbar, but when I call the same MessageBox function above, it returns 131260 (65774 if the icon is within the hidden icons area).

Does anyone know if there is anything else I can try to determine if the lastWnd I have calculated is the taskbar? I would prefer not to have something that checks if the IntPtr's are close to each other instead of being equal.

Community
  • 1
  • 1
topherg
  • 4,203
  • 4
  • 37
  • 72
  • I'm not sure, but perhaps you could try to check if the window belongs to "explorer.exe" process, something like that, cuz the taskbar is managed by this process if I'm not wrong (it's been a while since I didn't dig into that kind of stuff) – ppetrov Apr 17 '13 at 01:14
  • ah, sounds like a good thought. How would I find that out though (a quick google search yielded little, but i think that comes down to not knowing the right words) – topherg Apr 17 '13 at 01:16
  • ah, nevermind, got it :) – topherg Apr 17 '13 at 01:27
  • by `IntPtr` I'm sure you mean `window handle`. – Sam Axe Apr 17 '13 at 01:39
  • I'm sure I probably do, I just didn't know that was the proper name for it – topherg Apr 17 '13 at 01:43
  • sorry don't have much more clues right now, did you get it work with what you found? – ppetrov Apr 17 '13 at 02:52
  • What do you mean by FindWindow("Shell_TrayWnd", null); doesn't seem to work? Does this call return null? – Flot2011 Apr 17 '13 at 06:22
  • You're trying to solve the problem the wrong way around. Focus on the original question, not implementing the hack you've devised. – Cody Gray - on strike Apr 17 '13 at 07:01

1 Answers1

0

I can't check right now since this is my iPad, but I'm pretty sure the taskbar windows all use custom window classes so you should be able to call GetClassName and figure out from the result what your handle refers to.