因为2000中的API本来就跟WIN9X中的不一样。

解决方案 »

  1.   

    jingxiaoping(恋爱温度) :
    怎么个不同法?说具体些,ok?
      

  2.   

    就是说升级到WIN2000以后,它就拥有了新的一套API,而现行的API已经不试用了,就是这样,但差异这么大,我还没有见过,出现的是这个结果吗?
      

  3.   

    2000和9x的整个API系统肯定是有区别的,这点毋庸置疑,但并不代表此函数就有区别,因为同样都可执行,只是在对字符串的取值上有差异:9x中无论中英文字都可按一个字节取,但2000中中文字算两个字节,因此在2000中要先将字符串转成Unicode才能正确反映中文字的长度,从而正确取得字符串。
    这到底是因为何故,光以一句“不同”不能说清楚吧?
      

  4.   

    2000嘛,NT内核,为了稳定和安全性,肯定会对许多API进行适当的修改.
    就象下面这个代码:
    ===========================================================
    BAS模块
    ===========================================================
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINT) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
                                                        ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Const HWND_TOPMOST = -1
    Private Const SWP_SHOWWINDOW = &H40
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nmaxCount As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_GETTEXTLENGTH = &HE
    Private Const WM_GETTEXT = &HD
    Private Const EM_SETPASSWORDCHAR = &HCC
    Private Type POINT 'sign mouse point
        x As Long
        y As Long
    End Type
    Public mMousePoint As POINT
    Public Function SetWindowP(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
                                                        ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
        SetWindowP = SetWindowPos(hwnd, hWndInsertAfter, x, y, cx, cy, wFlags)
    End Function
    Public Function GetCursor(lpMousePoint As POINT) As Long
        GetCursor = GetCursorPos(lpMousePoint)
    End FunctionPublic Function PasswordShow(ByVal obj As Object) As Long
        Dim currsor As Long
        Dim gclass As String * 255
        Dim gname As String
        
        PasswordShow = 0
        Call GetCursor(mMousePoint)
        cursor = WindowFromPoint(mMousePoint.x, mMousePoint.y)
        Call GetClassName(cursor, gclass, 255)
        gname = Trim(Left(gclass, InStr(gclass, vbNullChar) - 1))
        If gname = "Edit" Or InStr(gname, "TextBos") > 0 Then
            Call SendMessage(cursor, EM_SETPASSWORDCHAR, 0, 0)
            
            obj.BackColor = vbGreen
            obj.Caption = GetText(cursor)
        Else
            PasswordShow = -1
            MsgBox "This is not PassWord box or time out!", vbInformation, "Error"
        End If
    End FunctionPublic Function GetText(ByVal mhwnd As Long) As String
        Dim pwdlong As Long
        Dim pwd As String
        
        pwdlong = SendMessage(mhwnd, WM_GETTEXTLENGTH, 0, 0)
        
        If pwdlong = 0 Then
            GetText = "Not Password"
            Exit Function
        End If
        pwdlong = pwdlong + 1
        pwd = Space(pwdlong)
        pwdlong = SendMessage(mhwnd, WM_GETTEXT, pwdlong, ByVal pwd)
        GetText = Left(pwd, pwdlong)
    End Function
    ==============================================================================
    FRM文件
    ==============================================================================
    Private Sub cmdBtn_Click(Index As Integer)
        Select Case Index
        Case 0
            Timer1.Interval = 500
            Timer1.Enabled = True
            lblShow.BackColor = vbYellow
            lblShow.Caption = "Point to Password box inside 5 second with mouse cursor"
            Timer2.Enabled = False
        Case 1
            Timer1.Enabled = False
            lblShow.Caption = "If restart ,press start button"
            Timer2.Enabled = True
        Case 2
            MsgBox "thanks use it!"
        Case 3
            End
        End Select
    End SubPrivate Sub Form_Load()
        Dim pos As Long
        pos = SetWindowP(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 600, 80, SWP_SHOWWINDOW)
        BorderStyle = 1
        Me.Caption = App.Title
        Me.ScaleMode = 2
        Timer1.Enabled = False
        Timer2.Interval = 1
        lblShow.BackColor = &HFFFF00
        lblShow.Caption = "press start button"
        Me.Left = (0 - Me.Width) + 100
    End SubPrivate Sub Timer1_Timer()
        If PasswordShow(lblShow) < 0 Then
            Timer1.Enabled = False
            lblShow.BackColor = &HFFFF00
            lblShow.Caption = "If restart ,press start button"
        End If
    End SubPrivate Sub Timer2_Timer()
        On Error GoTo Timer_Error
        m = GetCursor(mMousePoint)
        If mMousePoint.y = 0 And mMousePoint.x <= Me.ScaleWidth Then
            Me.Left = 0
            Me.Top = 0
        End If
        
        If mMousePoint.y > Me.ScaleHeight + 50 Or mMousePoint.x > Me.ScaleWidth + 150 Then
            Me.Left = (0 - Me.Width) + 100
        End If
    Timer_Error:
    End Sub
    (这是一个可以取得星号密码的程序)
    但是他只在98下有用,在2000下无效.
    为什么?只因为SENDMESSAGE函数在2000中有所改动.使他变得更安全.