0

I was trying to prevent applications from stealing focus and flashing with the taskbar. There's, unfortunatelly, no clean winapi approach to this, but this post on SuperUser describes how to hook WinApi function calls with his own (dummy) functions.

That looks really good, but since I have already started a java project, I'll need to port this code somehow - though I really regret I'm not using C++.

Therefore I need to know how to apply my user-defined functions to the target window. How to hook winapi methods from java?

Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • http://stackoverflow.com/questions/2172520/how-to-use-winapi-functions-in-java might give you an idea? – Chief Wiggum Feb 18 '15 at 02:43
  • 1
    Theoretically, the windows API *already* prevents applications from stealing focus. What are you trying to do? – user253751 Feb 18 '15 at 02:44
  • I'm not absolutely certain that this is impossible. I am absolutely certain that it would be a bad idea. Use C/C++. :-) – Harry Johnston Feb 18 '15 at 06:12
  • 1
    You are clearly choosing the wrong solution to your actual problem – David Heffernan Feb 18 '15 at 08:04
  • Wonderfully useless comment guys. There is no reason what I'm doing would be a bad idea or impossible. Windows API doesn't prevent taskbar flashing or stealing focus. – Tomáš Zato Feb 18 '15 at 11:17
  • [Yes, the Windows API](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx) [does prevent focus stealing.](http://blogs.msdn.com/b/oldnewthing/archive/2009/02/20/9435239.aspx) If a program that wasn't started by the one you're currently running is stealing focus, then *that program* is the one misbehaving and finding a way to bypass activation protection. (People like to misbehave.) I don't know where the "useless comments" are coming from, but there is always a reason that something can be a bad idea, usually because there can be a better solution. – andlabs Feb 18 '15 at 18:59
  • 1
    So what we want to know (and what @immibis's comment means) is: what scenario is causing what program to steal focus, and how was that program started? And what's wrong with taskbar flashing? How are you trying to use (key word) this program that even the taskbar flashing (the normal, correct way a program requests attention on Windows, and thus the preferred alternative to focus stealing) is undesirable? I can't say why for the people telling you to not use Java, as I personally have no hooking experience (by choice). They should be able to explain better... – andlabs Feb 18 '15 at 19:03
  • As you could see in the vote-count of the question I linked to, I'm not the only one who's trying to prevent taskbar flashing. As of my particular case and reasons - frankly, it's none of your business and not relevant to the answer. But I'm automating an application which normally requests attention for some tasks. As tasks are automated, attention is not needed. – Tomáš Zato Feb 18 '15 at 20:19

0 Answers0