C#调用API周期性的显示某应用运行

日常中,我们可能关心某应用的运行结果,编写这个小程序目的就是设定时间周期性将某应用的运行呈现在桌面的最上方,以便我们显看。本程序呈现的是中金财富金融终端运行。
当不清楚某应用程序的接口名称时,可以使用VS中的spy++进行查看。如下图。
在这里插入图片描述
当找到parent window的caption后,可以使用api中的findwindow函数调用这个应用程序。
具体见下面代码:

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
        [DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
        private static extern void SetForegroundWindow(IntPtr hwnd);
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_CLOSE = 0xF060;
        const int SC_MINIMIZE = 0xF020;
        const int SC_MAXIMIZE = 0xF030;

        private void timer1_Tick(object sender, EventArgs e)
        {
            ii++;
            if (ii % 2 == 0)
            {
                this.TopMost = true;
                this.Show();
            }
            else 
            {
                this.TopMost = false;
                this.Hide();
                IntPtr mainHandle = FindWindow(null, "中金财富金融终端V9.02 - [版面-自选股]");
                    //FindWindow("Afx:00400000:3:00010003:00000010:00000000", "中金财富金融终端V9.02");
                if (mainHandle != null)
                {
                    SetForegroundWindow(mainHandle);
                    SendMessage(mainHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0); // 最大化
                }
            }
        }

源码:资源下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘二光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值