C# 訊息發送

來源:互聯網
上載者:User

一、結構聲明<br /> public struct RecBoxMessage<br /> {<br /> public int RecID;<br /> }<br />二、API聲明<br />--------------<br />public class Win32API<br /> {<br /> /// <summary><br /> /// 發送訊息<br /> /// </summary><br /> /// <param name="aHwnd"></param><br /> /// <param name="aWMsg"></param><br /> /// <param name="aWParam"></param><br /> /// <param name="aLParam"></param><br /> /// <returns></returns><br /> [DllImport("user32", EntryPoint = "SendMessage")]<br /> public static extern int SendMessage(IntPtr aHwnd, int aWMsg, int aWParam, IntPtr aLParam);<br /> /// <summary><br /> /// 發送案卷箱子訊息<br /> /// </summary><br /> /// <param name="hwnd"></param><br /> /// <param name="wMsg"></param><br /> /// <param name="wParam"></param><br /> /// <param name="lParam"></param><br /> /// <returns></returns><br /> [DllImport("user32", EntryPoint = "SendMessage")]<br /> public static extern int SendMessage(IntPtr aHwnd, int aWMsg, int aWParam, ref RecBoxMessage aLParam);<br /> /// <summary><br /> /// 尋找指定類名或表單名稱的視窗<br /> /// </summary><br /> /// <param name="lpClassName"></param><br /> /// <param name="lpWindowName"></param><br /> /// <returns></returns><br /> [DllImport("user32", EntryPoint = "FindWindow")]<br /> public static extern IntPtr FindWindow(string aLpClassName, string aLpWindowName);<br /> }<br />--------------------------------<br />三、發送訊息<br /> #region SendBoxMessage 向所有開啟的箱子發送訊息<br /> /// <summary><br /> /// 向所有開啟的箱子發送訊息<br /> /// </summary><br /> public static void SendBoxMessage(List<int> aRecIDList)<br /> {<br /> foreach (int vRecID in aRecIDList)<br /> {<br /> SendBoxMessage(vRecID);<br /> }<br /> }<br /> /// <summary><br /> /// 向所有開啟的箱子發送訊息<br /> /// </summary><br /> public static void SendBoxMessage(int aRecID)<br /> {<br /> //局部變數定義<br /> RecBoxMessage vRecBoxMessage;<br /> //初始局部變數<br /> vRecBoxMessage.RecID = aRecID;<br /> RefreshMessage.SendBoxMessage(vRecBoxMessage);<br /> }<br /> #endregion<br />--------------------------------------<br /> public class RefreshMessage<br /> {<br /> public static bool SendBoxMessage(RecBoxMessage aRecBoxMessage)<br /> {<br /> foreach (IntPtr vTargetWindow in RecBoxHandles)<br /> {<br /> Win32API.SendMessage(vTargetWindow, WMConsts.WM_BOXMESSGE, WMConsts.WM_BOXMESSGE, ref aRecBoxMessage);<br /> }<br /> return true;<br /> }<br /> public static List<IntPtr> RecBoxHandles = new List<IntPtr>();<br /> }<br /> -------------------------<br /> 四、添加與刪除控制代碼<br /> private void frmEstateWorkFlow_FormClosed(object sender, FormClosedEventArgs e)<br /> {<br /> RefreshMessage.RecBoxHandles.Remove(this.Handle);<br /> }<br /> #endregion<br /> #region 關於箱子表單控制代碼<br /> private void SetHandle()<br /> {<br /> RefreshMessage.RecBoxHandles.Add(this.Handle);<br /> }<br /> #endregion<br /> 五、接收訊息<br /> #region WndProc 通過監視系統訊息,來調用過程<br /> protected override void WndProc(ref Message aMessage)<br /> {<br /> RecBoxMessage vRecBox;<br /> switch (aMessage.Msg)<br /> {<br /> case WMConsts.WM_BOXMESSGE:<br /> {<br /> if (aMessage.WParam.ToInt32() == WMConsts.WM_BOXMESSGE)<br /> {<br /> vRecBox = (RecBoxMessage)aMessage.GetLParam(typeof(RecBoxMessage));<br /> this.ucEstateWorkFlowGrid1.ActionRecBoxMessge(vRecBox);<br /> }<br /> break;<br /> }<br /> }<br /> //將系統訊息傳遞自父類的WndProc<br /> base.WndProc(ref aMessage);<br /> }<br /> #endregion<br /> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.