برسی on top بودن یک برنامه ؟ - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

برسی on top بودن یک برنامه ؟

0 امتیاز

سلام , دوستان من توی این لینک در خواست کردم که چطوری میشه فهمید که یک برنامه روی تمام برنامه های دیگه قرار داره ؟ ولی متاسفانه 1 نفر بیشتر جواب نداد! که اونم گیجم کردfrown حالا بگذریم : کد برنامه ای که با توابع api آن تاپ بودن یک برنامه رو برسی میکنه؟ ممنون. 

سوال شده فروردین 28, 1393  بوسیله ی daniyaltjm (امتیاز 840)   47 88 103

1 پاسخ

+1 امتیاز
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
        [DllImport("user32.dll")]
        static extern IntPtr GetActiveWindow();
        Timer timer=new Timer();
        public Form1()
        {
            InitializeComponent();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 200;
            timer.Start();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            IntPtr hwnd = FindWindow("NotePad", "NotePad");
            IntPtr ActiveHandle = GetActiveWindow();
            if (hwnd==ActiveHandle)
            {
                timer.Stop();
                MessageBox.Show("NotePad on top");   
            }
             
        }
    }

 

پاسخ داده شده فروردین 28, 1393 بوسیله ی PSPCoder (امتیاز 1,301)   14 40 57
تنکیو کار کرد  فقط خط 22 باید اینطوری بشه timer1.Stop();
متاسفانه کار نکرد!!! برای هر چیزی که روش کلیک میکنیم پاسخ میده!!!
این هم برنامه که خودم نوشتم گزینه ویرایش نبود مجبور شدم اینجا بزارمش شرمنده!!! فقط نمیدونم چرا با تابع GetActiveWindow کار نمیکنه!!!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class FormMain : Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        public  static extern IntPtr FindWindow(string LpClassName, string LpWindowName);
        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();


        public FormMain()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr find = FindWindow("Notepad", null);
            IntPtr act = GetForegroundWindow();
           
            if(find  == act )
            {
                label1.Text = "نوت پد روی تمام پنجره ها است";
            }
            else
            {
                label1.Text ="نوت پد روی تمام پنجره ها نیست";
  
            }
        }

        

        
    }
}
...