大众计算机学习网

专门提供各种电脑教程

VB代码之禁止使用Alt+F4关闭窗口及软件的使用限制(次数、天数)

Admin | 2009-5-5 13:06:31 | 被阅次数 | 6660

  一、禁止使用Alt+F4关闭窗口代码

  Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
  Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&

  Private Sub Form_Load()
  Dim hwndMenu As Long
  Dim c As Long
  hwndMenu = GetSystemMenu(Me.hwnd, 0)

  c = GetMenuItemCount(hwndMenu)

  DeleteMenu hwndMenu, c - 1, MF_BYPOSITION

  c = GetMenuItemCount(hwndMenu)
  DeleteMenu hwndMenu, c - 1, MF_BYPOSITION
  End Sub

  二、限制软件的使用次数

  ①限制使用60次

  Private Sub Form_Load()
  Dim RemainDay As Long
  RemainDay = GetSetting("MyApp", "set", "times", 0)
  If RemainDay = 60 Then
     MsgBox "试用次数已满,请购买正版"
     Unload Me
  End If
  MsgBox "现在剩下:" & 60 - RemainDay & "的试用次数,请阁下珍惜!"
  RemainDay = RemainDay + 1
  SaveSetting "MyApp", "set", "times", RemainDay
  End Sub

  ②限制使用60天

  Private Sub Form_Load()
  Dim RemainDay As Long
  RemainDay = GetSetting("MyApp", "set", "day", 0)
  If RemainDay = 60 Then
      MsgBox "试用期已过,请购买正版"
      Unload Me
  End If
  MsgBox "现在还剩下:" & 60 - RemainDay & "的试用天数,请阁下珍惜!"
  if day(now)-remainday>0 then RemainDay = RemainDay + 1
  SaveSetting "MyApp", "set", "times", RemainDay
  End Sub