:)我要的坐标窗口可不是像现在我自己画的这么惨:)))

解决方案 »

  1.   

    Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" _
        (ByVal hdc As Long, _
        ByVal lpszString As String, _
        ByVal cbString As Long, _
        lpSize As Size _
        ) As LongPrivate Type Size
            cx As Long
            cy As Long
    End Type
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
        (ByVal hdc As Long, _
        ByVal X As Long, ByVal Y As Long, _
        ByVal lpString As String, _
        ByVal nCount As Long _
        ) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
        
    Const DSTINVERT = &H550009
    Const WHITENESS = &HFF0062Const SRCINVERT = &H660046Dim PMD As Boolean
    Dim StartX As Long, StartY As Long        '3--pixl
    Dim LastX  As Long, LastY As Long         '3--pixlPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      PMD = True
      StartX = Picture1.ScaleX(X, Picture1.ScaleMode, 3)
      StartY = Picture1.ScaleY(Y, Picture1.ScaleMode, 3)
      LastX = -1
      LastY = -1
       
    End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     Dim pX As Long, pY As Long
     If PMD Then
        If LastX <> -1 And LastY <> -1 Then
         Call DrawLine(LastX, LastY)
        End If
        
        pX = Picture1.ScaleX(X, Picture1.ScaleMode, 3)
        pY = Picture1.ScaleY(Y, Picture1.ScaleMode, 3)
        Call DrawLine(pX, pY)
        LastX = pX
        LastY = pY
     End If
    End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
     PMD = False
    End SubPrivate Sub DrawLine(ByVal X As Long, ByVal Y As Long)
      Dim RateYX As Single
      Dim lX As Long, lY As Long
      Dim rX As Long, rY As Long
      Dim DX As Long, DY As Long
      Dim Rc As Long
      Dim sExtent As Size     ' SIZE
      Dim sz As String
      Dim hbm As Long
      Dim hdcBits  As Long  
      If X = StartX Then
        If StartY < Y Then
          lY = StartY
          rY = Y
        Else
          lY = Y
          rY = StartY
        End If
        For DY = lY To rY
          Rc = PatBlt(Picture1.hdc, lX, DY, 1, 1, DSTINVERT)
        Next DY
        Exit Sub
      End If
      
      If X > StartX Then
        lX = StartX
        rX = X
        lY = StartY
        rY = Y
      
        RateYX = (rY - lY) / (rX - lX)
        Me.Caption = CStr(RateYX)
        For DX = lX To rX
          rY = lY + Round(((DX - lX) * RateYX), 0)
          Rc = PatBlt(Picture1.hdc, DX, rY, 1, 1, DSTINVERT)
        Next DX
      Else
        lX = X
        rX = StartX
        
        lY = Y
        rY = StartY
      
        RateYX = (rY - lY) / (rX - lX)
        Me.Caption = CStr(RateYX)
        For DX = lX To rX
          rY = lY - Round(((lX - DX) * RateYX), 0)
          Rc = PatBlt(Picture1.hdc, DX, rY, 1, 1, DSTINVERT)
        Next DX
      End If
      
      sz = CStr(X) + "x" + CStr(Y)
      GetTextExtentPoint32 Picture1.hdc, sz, Len(sz), sExtent
      hdcBits = CreateCompatibleDC(Picture1.hdc)
      SetTextColor hdcBits, &HFFFFFF
      SetBkColor hdcBits, &H0 
      
          hbm = CreateBitmap(sExtent.cx + 10, sExtent.cy, 1, 1, 0&)
       If (hbm) Then
           hbm = SelectObject(hdcBits, hbm)
           TextOut hdcBits, 0, 0, sz, Len(sz)
           BitBlt Picture1.hdc, X, Y, sExtent.cx + 10, sExtent.cy, hdcBits, 0, 0, SRCINVERT
            
           hbm = SelectObject(hdcBits, hbm)
           DeleteObject hbm
        End If 
    End Sub