public void game()
        {
            int proID,proid1;
            proID = OpenProcess("PROCESS_VM_READ", false, Phandle);//它返回的是什么,我得到的总是0?
            //textBox2.Text = proID.ToString();
            proid1 = GetWindowThreadProcessId(Phandle,null);//它有返回值,可的返回的是进程ID,还是线程ID,或是哪个的句柄??
            //textBox3.Text = proid1.ToString();
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            Phandle = FindWindow("SciCalc", null);
            if (Phandle != 0)
            {
                label1.Text = "计算器运行!";
                game();
                textBox1.Text = Phandle.ToString();
                
            }
            else
            {
                label1.Text = "计算器未运行!";
                            }
        }

解决方案 »

  1.   

    PROCESS_VM_READ
    不是文本 ,有关是数值常量啊
      

  2.   

    const int PROCESS_VM_READ = 16;
      现在的人们要求越来越高!事情还是十画还没有一撇,就要源码!
      

  3.   

    const int PROCESS_VM_READ = 16;//它为什么要定义成16呢??定义成别的数不行吗。proID = OpenProcess("PROCESS_VM_READ", false, Phandle);//它返回的是什么,
    proid1 = GetWindowThreadProcessId(Phandle,null);//它有返回值,可的返回的是进程ID,还是线程ID,或是哪个的句柄??这两个返回的是什么值??
      

  4.   

    PROCESS_VM_READ是常量,值为0x10,也就是16,不是字符串
    OpenProcess成功的话返回process的句柄,否则返回null
    GetWindowThreadProcessId返回的是线程ID,第二个参数是接收进程ID的
    MSDN上都有
      

  5.   

    谢谢,MSDN是英文的,看了一下,没太明白。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
                
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            [DllImport("User32.dll")]
            public static extern int FindWindow(string s,string ss);        [DllImport("Kernel32.dll")]
            public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle,int dwProcessId);        [DllImport("user32.dll")]
            public static extern int GetWindowThreadProcessId(int hWnd,string lpdwProcessId);        public void game()
            {
                const int PROCESS_VM_READ = 16;
                int proID,proid1;
                proID = OpenProcess(16, false, Phandle);//这样不对吗,返回还是0
                textBox2.Text = proID.ToString();
                proid1 = GetWindowThreadProcessId(Phandle,null);
                textBox3.Text = proid1.ToString();
            }        public Form1()
            {
                InitializeComponent();
            }        int Phandle;
            private void button1_Click(object sender, EventArgs e)
            {
            }        private void Form1_Load(object sender, EventArgs e)
            {
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                Phandle = FindWindow("SciCalc", null);
                if (Phandle != 0)
                {
                    label1.Text = "计算器运行!";
                    game();
                    textBox1.Text = Phandle.ToString();
                                }
                else
                {
                    label1.Text = "计算器未运行!";
                                }
            }        private void textBox1_TextChanged(object sender, EventArgs e)
            {        }
        }
    }接触时间不常,问一下,private void textBox1_TextChanged(object sender, EventArgs e)像这样,我不用的,要怎么把它删掉?
      

  6.   

    proID = OpenProcess(PROCESS_VM_READ, false, Phandle);//这样也还是0
      

  7.   

    [DllImport("User32.dll", EntryPoint = "GetWindowThreadProcessId")]
    private static extern int GetWindowThreadProcessId(int hWnd, ref int ProcessId);int pid = 0;
    GetWindowThreadProcessId(Phandle, ref pid);//ProcessID存入pid
    int hProcess = OpenProcess(PROCESS_VM_READ, false, pid);private void textBox1_TextChanged(object sender, EventArgs e)之类的你可以在属性窗口里的事件里面删除
      

  8.   

    谢谢,可以了
    不点不明白
    EntryPoint = "GetWindowThreadProcessId为什么要加这个,我试了,不写也可以啊?