Sending a mouse click to a button in the taskbar using C#

前端 未结 4 2014
借酒劲吻你
借酒劲吻你 2021-01-05 10:45

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 BringWindo

相关标签:
4条回答
  • 2021-01-05 11:03

    I used this in a program where I needed to simulate clicks and mouse movements;

    Global Mouse and Keyboard Library

    0 讨论(0)
  • 2021-01-05 11:08

    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.

    Here's a bit on finding the window handle of the taskbar:

    http://www.codeproject.com/

    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. :)

    0 讨论(0)
  • 2021-01-05 11:12

    To be honest I've never had an issue bringing a window to the foreground on XP/Vista/2003/2000.

    You need to make sure you do the following:

    1. Check if IsIconic (minimized)
    2. If #1 results in true then call ShowWindow passing SW_RESTORE
    3. Then call SetForegroundWindow

    I've never had problems that I can think of doing it with those steps.

    0 讨论(0)
  • 2021-01-05 11:26

    Check out the section "How to steal focus on 2K/XP" at http://www.codeproject.com/KB/dialog/dlgboxtricks.aspx, as this is exactly what you need. I wouldn't go the taskbar route as the taskbar could be hidden or simply not there.

    0 讨论(0)
提交回复
热议问题