Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4764064
  • 博文数量: 206
  • 博客积分: 5240
  • 博客等级: 大校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-12 21:40
文章分类

全部博文(206)

文章存档

2013年(13)

2012年(8)

2011年(33)

2010年(152)

我的朋友

分类: 项目管理

2011-10-12 16:35:32

  1. 基本原理是:获取本机登录的QQ号是否与绑定注册的QQ号一致,再判定QQ号是否在线,未在线的话不能使用全部功能或干脆退出。

  2. 实现代码,本人用vb6.0开发的,实现代码如下:

  3. 'Option Explicit
  4. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  5. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  6. Private Const READ_CONTROL As Long = &H20000
  7. Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
  8. Private Const STANDARD_RIGHTS_READ As Long = (READ_CONTROL)
  9. Private Const STANDARD_RIGHTS_EXECUTE As Long = (READ_CONTROL)
  10. Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
  11. Private Const STANDARD_RIGHTS_WRITE As Long = (READ_CONTROL)
  12. Private Const SYNCHRONIZE As Long = &H100000
  13. Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  14. Private Const PROCESS_TERMINATE As Long = (&H1)
  15. Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
  16. Private Const WM_USER As Long = &H400
  17. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  18. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  19. Private Const TB_BUTTONCOUNT As Long = (WM_USER + 24)
  20. Private Const TB_HIDEBUTTON As Long = (WM_USER + 4)
  21. Private Const TB_GETBUTTON As Long = (WM_USER + 23)
  22. Private Const TB_GETBITMAP As Long = (WM_USER + 44)
  23. Private Const TB_DELETEBUTTON As Long = (WM_USER + 22)
  24. Private Const TB_ADDBUTTONS As Long = (WM_USER + 20)
  25. Private Const TB_INSERTBUTTON As Long = (WM_USER + 21)
  26. Private Const TB_ISBUTTONHIDDEN As Long = (WM_USER + 12)
  27. Private Const ILD_NORMAL As Long = &H0
  28. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  29. Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  30. Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  31. Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  32. Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
  33. Private Const PROCESS_VM_OPERATION As Long = (&H8)
  34. Private Const PROCESS_VM_READ As Long = (&H10)
  35. Private Const PROCESS_VM_WRITE As Long = (&H20)
  36. Private Const MEM_RESERVE As Long = &H2000
  37. Private Const MEM_COMMIT As Long = &H1000
  38. Private Const MEM_RELEASE As Long = &H8000
  39. Private Const PAGE_READWRITE As Long = &H4

  40. Private Function ConverNull(ByVal S As String) As String
  41.     Dim nullpos As Long
  42.     nullpos = InStr(S, Chr$(0))
  43.     If nullpos > 0 Then
  44.         ConverNull = Left(S, nullpos - 1)
  45.     Else
  46.         ConverNull = S
  47.     End If
  48. End Function

  49. Public Function getQQ() As String
  50.     Dim lngTemp As Long
  51.     Dim lngTray
  52.     Dim lngPID As Long
  53.     Dim lngPID2 As Long
  54.     Dim hProcess As Long
  55.     Dim lngProcess As Long
  56.     Dim lngAddress As Long
  57.     Dim lngCount As Long
  58.     Dim lngButtons As Long
  59.     Dim ret As Long
  60.     Dim lngTextAdr As Long
  61.     Dim lngHwndAdr As Long
  62.     Dim lngButtonID As Long
  63.     Dim hIcon As Long
  64.     Dim lngHwnd As Long
  65.     Dim lpFileName As String * 1024
  66.     Dim i As Long
  67.     Dim strBuff(1024) As Byte
  68.     Dim strText As String
  69.     Dim lngTrayDC As Long
  70.     Dim Start As Long
  71.     Dim str As String
  72.     lngTemp = FindWindow("Shell_TrayWnd", vbNullString)
  73.     lngTemp = FindWindowEx(lngTemp, 0, "TrayNotifyWnd", vbNullString)
  74.     lngTemp = FindWindowEx(lngTemp, 0, "SysPager", vbNullString)
  75.         lngTray = FindWindowEx(lngTemp, 0, "ToolbarWindow32", vbNullString)
  76.     Debug.Print "lngTray="; lngTray
  77.     ret = GetWindowThreadProcessId(lngTray, lngPID)
  78.     hProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, lngPID)
  79.     lngAddress = VirtualAllocEx(hProcess, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE)
  80.     lngButtons = SendMessage(lngTray, TB_BUTTONCOUNT, 0, 0)
  81.     For i = 0 To lngButtons - 1
  82.         ret = SendMessage(lngTray, TB_GETBUTTON, ByVal i, ByVal lngAddress)
  83.         ret = ReadProcessMemory(hProcess, ByVal lngAddress + 16, ByVal VarPtr(lngTextAdr), ByVal 4, ByVal 0&)
  84.         If lngTextAdr <> -1 Then
  85.             ret = ReadProcessMemory(hProcess, ByVal lngTextAdr, ByVal VarPtr(strBuff(0)), ByVal 1024, ByVal 0&)
  86.             ret = ReadProcessMemory(hProcess, ByVal lngAddress + 12, ByVal VarPtr(lngHwndAdr), ByVal 4, ByVal 0&)
  87.             ret = ReadProcessMemory(hProcess, ByVal lngHwndAdr, ByVal VarPtr(lngHwnd), ByVal 4, ByVal 0&)
  88.             ret = ReadProcessMemory(hProcess, ByVal lngAddress + 4, ByVal VarPtr(lngButtonID), ByVal 4, ByVal 0&)
  89.             strText = ConverNull(strBuff)
  90.               
  91.               If Left(strText, 3) = "QQ:" Then
  92.                  '仅提取QQ号码
  93.                  Dim l1 As Integer
  94.                  Dim l2 As Integer
  95.                  l1 = InStr(strText, "(")
  96.                  l2 = InStr(strText, ")")
  97.                  
  98.                  str = Mid(strText, l1 + 1, l2 - l1 - 1)
  99.                  
  100.                  getQQ = str
  101.               End If
  102.          End If
  103.     Next i
  104.     VirtualFreeEx hProcess, ByVal lngAddress, ByVal 4096&, MEM_RELEASE
  105.     CloseHandle hProcess
  106. End Function

  107. '判断QQ是否在线
  108. Public Function if_QQonline(qq_str As String) As Boolean
  109. On Error Resume Next
  110. Dim QQUrl As String
  111. Dim QQ As String

  112. If qq_str <> getQQ Then
  113.    m = MsgBox("你绑定的QQ号未在当前使用的电脑上登录,不能使用全部功能!", vbExclamation)
  114.    if_QQonline = False
  115.    Exit Function
  116. End If

  117. QQ = qq_str
  118. QQUrl = "" & QQ & ":7"
  119. Dim rlt() As Byte

  120. rlt = 总控窗体.Inet1.OpenURL(QQUrl, icByteArray)

  121. If rlt(13) = &H34 Then
  122.    if_QQonline = False
  123. ElseIf rlt(13) = &H52 Then
  124.       if_QQonline = True
  125.    Else
  126.       if_QQonline = False
  127. End If

  128. End Function

  129. Public Function if_registQQonline(ifdisp As Boolean) As Boolean
  130. 'ifdisp变量为是否弹出警告框
  131. if_registQQonline = False

  132. Set adocon = New ADODB.Connection
  133. Set rsado = New ADODB.Recordset
  134. adocon.Open "Provider=Microsoft.jet.OLeDB.4.0;Data Source=" & App.Path & "\data\综合设置.mdb;"
  135. Set rsado.ActiveConnection = adocon
  136. rsado.LockType = adLockOptimistic
  137. rsado.CursorLocation = adUseClient
  138. Dim str As String

  139. '看注册方式是否为绑定QQ,不是的话则退出
  140. str = "select * from 注册信息 where 项目名称='注册方式' "
  141. rsado.Open str
  142. If rsado.EOF Then
  143.    l = MsgBox(mybase64.DecodeBase64String(Mymsg3), vbExclamation)
  144.    adocon.Close
  145.    End
  146. End If
  147. rsado.MoveFirst
  148. If IsNull(rsado.Fields("设置值").value) Then
  149.    adocon.Close
  150.    GoTo out
  151. End If
  152. registname = rsado.Fields("设置值").value
  153. rsado.Close
  154. If registname = "0" Then
  155.    if_registQQonline = True
  156.    adocon.Close
  157.    GoTo out
  158. End If


  159. '读取存于数据库中的QQ号
  160. str = "select * from 注册信息 where 项目名称='QQ号' "
  161. rsado.Open str
  162. If rsado.EOF Then
  163.    l = MsgBox(mybase64.DecodeBase64String(Mymsg3), vbExclamation)
  164.    adocon.Close
  165.    End
  166. End If
  167. rsado.MoveFirst
  168. If IsNull(rsado.Fields("设置值").value) Then
  169.    adocon.Close
  170.    GoTo out
  171. End If
  172. registname = rsado.Fields("设置值").value
  173. rsado.Close
  174. adocon.Close

  175. If if_QQonline(CStr(registname)) = True Then
  176.    if_registQQonline = True
  177. Else
  178.    'if_registQQonline = False
  179.    If ifdisp Then m = MsgBox(mybase64.DecodeBase64String(Mymsg8), vbExclamation) '不在线提示
  180. End If

  181. out:
  182. End Function
阅读(4381) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~