Tricky issue when I attempted to use JNA to bring a non-foreground window to foreground
<p>This has been confusing me for several weeks, but still I have no clue.
I tend to use JNA to implement automation on certain web page (only compatible with IE browser).</p>

<p>As the first step, I want raise a browser with specified url (say www.google.com)
and then 
1) find window by name 
2) use certain api to bring it the top</p>

<p>Here is the code </p>

<pre><code>    HWND window = user32.FindWindow(null, "${WINDOW NAME}");
    user32.ShowWindow(window, 1);
    User32.INSTANCE.SetForegroundWindow(window);
    User32.INSTANCE.GetForegroundWindow();
    User32.INSTANCE.MoveWindow(window, 7, 7, 777, 777, true);
</code></pre>

<p>The above code is invoked in a button's click event listener. 
However, after the browser initialized, nothing happened with the 1st click.
But window does appear and resize with 2nd click.</p>

<p>I've ever tried BringWindowToTop / SetWindowPos, neither works.</p>

<p>Anyway, I'm not familiar with Win Api.</p>

<p>Thanks in advance. </p>