日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# 获得窗体句柄并发送消息(利用windows API可在不同进程中获取)

發布時間:2023/12/18 C# 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 获得窗体句柄并发送消息(利用windows API可在不同进程中获取) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?C#使用Windows API獲取窗口句柄控制其他程序窗口

編寫程序模擬鼠標和鍵盤操作可以方便的實現你需要的功能,而不需要對方程序為你開放接口。比如,操作飛信定時發送短信等。我之前開發過飛信耗子,用的是對飛信協議進行抓包,然后分析協議,進而模擬協議的執行,開發出了客戶端,與移動服務器進行通信,但是這有一些缺點。如果移動的服務器對接口進行變更,我所編寫的客戶端也要進行相應的升級。如果服務器的協議進行了更改,甚至個人編寫的這種第三方客戶端需要重寫。而我個人也沒有這個時間和精力,或者說沒有足夠的利益支撐我繼續去重構飛信耗子。因此,這款還算優秀的軟件,現在就束之高閣了,我自己也覺得遺憾。上周,某項目驗收,需要修改界面,但是零時找不到源碼了。我在兩三個小時內要解決這個問題,時間緊迫。我突然想起室友以前做過模擬鼠標鍵盤去發送飛信消息的小程序。于是我趕緊電話咨詢了一下。然后掌握了這個技巧,按時解決了問題。我覺得這個技巧還是很有用的,現總結如下:

首先,引入如下三個API接口:

?
  • [DllImport("user32.dll")]
  • public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  • ?
  • [DllImport("User32.dll", EntryPoint = "SendMessage")]
  • private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, stringlParam);
  • ?
  • [DllImport("User32.dll ")]
  • public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string FrmText);
  • 第一個與第三個是用于查找窗口句柄的,凡運行于Windows上的窗口,都具有句柄。窗口上的文本框,按鈕之類的,也有其句柄(可看作子窗口句柄)。這些句柄的類型可以通過

    Spy++進行查詢。比如C語言編寫的程序中,文本框的句柄類型一般為“EDIT”,C#寫的程序則不是,可以具體去查。第二個接口則是用于向窗口發送各種消息,比如向文本框發送

    字符串,或者向按鈕發送按下與彈起的消息等。詳細解釋如下:

    ?
  • IntPtr hwnd = FindWindow(null, "無標題 - 記事本");? ? ?//不同進程也可使用此API查找其他進程下的窗體
  • 這是用于查找操作系統中打開的窗口中標題名為無標題 - 記事本的窗口。第一個參數是此窗口的類型。這兩個參數知道一

    個即可,另一個可以填null。但是如果是用窗口類型查找,則可能只能得到其中的一個窗口。因此通過標題進行查找是非常方便的。

    ?
  • IntPtr htextbox = FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
  • 這個函數用于獲得窗口中子窗口的句柄,子窗口指的其實就是窗口中的各種控件。第一個參數是父窗口的句柄,第二個參數指示獲得的是同一類型中的第幾個子窗口。填

    IntPtr.Zero則表示獲得第一個子窗口。第三個參數表示你需要找的子窗口的類型,第四個參數一般為null。如果一個窗口中有兩個文本框,那么可以用如下操作獲得第二個文本框

    的句柄。

    ?
  • IntPtr htextbox = FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
  • IntPtr htextbox2 = FindWindowEx(hwnd, htextbox, "EDIT", null);//填上次獲得的句柄,可以得到下一個的句柄。
  • 這里只是先將第二個參數填為IntPtr.Zero,獲取第一個EDIT類型的文本框,然后第二次調用時,再將第二參數填為第一個文本框的句柄,那么執行返回的就是下一個文本框的句柄

    了。因此htextbox2得到的就是第二文本框的句柄。
    在可以自由獲得各種窗口及其上控件的句柄后,我們就可以向其發送各種消息進行鼠標和鍵盤的模擬了。比如:

    ?
  • SendMessage(htextbox, WM_SETTEXT, IntPtr.Zero, name);
  • 這句是為文本框填寫相應的字符串name。

    ?
  • IntPtr hbutton = FindWindowEx(hwnd, IntPtr.Zero, "BUTTON", null);
  • SendMessage(hbutton, WM_LBUTTONDOWN, IntPtr.Zero, null);
  • SendMessage(hbutton, WM_LBUTTONUP, IntPtr.Zero, null);
  • 這三句是獲得了窗口的一個button,然后發送按下,彈起消息給它,模擬了點擊鼠標的動作。
    SendMessage函數的第一個參數是窗口句柄,或者窗口中控件的句柄,第二個參數是消息的類型Flag,這些值是在API的一些頭文件中定義好的。你要是在C#中用,就自己去定義他們,比如

    ?
  • constint WM_SETTEXT =0x000C;
  • constint WM_LBUTTONDOWN =0x0201;
  • constint WM_LBUTTONUP =0x0202;
  • constint WM_CLOSE =0x0010;
  • 還有其他的類型Flag,可以參考上一篇Blog查詢,也可以去查MSDN。第三個參數和第四個參數都是消息的具體內容。一般我們用的是最后一個參數。第三個參數填為IntPtr.Zero。

    當然如果是鼠標的動作,那么最后一個參數就是null。

    ?
  • SendMessage(htextbox, WM_SETTEXT, IntPtr.Zero, name);//填寫文本框。
  • SendMessage(hbutton, WM_LBUTTONDOWN, IntPtr.Zero, null);//鼠標按下按鈕
  • //******************************

    ???在項目中有這樣的需求,在主窗體隱藏時或者主進程運行時對其它窗體的控件或者事件進行控制,而且其它窗體是處于活動狀態,而主窗體或者主進程是隱藏在后面的。這個時候使用句柄和消息來處理就比較好解決這些問題了,當然了也可以使用其它方法。比如將其它窗體在主窗體中申明并且定義,使之和主窗體一樣一直存在于內存中,在各個窗體中申明公共方法,在主進程需要調用時直接調用即可,但是這樣耗費了大量的系統資源。現在使用消息來解決這個問題。下面提供一個小程序,在主窗體中通過句柄和消息來控制子窗體中Label上文字變化和顏色,代碼如下:

    ?

    Windowns的API類

    using?System;
    using?System.Runtime.InteropServices;

    namespace?TestHwnd
    {
    ????public?class?Win32API
    ????{
    ?????????[DllImport("user32.dll ",?CharSet = CharSet.Unicode)]
    ????????public?static?extern?IntPtr?PostMessage(IntPtr hwnd,?int?wMsg,?string?wParam,?string?lParam);

    ????}

    }

    ?

    主窗體程序(發送消息):

    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?TestHwnd
    {
    ????public?partial?class?Main : Form
    ????{

    ????????//定義了一個子窗體的句柄
    ????????public?IntPtr hwndfrmTest;
    ????????

    ????????public?Main()
    ????????{
    ????????????InitializeComponent();
    ????????}

    ?????

    ????????private?void?timer1_Tick(object?sender,?EventArgs e)
    ????????{

    ????????????if(hwndfrmTest!=(IntPtr)0)
    ????????????{
    ????????????????if(DateTime.Now.Second?%?3?==?0)
    ????????????????{
    ????????????????????Win32API.PostMessage(hwndfrmTest,?0x60,?"",?"");
    ????????????????}
    ????????????????
    ????????????????if(DateTime.Now.Second?%?5?==?0)
    ????????????????{
    ????????????????????Win32API.PostMessage(hwndfrmTest,?0x61,?"",?"");
    ????????????????}
    ????????????????
    ????????????}
    ????????????
    ????????}


    ????????void?Button2Click(object?sender,?EventArgs e)
    ????????{
    ????????????frmTest frm=new?frmTest();
    ????????????frm.Show(this);
    ????????}
    ????}

    子窗體程序(接收消息)

    using?System;
    using?System.Drawing;
    using?System.Windows.Forms;

    namespace?TestHwnd
    {
    ?????///??<summary>
    ?????///??Description of frmTest.
    ?????///??</summary>
    ?????public??partial??class?frmTest : Form
    ????{
    ????????Main main;
    ?????????public??frmTest()
    ????????{
    ?????????????//
    ?????????????// The InitializeComponent() call is required for Windows Forms designer support.
    ?????????????//
    ?????????????InitializeComponent();
    ????????????
    ?????????????//
    ?????????????//?TODO: Add constructor code after the InitializeComponent() call.
    ?????????????//
    ????????}
    ????????
    ?????????void??FrmTest_Load(?object?sender,?EventArgs e)
    ????????{
    ????????????main =?this.Owner?as?Main;

    ?????????????//初始化該窗體的句柄

    ????????????main.hwndfrmTest =??this.Handle;
    ????????}
    ????????
    ?????????///?重寫窗體的消息處理函數DefWndProc,從中加入自己定義消息 MYMESSAGE 的檢測的處理入口
    ?????????protected??override??void??DefWndProc(?ref?Message m)
    ????????{
    ?????????????switch?(m.Msg)
    ????????????{
    ?????????????????case??0x60:
    ????????????????????{
    ????????????????????????label1.ForeColor=Color.Red;
    ????????????????????????label1.Text = DateTime.Now.?ToString()?+??"-"?+??"測試成功。。。。,呵呵,變紅了";
    ????????????????????}
    ?????????????????????break;
    ?????????????????case??0x61:
    ????????????????????{
    ????????????????????????label1.ForeColor=Color.Blue;
    ????????????????????????label1.Text = DateTime.Now.?ToString()?+??"-"?+??"測試成功。。。。,呵呵,變藍了";
    ????????????????????}
    ?????????????????????break;
    ?????????????????default:
    ?????????????????????base.?DefWndProc(?ref?m);
    ?????????????????????break;
    ????????????}
    ????????}
    ????????
    ????????
    ????????
    ?????????void??Button1Click(?object?sender,?EventArgs e)
    ????????{
    ????????????????main.hwndfrmTest =?(IntPtr)?(?0);
    ?????????????this.?Close();
    ????????}
    ????}
    }

    //******************************************

    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;
    using System.IO;
    ?
    namespace findWindowTest
    {
    ? ? public partial class Form1 : Form
    ? ? {
    ? ? ? ? public Form1()
    ? ? ? ? {
    ? ? ? ? ? ? InitializeComponent();
    ? ? ? ? }
    ?
    ? ? ? ? // Find Window
    ? ? ? ? // 查找窗體
    ? ? ? ? // @para1: 窗體的類名 例如對話框類是"#32770"
    ? ? ? ? // @para2: 窗體的標題 例如打開記事本 標題是"無標題 - 記事本" 注意 - 號兩側的空格
    ? ? ? ? // return: 窗體的句柄
    ? ? ? ? [DllImport("User32.dll", EntryPoint = "FindWindow")]
    ? ? ? ? public static extern IntPtr FindWindow(string className, string windowName);
    ? ? ? ?
    ? ? ? ?
    ? ? ? ?
    ? ? ? ?
    ? ? ? ?
    ? ? ? ? // Find Window Ex
    ? ? ? ? // 查找窗體的子窗體
    ? ? ? ? // @para1: 父窗體的句柄 如果為null,則函數以桌面窗口為父窗口,查找桌面窗口的所有子窗口
    ? ? ? ? // @para2: 子窗體的句柄 如果為null,從@para1的直接子窗口的第一個開始查找
    ? ? ? ? // @para3: 子窗體的類名 為""表示所有類
    ? ? ? ? // @para4: 子窗體的標題 為""表示要查找的窗體無標題 如空白的textBox控件
    ? ? ? ? // return: 子窗體的句柄
    ? ? ? ? [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
    ? ? ? ? private static extern IntPtr FindWindowEx(
    ? ? ? ? ? ? IntPtr hwndParent,
    ? ? ? ? ? ? IntPtr hwndChildAfter,
    ? ? ? ? ? ? string lpszClass,
    ? ? ? ? ? ? string lpszWindow);
    ?
    ? ? ? ? // SendMessage
    ? ? ? ? // 向窗體發送消息
    ? ? ? ? // @para1: 窗體句柄
    ? ? ? ? // @para2: 消息類型
    ? ? ? ? // @para3: 附加的消息信息
    ? ? ? ? // @para4: 附加的消息信息
    ? ? ? ? [DllImport("User32.dll", EntryPoint = "SendMessage")]
    ? ? ? ? private static extern int SendMessage(
    ? ? ? ? ? ? IntPtr hWnd,
    ? ? ? ? ? ? int Msg,
    ? ? ? ? ? ? IntPtr wParam,
    ? ? ? ? ? ? string lParam);
    ?
    ? ? ? ? // 消息類型(部分)
    ? ? ? ? const int WM_GETTEXT ? ? = 0x000D; ?// 獲得窗體文本 如獲得對話框標題
    ? ? ? ? const int WM_SETTEXT ? ? = 0x000C; ?// 設置窗體文本 如設置文本框內容
    ? ? ? ? const int WM_CLICK ? ? ? = 0x00F5; ?// 發送點擊消息如調用該窗體(按鈕)的"button1_Click();"
    ?
    ? ? ? ? // 本程序針對指定的另一程序窗體因此聲名了如下變量
    ? ? ? ? IntPtr Wnd ?= new IntPtr(0);// 一卡通注冊程序主窗體
    ? ? ? ? IntPtr sWnd = new IntPtr(0);// GroupBox控件 此為“一卡通注冊程序”主窗體的子窗體
    ? ? ? ? IntPtr txt ?= new IntPtr(0);// 文本框
    ? ? ? ? IntPtr btn1 = new IntPtr(0);// 查詢按鈕
    ? ? ? ? IntPtr btn2 = new IntPtr(0);// 注冊按鈕 這三個窗體又為“GroupBox控件”的子窗體
    ? ? ? ? //IntPtr popW = new IntPtr(0);// 彈出對話框
    ? ? ? ? //IntPtr popB = new IntPtr(0);// 彈出對話框確定按鈕
    ?
    ? ? ? ? // 文件操作
    ? ? ? ? private String filename = string.Empty;
    ? ? ? ? private StreamReader reader = null;
    ?
    ? ? ? ? // 從“打開文件”對話框打開txt文件 同時獲得需要的窗口句柄
    ? ? ? ? private void button2_Click(object sender, EventArgs e)
    ? ? ? ? {
    ? ? ? ? ? ? label2.Text = "";
    ? ? ? ? ? ? openFileDialog1.DefaultExt = "txt";
    ? ? ? ? ? ? openFileDialog1.Filter = "文本文件|*.txt";
    ? ? ? ? ? ? openFileDialog1.RestoreDirectory = true;
    ? ? ? ? ? ? openFileDialog1.FilterIndex = 1;
    ? ? ? ? ? ? if (openFileDialog1.ShowDialog() == DialogResult.OK)
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? filename = openFileDialog1.FileName;
    ? ? ? ? ? ? }
    ?
    ? ? ? ? ? ? // 獲得窗口句柄
    ? ? ? ? ? ? Wnd ?= FindWindowEx((IntPtr)0, (IntPtr)0, null, "讀者一卡通注冊");// 一個注冊程序的窗體
    ? ? ? ? ? ? sWnd = FindWindowEx(Wnd, ?(IntPtr)0, null, "條件"); // 窗體上的一個GroupBox控件
    ? ? ? ? ? ? txt ?= FindWindowEx(sWnd, (IntPtr)0, null, ""); ? ? // GroupBox內的textBox控件
    ? ? ? ? ? ? btn1 = FindWindowEx(sWnd, (IntPtr)0, null, "查詢"); // GroupBox內的查詢按鈕
    ? ? ? ? ? ? btn2 = FindWindowEx(sWnd, (IntPtr)0, null, "注冊"); // GroupBox內的注冊按鈕
    ? ? ? ? }
    ?
    ? ? ? ? // 重復地把文件內讀取的行
    ? ? ? ? // 將該行發送給注冊程序窗體上的文本框中
    ? ? ? ? // 并“點擊”查詢按鈕和注冊按鈕
    ? ? ? ? // 直到文件讀取完畢
    ? ? ? ? private void button3_Click(object sender, EventArgs e)
    ? ? ? ? {
    ? ? ? ? ? ? //計數
    ? ? ? ? ? ? int count = 0;
    ?
    ? ? ? ? ? ? //讀取文件
    ? ? ? ? ? ? if (filename == string.Empty)
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? button2.Focus();
    ? ? ? ? ? ? ? ? return;
    ? ? ? ? ? ? }
    ?
    ? ? ? ? ? ? reader = new StreamReader(filename);
    ? ? ? ? ? ? if (reader.EndOfStream)
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? return;
    ? ? ? ? ? ? }
    ?
    ? ? ? ? ? ? string str = string.Empty;
    ?
    ? ? ? ? ? ? do
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? //讀取學號 保存在變量str中
    ? ? ? ? ? ? ? ? str = reader.ReadLine();
    ?
    ? ? ? ? ? ? ? ? //設置學號
    ? ? ? ? ? ? ? ? SendMessage(txt, WM_SETTEXT, (IntPtr)0, str);
    ?
    ? ? ? ? ? ? ? ? //點擊查詢按鈕
    ? ? ? ? ? ? ? ? SendMessage(btn1, WM_CLICK, (IntPtr)0, "");
    ?
    ? ? ? ? ? ? ? ? //點擊注冊按鈕
    ? ? ? ? ? ? ? ? SendMessage(btn2, WM_CLICK, (IntPtr)0, "");
    ?
    ? ? ? ? ? ? ? ? count++;
    ? ? ? ? ? ? }
    ? ? ? ? ? ? while(!reader.EndOfStream);
    ?
    ? ? ? ? ? ? reader.Close();
    ? ? ? ? ? ? filename = string.Empty;
    ? ? ? ? ? ? label1.Text = "注冊人數:";
    ? ? ? ? ? ? label2.Text = Convert.ToString(count);
    ? ? ? ? }
    ? ? }
    }


    //******************************

    C#獲取進程的主窗口句柄

    通過調用Win32 API實現。

    ?

    public?class?User32API
    {
    ????private?static?Hashtable?processWnd?=?null;

    ????public?delegate?bool?WNDENUMPROC(IntPtr?hwnd,?uint?lParam);

    ????static?User32API()
    ????{
    ????????if?(processWnd?==?null)
    ????????{
    ????????????processWnd?=?new?Hashtable();
    ????????}
    ????}

    ????[DllImport("user32.dll",?EntryPoint?=?"EnumWindows",?SetLastError?=?true)]
    ????public?static?extern?bool?EnumWindows(WNDENUMPROC?lpEnumFunc,?uint?lParam);

    ????[DllImport("user32.dll",?EntryPoint?=?"GetParent",?SetLastError?=?true)]
    ????public?static?extern?IntPtr?GetParent(IntPtr?hWnd);

    ????[DllImport("user32.dll",?EntryPoint?=?"GetWindowThreadProcessId")]
    ????public?static?extern?uint?GetWindowThreadProcessId(IntPtr?hWnd,?ref?uint?lpdwProcessId);

    ????[DllImport("user32.dll",?EntryPoint?=?"IsWindow")]
    ????public?static?extern?bool?IsWindow(IntPtr?hWnd);

    ????[DllImport("kernel32.dll",?EntryPoint?=?"SetLastError")]
    ????public?static?extern?void?SetLastError(uint?dwErrCode);

    ????public?static?IntPtr?GetCurrentWindowHandle()
    ????{
    ????????IntPtr?ptrWnd?=?IntPtr.Zero;
    ????????uint?uiPid?=?(uint)Process.GetCurrentProcess().Id;??//?當前進程?ID
    ????????object?objWnd?=?processWnd[uiPid];

    ????????if?(objWnd?!=?null)
    ????????{
    ????????????ptrWnd?=?(IntPtr)objWnd;
    ????????????if?(ptrWnd?!=?IntPtr.Zero?&&?IsWindow(ptrWnd))??//?從緩存中獲取句柄
    ????????????{
    ????????????????return?ptrWnd;
    ????????????}
    ????????????else
    ????????????{
    ????????????????ptrWnd?=?IntPtr.Zero;
    ????????????}
    ????????}

    ????????bool?bResult?=?EnumWindows(new?WNDENUMPROC(EnumWindowsProc),?uiPid);
    ????????//?枚舉窗口返回?false?并且沒有錯誤號時表明獲取成功
    ????????if?(!bResult?&&?Marshal.GetLastWin32Error()?==?0)
    ????????{
    ????????????objWnd?=?processWnd[uiPid];
    ????????????if?(objWnd?!=?null)
    ????????????{
    ????????????????ptrWnd?=?(IntPtr)objWnd;
    ????????????}
    ????????}

    ????????return?ptrWnd;
    ????}

    ????private?static?bool?EnumWindowsProc(IntPtr?hwnd,?uint?lParam)
    ????{
    ????????uint?uiPid?=?0;

    ????????if?(GetParent(hwnd)?==?IntPtr.Zero)
    ????????{
    ????????????GetWindowThreadProcessId(hwnd,?ref?uiPid);
    ????????????if?(uiPid?==?lParam)????//?找到進程對應的主窗口句柄
    ????????????{
    ????????????????processWnd[uiPid]?=?hwnd;???//?把句柄緩存起來
    ????????????????SetLastError(0);????//?設置無錯誤
    ????????????????return?false;???//?返回?false?以終止枚舉窗口
    ????????????}
    ????????}

    ????????return?true;
    ????}
    }

    ?

    調用User32API.GetCurrentWindowHandle()即可返回當前進程的主窗口句柄,如果獲取失敗則返回IntPtr.Zero。

    --EOF--

    ?

    2008年10月7日補充:微軟實現的獲取進程主窗口句柄代碼


    public?class?MyProcess
    {
    ????private?bool?haveMainWindow?=?false;
    ????private?IntPtr?mainWindowHandle?=?IntPtr.Zero;
    ????private?int?processId?=?0;

    ????private?delegate?bool?EnumThreadWindowsCallback(IntPtr?hWnd,?IntPtr?lParam);

    ????public?IntPtr?GetMainWindowHandle(int?processId)
    ????{
    ????????if?(!this.haveMainWindow)
    ????????{
    ????????????this.mainWindowHandle?=?IntPtr.Zero;
    ????????????this.processId?=?processId;
    ????????????EnumThreadWindowsCallback?callback?=?new?EnumThreadWindowsCallback(this.EnumWindowsCallback);
    ????????????EnumWindows(callback,?IntPtr.Zero);
    ????????????GC.KeepAlive(callback);

    ????????????this.haveMainWindow?=?true;
    ????????}
    ????????return?this.mainWindowHandle;
    ????}

    ????private?bool?EnumWindowsCallback(IntPtr?handle,?IntPtr?extraParameter)
    ????{
    ????????int?num;
    ????????GetWindowThreadProcessId(new?HandleRef(this,?handle),?out?num);
    ????????if?((num?==?this.processId)?&&?this.IsMainWindow(handle))
    ????????{
    ????????????this.mainWindowHandle?=?handle;
    ????????????return?false;
    ????????}
    ????????return?true;
    ????}

    ????private?bool?IsMainWindow(IntPtr?handle)
    ????{
    ????????return?(!(GetWindow(new?HandleRef(this,?handle),?4)?!=?IntPtr.Zero)?&&?IsWindowVisible(new?HandleRef(this,?handle)));
    ????}

    ????[DllImport("user32.dll",?CharSet?=?CharSet.Auto,?SetLastError?=?true)]
    ????public?static?extern?bool?EnumWindows(EnumThreadWindowsCallback?callback,?IntPtr?extraData);

    ????[DllImport("user32.dll",?CharSet?=?CharSet.Auto,?SetLastError?=?true)]
    ????public?static?extern?int?GetWindowThreadProcessId(HandleRef?handle,?out?int?processId);

    ????[DllImport("user32.dll",?CharSet?=?CharSet.Auto,?ExactSpelling?=?true)]
    ????public?static?extern?IntPtr?GetWindow(HandleRef?hWnd,?int?uCmd);

    ????[DllImport("user32.dll",?CharSet?=?CharSet.Auto)]
    ????public?static?extern?bool?IsWindowVisible(HandleRef?hWnd);
    }

    總結

    以上是生活随笔為你收集整理的C# 获得窗体句柄并发送消息(利用windows API可在不同进程中获取)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 韩日av| 欧美日韩久久精品 | 精品无码久久久久国产 | 精品人妻二区中文字幕 | 99免费| 亚洲欧美国产高清va在线播放 | 57pao国产成永久免费视频 | 99爱视频 | 91视频精品 | 国模吧无码一区二区三区 | 在线看国产视频 | 成人精品 | 成人免费视频国产免费网站 | av导航站| 一本毛片 | 中国少妇高潮 | 性色一区二区 | 日韩人妻精品一区二区三区视频 | 中国一级特黄真人毛片免费观看 | 日韩欧美中文字幕一区 | 国产伦精品一区二区三区四区视频 | 亚洲一级二级片 | 无码人妻一区二区三区在线视频 | av在线中文| 日韩中文一区二区三区 | 精品美女一区 | 日本理论视频 | 色一情一伦一子一伦一区 | 国产偷国产偷av亚洲清高 | 亚洲成人黄色小说 | 国产精品不卡av | 久久久婷 | 国产精品激情 | 人人综合网 | 91精品综合久久久久久五月天 | 亚洲自啪 | 99久久毛片 | 狠狠干狠狠艹 | 精品影片一区二区入口 | 色视频在线看 | 国产精品久久久久久久免费观看 | 国产性在线 | 新呦u视频一区二区 | 亚洲精品美女网站 | 综合视频在线观看 | 国产日韩欧美日韩大片 | 欧美性大战久久久久久 | 国产精品一二三四 | 日韩淫| 日韩精品第三页 | 羞羞的网站在线观看 | 亚洲精品香蕉 | 在线免费av网址 | 国产午夜av| 国产在线观看网站 | 久久av无码精品人妻系列试探 | 中文字幕日产乱码中 | 91视频你懂的 | 肉丝肉足丝袜一区二区三区 | 亚洲一级影片 | 极度诱惑香港电影完整 | 久久99免费视频 | 成人毛片在线观看 | 欧美三级网站在线观看 | 欧美在线性爱视频 | xxxx18日本| 我爱52av| 国产社区在线 | 午夜视频在线免费观看 | av中文字幕免费观看 | 国产黄a三级三级三级看三级男男 | 色婷婷狠狠| 日韩Av无码精品 | 国产精品一区二区三区免费在线观看 | 欧美日本韩国 | 亚洲av成人精品一区二区三区在线播放 | 久久都是精品 | 四虎影视永久地址 | 欧美性做爰毛片 | 天天射干 | 日韩高清影视在线观看 | 国产成人精品一区二区三区免费 | av观看网| 久久久99国产精品免费 | 免费吃奶摸下激烈视频 | 操干网 | 亚洲中文一区二区三区 | www.欧美色 | 亚洲美女色视频 | 国产精品无码免费专区午夜 | 中文字幕dvd| 国产性猛交╳xxx乱大交 | 九九九九精品 | 成人高潮片免费视频 | 午夜精品久久久久久久久久 | 亚洲爆爽av | 日韩孕交 | 成年人福利| 欧美性猛交99久久久久99按摩 |