[VB.NET]密碼框顯示程式探討與其簡易的保護之道
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean End Function
Const EM_SETPASSWORDCHAR = &HCC
Private Sub TargetSelectedControl1_TargetSelected(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TargetSelectedControl1.TargetSelected
Dim hWnd As IntPtr = WindowFromPoint(MousePosition)
PostMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0)
End Sub</pre></div>
Const WM_SETTEXT As Integer = &HC
Const WM_GETTEXT As Integer = &HD
Const EM_SETPASSWORDCHAR = &HCC
Sub New()
With Me
.Multiline = False
.UseSystemPasswordChar = True
End With
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_SETTEXT OrElse m.Msg = WM_GETTEXT OrElse m.Msg = EM_SETPASSWORDCHAR Then
Return
End If
MyBase.WndProc(m)
End Sub
End Class