public void TestEmulateChangeAddressEvent() { //イベント確認。 NativeIPAddress ipadress = new NativeIPAddress(testDlg.IdentifyFromDialogId(1016)); ipadress.EmulateChangeAddress(0, 0, 0, 0); Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg, delegate { ipadress.EmulateChangeAddress(1, 2, 3, 4); }, new CodeInfo(1016, NativeMethods.WM_NOTIFY, IPN_FIELDCHANGED), new CodeInfo(1016, NativeMethods.WM_COMMAND, 512), new CodeInfo(1016, NativeMethods.WM_COMMAND, 256), new CodeInfo(1016, NativeMethods.WM_COMMAND, EN_CHANGE), new CodeInfo(1016, NativeMethods.WM_NOTIFY, IPN_FIELDCHANGED), new CodeInfo(1016, NativeMethods.WM_COMMAND, EN_CHANGE), new CodeInfo(1016, NativeMethods.WM_NOTIFY, IPN_FIELDCHANGED), new CodeInfo(1016, NativeMethods.WM_COMMAND, EN_CHANGE), new CodeInfo(1016, NativeMethods.WM_NOTIFY, IPN_FIELDCHANGED), new CodeInfo(1016, NativeMethods.WM_COMMAND, EN_CHANGE), new CodeInfo(1016, NativeMethods.WM_NOTIFY, IPN_FIELDCHANGED))); //詳細なNotify内容を確認。 NMIPADDRESS[] expectation = new NMIPADDRESS[5]; expectation[0].iField = 0; expectation[0].iValue = 1; expectation[1].iField = 0; expectation[1].iValue = 11; expectation[2].iField = 1; expectation[2].iValue = 12; expectation[3].iField = 2; expectation[3].iValue = 13; expectation[4].iField = 3; expectation[4].iValue = 14; Assert.IsTrue(EventChecker.CheckNotifyDetail(testDlg, delegate { ipadress.EmulateChangeAddress(11, 12, 13, 14); }, expectation)); }
/// <summary> /// IPアドレスを変更します。 /// IPN_FIELDCHANGEDの通知が発生します。 /// </summary> /// <param name="handle">ウィンドウハンドル。</param> /// <param name="field0">フィールド0。</param> /// <param name="field1">フィールド1。</param> /// <param name="field2">フィールド2。</param> /// <param name="field3">フィールド3。</param> private static void EmulateChangeAddressInTarget(IntPtr handle, byte field0, byte field1, byte field2, byte field3) { NativeMethods.SetFocus(handle); byte[] newFields = new byte[] { field0, field1, field2, field3 }; for (int i = 0; i < newFields.Length; i++) { //変更前のアドレスを取得。 int address = 0; NativeMethods.SendMessage(handle, IPM_GETADDRESS, IntPtr.Zero, ref address); byte[] fields = new byte[] { (byte)((address & 0xff000000) >> 24), (byte)((address & 0x00ff0000) >> 16), (byte)((address & 0x0000ff00) >> 8), (byte)(address & 0x000000ff)}; //一つフィールドを変更 fields[i] = newFields[i]; //変更。 NativeMethods.SendMessage(handle, IPM_SETADDRESS, IntPtr.Zero, new IntPtr((fields[0] << 24) + (fields[1] << 16) + (fields[2] << 8) + fields[3])); //WM_NOTIFYでの通知 NMIPADDRESS ipAdress = new NMIPADDRESS(); EmulateUtility.InitNotify(handle, IPN_FIELDCHANGED, ref ipAdress.hdr); ipAdress.iField = i; ipAdress.iValue = newFields[i]; NativeMethods.SendMessage(NativeMethods.GetParent(handle), NativeCommonDefine.WM_NOTIFY, ipAdress.hdr.idFrom, ref ipAdress); } }