<p>In an application that I am currently working on, a requirement is to bring a window of an external application to the foreground.  Making Win32 API calls such as BringWindowToTop and SetForeground window do not work all the time.  This is due to some restrictions within Windows XP.  What I would like to do instead is send simulate a mouse click the window's button on the taskbar which I am hoping will bring the window to the front.  Does anyone know how this is possible?</p>

[{'answer_id': 18520, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s possible. But it\'s extremely sketchy. Your application may also break with the next version of Windows, since it\'s undocumented. What you need to do is find the window handle of the taskbar, then find the window handle of the child window representing the button, then send it a WM_MOUSEDOWN (I think) message.</p>\n\n<p>Here\'s a bit on finding the window handle of the taskbar:</p>\n\n<p><a href="http://www.codeproject.com/KB/miscctrl/hide_vista_start_orb.aspx" rel="nofollow noreferrer">http://www.codeproject.com/</a></p>\n\n<p>FWIW, the restrictions on BringWindowToTop/SetForeground are there because it\'s irritating when a window steals focus. That may not matter if you\'re working on a corporate environment. Just keep it in mind. :)</p>\n'}, {'answer_id': 18521, 'author': 'Nelson Miranda', 'author_id': 1130097, 'author_profile': 'https://Stackoverflow.com/users/1130097', 'pm_score': 1, 'selected': False, 'text': '<p>I used this in a program where I needed to simulate clicks and mouse movements; </p>\n\n<p><a href="http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx" rel="nofollow noreferrer">Global Mouse and Keyboard Library</a></p>\n'}, {'answer_id': 18544, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 1, 'selected': False, 'text': "<p>To be honest I've never had an issue bringing a window to the foreground on XP/Vista/2003/2000. </p>\n\n<p>You need to make sure you do the following:</p>\n\n<ol>\n<li>Check if IsIconic (minimized)  </li>\n<li>If #1 results in true then call\nShowWindow passing SW_RESTORE </li>\n<li>Then call SetForegroundWindow</li>\n</ol>\n\n<p>I've never had problems that I can think of doing it with those steps. </p>\n"}, {'answer_id': 18756, 'author': 'Joel Lucsy', 'author_id': 645, 'author_profile': 'https://Stackoverflow.com/users/645', 'pm_score': 3, 'selected': True, 'text': '<p>Check out the section "How to steal focus on 2K/XP" at <a href="http://www.codeproject.com/KB/dialog/dlgboxtricks.aspx" rel="noreferrer">http://www.codeproject.com/KB/dialog/dlgboxtricks.aspx</a>, as this is exactly what you need. I wouldn\'t go the taskbar route as the taskbar could be hidden or simply not there.</p>\n'}]
['https://Stackoverflow.com/questions/18505', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/324/']