答案已发. 悄悄得2分:-)
代码很简洁,有点小问题,当快速单击2次鼠标右键后会变成红色大圆。 --------------------------- 没测试快速两次击键的情况,想当然地认为up/down应是成对出现的,测试发现在两次快击中Down事件触发一次(??这个应和系统捕捉的时间间隔有关),而UP事件触发了2次.完善一下: '** iState状态列表********************************************************** '** 0 :初使状态 小红 '** 1 :前一按键为左键 小红 '** 2 :当前按住左键 大红 '** 3 :前一按键为右键 小兰 '** 4 :当前按住右键 大兰 '** 以上状态由Back_MouseDown/MouseUp改变,DrawRound据之确定圆圈的大小及颜色 '*************************************************************************** Dim iState As Integer Private Const SmallSize = 30 Private Const LargeSize = 60 Private Const PS_SOLID = 0 Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long 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 RoundRect Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long Private Sub Back_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS) iState = Button * 2 DrawRound x, y End Sub Private Sub Back_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS) If iState Mod 2 = 0 Then iState = iState - 1 '此处加个判断 DrawRound x, y End Sub Private Sub Back_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS) DrawRound x, y End Sub Private Sub DrawRound(ByVal x As Long, ByVal y As Long) Dim hdc As Long Dim pen As Long Dim lngSize As Long lngSize = IIf(iState = 2 Or iState = 4, LargeSize, SmallSize) hdc = GetDC(Back.hwnd) pen = CreatePen(PS_SOLID, 1, IIf(iState > 2, &HFF0000, &HFF&)) SelectObject hdc, pen Back.Refresh RoundRect hdc, x - lngSize / 2, y - lngSize / 2, x + lngSize / 2, y + lngSize / 2, lngSize, lngSize DeleteObject pen ReleaseDC 0, hdc End Sub
[此贴子已经被作者于2007-7-22 18:04:44编辑过] |