使用sendmessage函数模拟点击其他程序按钮事件

本文介绍了一种通过C#代码定位Windows任务栏开始按钮位置的方法。首先查找任务栏窗口,然后找到开始按钮,并获取其坐标。之后可以选择直接点击开始按钮或进行动画模拟。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 NativeRECT rect;
            IntPtr ptrTaskbar = FindWindow("Shell_TrayWnd", null);
            if (ptrTaskbar == IntPtr.Zero)
            {
                MessageBox.Show("No taskbar found.");
                return;
            }
            IntPtr ptrStartBtn = FindWindowEx(new HandleRef(this, ptrTaskbar), new HandleRef(this, IntPtr.Zero), "Button", null);
            if (ptrStartBtn == IntPtr.Zero)
            {
                MessageBox.Show("No start button found.");
                return;
            }
            GetWindowRect(new HandleRef(this, ptrStartBtn), out rect);
            endPosition.X = (rect.left + rect.right) / 2;
            endPosition.Y = (rect.top + rect.bottom) / 2;
            if (chkAnimation.Checked)
            {
            //    this.count = AnimationCount;
           //     movementTimer.Start();
            }
            else
            {
                SetCursorPos(endPosition.X, endPosition.Y);
                mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
                mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值