一、結構聲明<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 />