噗友的原文在這邊
- 職場:先升值,再升職;
- 溝通:先求同,再求異;
- 執行:先完成,再完美;
- 學習:先記錄,再記憶;
- 設計:先仿造,再創造;
- 創業:先成長,再成功;
- 發展:先站住,再站高;
- 人際:先交流,再交心;
- 先做好自己,再要求別人;
- 先解決心情,再解決事情。
We think, we believe then we make it
#Region "Const" Const INPUT_MOUSE As UInt32 = 0 Const INPUT_KEYBOARD As Integer = 1 Const INPUT_HARDWARE As Integer = 2 Const KEYEVENTF_EXTENDEDKEY As UInt32 = &H1 Const KEYEVENTF_KEYUP As UInt32 = &H2 Const KEYEVENTF_UNICODE As UInt32 = &H4 Const KEYEVENTF_SCANCODE As UInt32 = &H8 Const XBUTTON1 As UInt32 = &H1 Const XBUTTON2 As UInt32 = &H2 Const MOUSEEVENTF_MOVE As UInt32 = &H1 Const MOUSEEVENTF_LEFTDOWN As UInt32 = &H2 Const MOUSEEVENTF_LEFTUP As UInt32 = &H4 Const MOUSEEVENTF_RIGHTDOWN As UInt32 = &H8 Const MOUSEEVENTF_RIGHTUP As UInt32 = &H10 Const MOUSEEVENTF_MIDDLEDOWN As UInt32 = &H20 Const MOUSEEVENTF_MIDDLEUP As UInt32 = &H40 Const MOUSEEVENTF_XDOWN As UInt32 = &H80 Const MOUSEEVENTF_XUP As UInt32 = &H100 Const MOUSEEVENTF_WHEEL As UInt32 = &H800 Const MOUSEEVENTF_VIRTUALDESK As UInt32 = &H4000 Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000 #End Region #Region "Enums" Public Enum InputType As Integer Mouse = 0 Keyboard = 1 Hardware = 2 End Enum <Flags()> _ Public Enum MOUSEEVENTF As Integer MOVE = &H1 LEFTDOWN = &H2 LEFTUP = &H4 RIGHTDOWN = &H8 RIGHTUP = &H10 MIDDLEDOWN = &H20 MIDDLEUP = &H40 XDOWN = &H80 XUP = &H100 VIRTUALDESK = &H400 WHEEL = &H800 ABSOLUTE = &H8000 End Enum <Flags()> _ Public Enum KEYEVENTF As Integer EXTENDEDKEY = 1 KEYUP = 2 [UNICODE] = 4 SCANCODE = 8 End Enum #End Region #Region "Structure" <StructLayout(LayoutKind.Explicit)> _ Public Structure INPUT <FieldOffset(0)> Dim dwType As Integer <FieldOffset(4)> Dim mouseInput As MOUSEINPUT <FieldOffset(4)> Dim keyboardInput As KEYBDINPUT <FieldOffset(4)> Dim hardwareInput As HARDWAREINPUT End Structure <StructLayout(LayoutKind.Explicit)> _ Public Structure KEYBDINPUT <FieldOffset(0)> Public wVk As Short <FieldOffset(2)> Public wScan As Short <FieldOffset(4)> Public dwFlags As Integer <FieldOffset(8)> Public time As Integer <FieldOffset(12)> Public dwExtraInfo As IntPtr End Structure <StructLayout(LayoutKind.Explicit)> _ Public Structure HARDWAREINPUT <FieldOffset(0)> Public uMsg As Integer <FieldOffset(4)> Public wParamL As Short <FieldOffset(6)> Public wParamH As Short End Structure <StructLayout(LayoutKind.Explicit)> _ Public Structure MOUSEINPUT <FieldOffset(0)> Public dx As Integer <FieldOffset(4)> Public dy As Integer <FieldOffset(8)> Public mouseData As Integer <FieldOffset(12)> Public dwFlags As Integer <FieldOffset(16)> Public time As Integer <FieldOffset(20)> Public dwExtraInfo As IntPtr End Structure #End Region <DllImport("user32.dll", EntryPoint:="SendInput")> Public Shared Function SendInput(ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer End Function Public Shared Sub DoKeyBoard(ByVal flags As KEYEVENTF, ByVal key As Char) Dim _input As New INPUT Dim ki As New KEYBDINPUT _input.dwType = InputType.Keyboard _input.keyboardInput = ki _input.keyboardInput.wVk = Convert.ToInt16(key) _input.keyboardInput.wScan = 0 _input.keyboardInput.time = 0 _input.keyboardInput.dwFlags = flags _input.keyboardInput.dwExtraInfo = IntPtr.Zero Dim cbSize As Integer = Marshal.SizeOf(GetType(INPUT)) Dim result As Integer = SendInput(1, _input, cbSize) 'If result = 0 Then Debug.WriteLine(Marshal.GetLastWin32Error) _input = Nothing ki = Nothing End Sub
Public Property FoucedCtl As TextBox Private Sub Button_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) If Me.FoucedCtl Is Nothing Then Exit Sub End If Me.FoucedCtl.Focus() Win32Helper.DoKeyBoard(0, CType(sender, Button).Content.ToString.Chars(0)) System.Threading.Thread.Sleep(5) Win32Helper.DoKeyBoard(Win32Helper.KEYEVENTF.KEYUP, CType(sender, Button).Content.ToString.Chars(0)) End Sub
<DllImport("CoreDll.dll", EntryPoint:="RegDeleteKeyW")> _ Public Function RegDeleteKey(ByVal hKey As Integer, ByVal lpSubKey As String) As Integer End Function <DllImport("CoreDll.dll", EntryPoint:="RegCreateKeyExW")> _ Public Function RegCreateKeyEx(ByVal hkey As Integer, ByVal lpSubKey As String, _ ByVal Reserved As Integer, ByVal lpClass As String, _ ByVal dwOptions As Integer, ByVal samDesired As Integer, _ ByVal lpSecurityAttributes As Integer, ByRef phkResult As Integer, _ ByRef lpdwDisposition As Integer) As Integer End Function <DllImport("CoreDll.dll")> _ Public Function RegSetValueEx(ByVal hKey As Integer, ByVal lpValueName As String, _ ByVal Reserved As Integer, ByVal dwType As Integer, ByVal lpData As String, ByVal cbData As Integer) As Integer End Function <DllImport("CoreDll.dll")> _ Public Function RegCloseKey(ByVal hKey As Integer) As Integer End Function <DllImport("CoreDll.dll", EntryPoint:="RegOpenKeyExW")> _ Public Function RegOpenKeyEx(ByVal hKey As Integer, ByVal lpSubKey As String, ByVal dwOptions As Integer, _ ByVal samDesired As Integer, ByRef phkResult As Integer) As Integer End Function <DllImport("CoreDll.dll")> _ Public Function RegFlushKey(ByVal hKey As Integer) As Integer End Function
Dim buf, ohKey, iTmp As Integer Dim bolResult As Boolean = False ''R86101是我的網路卡名稱 buf = RegCreateKeyEx(RegRoots.HKEY_LOCAL_MACHINE, "Comm\PCI\R86101\Parms\TCPIP", 0, vbNullString, 0, 0, 0, ohKey, iTmp) buf = RegSetValueEx(ohKey, "Ipaddress", 0, RegValueType.REG_MULTI_SZ, IpAddress, 30) buf = RegFlushKey(ohKey) buf = RegCloseKey(ohKey) buf = RegCreateKeyEx(RegRoots.HKEY_LOCAL_MACHINE, "Comm\PCI\R86101\Parms\TCPIP", 0, vbNullString, 0, 0, 0, ohKey, iTmp) buf = RegSetValueEx(ohKey, "DefaultGateway", 0, RegValueType.REG_MULTI_SZ, Getway, 30) buf = RegFlushKey(ohKey) buf = RegCloseKey(ohKey) buf = RegCreateKeyEx(RegRoots.HKEY_LOCAL_MACHINE, "Comm\PCI\R86101\Parms\TCPIP", 0, vbNullString, 0, 0, 0, ohKey, iTmp) buf = RegSetValueEx(ohKey, "SubnetMask", 0, RegValueType.REG_MULTI_SZ, SubMask, 30) buf = RegFlushKey(ohKey) buf = RegCloseKey(ohKey)
Public Const OPEN_EXISTING As UInt32 = 3 Public Const INVALID_HANDLE_VALUE As Int32 = -1 Public Const IOCTL_NDIS_REBIND_ADAPTER As UInt32 = &H17002E Public Const FILE_ATTRIBUTE_NORMAL As UInt32 = &H80
<DllImport("coredll.dll", EntryPoint:="CreateFileW")> _ Public Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _ ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, _ ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, _ ByVal hTemplateFile As Integer) As Integer End Function <DllImport("CoreDll.dll", setlasterror:=True)> _ Public Function DeviceIoControl(ByVal m_handle As Integer, ByVal dwIoControlCode As Integer, _ ByVal npInBuffer As String, ByVal nInBufferSize As Integer, _ ByVal lpOutBuffer As String, ByVal nOutBufferSize As Integer, _ ByVal lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Boolean End Function <DllImport("CoreDll.dll")> _ Public Function GetLastError() As Integer End Function <DllImport("coredll.dll")> _ Public Function CloseHandle(ByVal m_handle As IntPtr) As Integer End Function
Dim _NDISAdapterName As String = mMyInfo.NDISAdapterName Dim m_handle As Integer m_handle = CreateFile("NDS0:", 0, 0, Nothing, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE) If Not DeviceIoControl(m_handle, IOCTL_NDIS_REBIND_ADAPTER, _NDISAdapterName, _ _NDISAdapterName.Length * 2 + 2, Nothing, 0, 0, 0) Then ''intResult = GetLastError() bolResult = False Else bolResult = True End If CloseHandle(m_handle)
Private Sub WaitForCommand() Do If _bolStop Then Exit Do Try btyRecv = _client.Receive(_anyEndpoint) If btyRecv.Length > 0 Then If ByteToStr(btyRecv) = "command" Then ''do something End If End If Catch ex As Exception ''錯誤處理 End Try Threading.Thread.Sleep(100) Loop End Sub
Public Sub [Stop]() _bolStop = True Try If _client IsNot Nothing Then _client.Close() End If Catch ex As Exception ''錯誤處理 End Try End Sub
public uint ImageWidth { get; set; }
public uint ImageHeight { get; set; }
public int ImageIndex { get; set; }
public bool IsEditMode
{
get
{
return _IsEditMode;
}
set
{
_IsEditMode = value;
NotifyPropertyChanged("IsEditMode");
}
}
<StackPanel Orientation="Horizontal" d:DesignWidth="290"> <CheckBox x:Name="chkMark" VerticalAlignment="Top" Width="55" Visibility="{Binding IsEditMode,
Converter={StaticResource VisibleConverter}}"/> <Image Width="90" Source="{Binding TumbUrl}" Stretch="UniformToFill" d:LayoutOverrides="Width" /> StackPanel>在上面的XAML就可以看到在CheckBox的Visibility屬性直接Binding到了IsEditMode的屬性,並且賦予了一個自訂的Converter,這個Converter也是一個自訂的類別,主要是處理邏輯,比如說當IsEditMode == true的時候,要吐甚麼東西給CheckBox的Visibility屬性,程式碼大概會像是這樣
public class clsVisibleConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
另外由於在XAML中利用的StaticResource去綁定,所以在頁面的資源中要再加入資源的設定,像是下面這樣
<UserControl.Resources> <myConverter:clsVisibleConverter x:Key="VisibleConverter" /> UserControl.Resources>
<access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="SOAPAction"> <domain uri="*"> </domain></allow-from> <grant-to> <resource include-subpaths="true" path="/"> </resource></grant-to> </policy> </cross-domain-access> </access-policy>
內容還滿容易理解的,在allow-form http-request-headers="SOAPAction"這個是表示允許SOAP的操作要求,而接下來的domain uri="*"在這邊是指允許所有地方連線過來取得資源的要求,而要限定只允許某個Uri的話就會是設定成像domain uri="http://www.othersite.com"這樣的設定,詳細的說明可以參考一下上面提到的網頁內容。Imports System.IO Imports System.ServiceModel Imports System.ServiceModel.Web <servicemodel.servicecontract()> Public Interface IPolicyRetriever <operationcontract(), webget(uritemplate:="/clientaccesspolicy.xml" )=""> Function GetSilverlightPolicy() As Stream End Interface
Public Class AcsServiceHost Implements ImyWebService Implements IPolicyRetriever Public Function GetSilverlightPolicy() As System.IO.Stream Implements IPolicyRetriever.GetSilverlightPolicy ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml" Return New IO.MemoryStream(Encoding.UTF8.GetBytes(PolicyXML)) End Function Private Const PolicyXML As String = "" & "" & "" & "" & "" *=" ">" & "" *=" ">" & "" & "" & "" & "" & "" & "" & "" End Class
Dim basic As New BasicHttpBinding() basic.MaxBufferSize = 8192000 basic.MaxBufferPoolSize = 8192000 basic.MaxReceivedMessageSize = 8192000 basic.MessageEncoding = WSMessageEncoding.Text Host = New ServiceHost(GetType(AcsServiceHost), New Uri("http://192.168.1.1:1234/myWindowsService")) Host.AddServiceEndpoint(GetType(IAcsService), basic, "http://192.168.1.1:1234/myWindowsService") Host.AddServiceEndpoint(GetType(IPolicyRetriever), New WebHttpBinding, "http://192.168.1.1:1234").Behaviors.Add(New Description.WebHttpBehavior) Dim smb As Description.ServiceMetadataBehavior = New Description.ServiceMetadataBehavior smb.HttpGetEnabled = True Host.Description.Behaviors.Add(smb) Host.Open()