android

Code

Mar 29th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 28.90 KB | None | 0 0
  1. Imports System.Security.Cryptography
  2. Imports System.IO
  3. Imports System.Text
  4. Imports System.Windows.Forms
  5. Imports System.Drawing
  6. Imports System.Threading
  7. Public Class Class1
  8.  
  9.     Shared Function NameBackWards(ByVal Name As String) As String
  10.         Dim BackWards As String = ""
  11.         For x As Integer = Name.Length - 1 To 0 Step -1
  12.             BackWards = BackWards & Name.Chars(x)
  13.         Next
  14.         Return BackWards
  15.     End Function
  16.  
  17.     Shared Function ConvertToBinary(ByVal str As String) As String
  18.  
  19.         Dim converted As New StringBuilder
  20.  
  21.         For Each b As Byte In ASCIIEncoding.ASCII.GetBytes(str)
  22.  
  23.             converted.Append(Convert.ToString(b, 2).PadLeft(8, "0"))
  24.  
  25.         Next
  26.  
  27.         Return converted.ToString()
  28.  
  29.     End Function
  30.  
  31.     Shared Function StringToMD5(ByVal Content As String) As String
  32.  
  33.         Dim M5 As New Security.Cryptography.MD5CryptoServiceProvider
  34.  
  35.         Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
  36.  
  37.         ByteString = M5.ComputeHash(ByteString)
  38.  
  39.         Dim FinalString As String = Nothing
  40.  
  41.         For Each bt As Byte In ByteString
  42.  
  43.             FinalString &= bt.ToString("x2")
  44.  
  45.         Next
  46.  
  47.         Return FinalString
  48.  
  49.     End Function
  50.  
  51.     Shared Function MD5CalcFile(ByVal filepath As String) As String
  52.  
  53.         Using reader As New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
  54.  
  55.             Using md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
  56.  
  57.                 Dim hash() As Byte = md5.ComputeHash(reader)
  58.  
  59.                 Return ByteArrayToString(hash)
  60.  
  61.             End Using
  62.  
  63.         End Using
  64.  
  65.     End Function
  66.  
  67.     Shared Function ByteArrayToString(ByVal arrInput() As Byte) As String
  68.  
  69.         Dim sb As New System.Text.StringBuilder(arrInput.Length * 2)
  70.  
  71.         For i As Integer = 0 To arrInput.Length - 1
  72.             sb.Append(arrInput(i).ToString("X2"))
  73.         Next
  74.  
  75.         Return sb.ToString().ToLower
  76.  
  77.     End Function
  78.  
  79.     Shared Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String
  80.         Dim AES As New System.Security.Cryptography.RijndaelManaged
  81.  
  82.         Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  83.  
  84.         Dim encrypted As String = ""
  85.  
  86.         Try
  87.  
  88.             Dim hash(31) As Byte
  89.  
  90.             Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  91.  
  92.             Array.Copy(temp, 0, hash, 0, 16)
  93.  
  94.             Array.Copy(temp, 0, hash, 15, 16)
  95.  
  96.             AES.Key = hash
  97.  
  98.             AES.Mode = Security.Cryptography.CipherMode.ECB
  99.  
  100.             Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
  101.  
  102.             Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
  103.  
  104.             encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  105.  
  106.             Return encrypted
  107.  
  108.         Catch ex As Exception
  109.  
  110.         End Try
  111.  
  112.     End Function
  113.  
  114.     Shared Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String
  115.         Dim AES As New System.Security.Cryptography.RijndaelManaged
  116.  
  117.         Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  118.  
  119.         Dim decrypted As String = ""
  120.  
  121.         Try
  122.  
  123.             Dim hash(31) As Byte
  124.  
  125.             Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  126.  
  127.             Array.Copy(temp, 0, hash, 0, 16)
  128.  
  129.             Array.Copy(temp, 0, hash, 15, 16)
  130.  
  131.             AES.Key = hash
  132.  
  133.             AES.Mode = Security.Cryptography.CipherMode.ECB
  134.  
  135.             Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
  136.  
  137.             Dim Buffer As Byte() = Convert.FromBase64String(input)
  138.  
  139.             decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  140.  
  141.             Return decrypted
  142.  
  143.         Catch ex As Exception
  144.  
  145.         End Try
  146.  
  147.     End Function
  148. End Class
  149.  
  150. Public Class IR_MessageBox
  151.  
  152. #Region " Iridium properties "
  153.     Public Property ForeColor() As Color
  154.         Get
  155.             Return mudtForeColor
  156.         End Get
  157.         Set(ByVal Value As Color)
  158.             mudtForeColor = Value
  159.         End Set
  160.     End Property
  161.     Private mudtForeColor As Color
  162.  
  163.     Public Property BackColor() As Color
  164.         Get
  165.             Return mudtForeColor
  166.         End Get
  167.         Set(ByVal Value As Color)
  168.             mudtBackColor = Value
  169.         End Set
  170.     End Property
  171.     Private mudtBackColor As Color
  172.  
  173.     Public Property MessageTitle() As String
  174.         Get
  175.             Return mstrTitle
  176.         End Get
  177.         Set(ByVal Value As String)
  178.             mstrTitle = Value
  179.         End Set
  180.     End Property
  181.     Private mstrTitle As String = ""
  182.  
  183.     Public Property MessageLocation() As Point
  184.         Get
  185.             Return New Point(mintX, mintY)
  186.         End Get
  187.         Set(ByVal Value As Point)
  188.             With Value
  189.                 mintX = .X
  190.                 mintY = .Y
  191.             End With
  192.         End Set
  193.     End Property
  194.     Private mintX As Int32
  195.     Private mintY As Int32
  196.  
  197.     Public Property MessagePauseSeconds() As Int32
  198.         Get
  199.             Return mintPause
  200.         End Get
  201.         Set(ByVal Value As Int32)
  202.             mintPause = Value
  203.             mintPauseMili = Value * 1000
  204.         End Set
  205.     End Property
  206.     Private mintPause As Int32
  207.     Private mintPauseMili As Int32
  208.  
  209.     Public Property MessageButtons() As MessageBoxButtons
  210.         Get
  211.             Return mudtButtons
  212.         End Get
  213.         Set(ByVal Value As MessageBoxButtons)
  214.             mudtButtons = Value
  215.         End Set
  216.     End Property
  217.     Private mudtButtons As MessageBoxButtons
  218.  
  219.     Public Property MessagePrompt() As String
  220.         Get
  221.             Return mstrPrompt
  222.         End Get
  223.         Set(ByVal Value As String)
  224.             mstrPrompt = Value
  225.         End Set
  226.     End Property
  227.     Private mstrPrompt As String = ""
  228.  
  229.     Public Property MessageCheckboxText() As String
  230.         Get
  231.             Return mstrCheckboxText
  232.         End Get
  233.         Set(ByVal Value As String)
  234.             mstrCheckboxText = Value
  235.         End Set
  236.     End Property
  237.     Private mstrCheckboxText As String = ""
  238.  
  239.     Public WriteOnly Property MessageButtonCaptions(ByVal pintIndex As Int32) As String
  240.         Set(ByVal Value As String)
  241.             If pintIndex >= LBound(mstrButtonText) And pintIndex <= UBound(mstrButtonText) Then
  242.                 mstrButtonText(pintIndex) = Value
  243.             End If
  244.         End Set
  245.     End Property
  246.     Private mstrButtonText(2) As String
  247.  
  248.     Public Property MessageSelfClosingText() As String
  249.         Get
  250.             Return mstrSelfClosingMessageText
  251.         End Get
  252.         Set(ByVal Value As String)
  253.             mstrSelfClosingMessageText = Value
  254.         End Set
  255.     End Property
  256.     Private mstrSelfClosingMessageText As String = ""
  257.  
  258.     Public Property CheckboxState() As Boolean
  259.         Get
  260.             Return mblnCheckState
  261.         End Get
  262.         Set(ByVal Value As Boolean)
  263.             mblnCheckState = Value
  264.         End Set
  265.     End Property
  266.     Private mblnCheckState As Boolean
  267.  
  268.     Public ReadOnly Property MessageResult() As System.Windows.Forms.DialogResult
  269.         Get
  270.             Return mudtMessageResult
  271.         End Get
  272.     End Property
  273.     Private mudtMessageResult As System.Windows.Forms.DialogResult
  274.  
  275.     Public Property MessageIcon() As MessageBoxIcon
  276.         Get
  277.             Return mudtIcon
  278.         End Get
  279.         Set(ByVal Value As MessageBoxIcon)
  280.             Value = mudtIcon
  281.         End Set
  282.     End Property
  283.     Private mudtIcon As MessageBoxIcon
  284.  
  285.     Public Property MessageDefaultButton() As MessageBoxDefaultButton
  286.         Get
  287.             Return mudtDefaultButton
  288.         End Get
  289.         Set(ByVal Value As MessageBoxDefaultButton)
  290.             mudtDefaultButton = Value
  291.         End Set
  292.     End Property
  293.     Private mudtDefaultButton As MessageBoxDefaultButton
  294.  
  295.     Public Property MessageOptions() As MessageBoxOptions
  296.         Get
  297.             Return mudtOptions
  298.         End Get
  299.         Set(ByVal Value As MessageBoxOptions)
  300.             mudtOptions = Value
  301.         End Set
  302.     End Property
  303.     Private mudtOptions As MessageBoxOptions
  304. #End Region
  305.  
  306. #Region " Iridium internal vars "
  307.     Private mintCheckHwnd As Int32
  308.     Private mintHook As Int32
  309.  
  310.     Private mudtScreenSize As Size
  311.  
  312.     Private mintCaptionHwnd As Int32
  313.     Private mintLabelHwnd As Int32
  314.  
  315.     Private mudtOwnerHandle As IWin32Window
  316. #End Region
  317.  
  318. #Region " Iridium functions "
  319.  
  320.     'standard
  321.     Public Sub New(ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, Optional ByVal pudtButtons As MessageBoxButtons = MessageBoxButtons.OK, Optional ByVal pstrTitle As String = "", Optional ByVal pudtIcon As MessageBoxIcon = MessageBoxIcon.None, Optional ByVal pudtDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, Optional ByVal pudtOptions As MessageBoxOptions = MessageBoxOptions.DefaultDesktopOnly)
  322.         Initialise(False, pudtOwnerHandle, pstrPrompt, pudtButtons, pstrTitle, pudtIcon, pudtDefaultButton, pudtOptions)
  323.     End Sub
  324.  
  325.     'self closing
  326.     Public Sub New(ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, ByVal pintMessagePauseSeconds As Int32, ByVal pstrMessageSelfClosingText As String, Optional ByVal pudtButtons As MessageBoxButtons = MessageBoxButtons.OK, Optional ByVal pstrTitle As String = "", Optional ByVal pudtIcon As MessageBoxIcon = MessageBoxIcon.None, Optional ByVal pudtDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, Optional ByVal pudtOptions As MessageBoxOptions = MessageBoxOptions.DefaultDesktopOnly)
  327.         mstrSelfClosingMessageText = pstrMessageSelfClosingText
  328.         MessagePauseSeconds = pintMessagePauseSeconds
  329.         Initialise(True, pudtOwnerHandle, pstrPrompt, pudtButtons, pstrTitle, pudtIcon, pudtDefaultButton, pudtOptions)
  330.     End Sub
  331.  
  332.     'move
  333.     Public Sub New(ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, ByVal pudtMessageLocation As Point, Optional ByVal pudtButtons As MessageBoxButtons = MessageBoxButtons.OK, Optional ByVal pstrTitle As String = "", Optional ByVal pudtIcon As MessageBoxIcon = MessageBoxIcon.None, Optional ByVal pudtDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, Optional ByVal pudtOptions As MessageBoxOptions = MessageBoxOptions.DefaultDesktopOnly)
  334.         MessageLocation = pudtMessageLocation
  335.         Initialise(True, pudtOwnerHandle, pstrPrompt, pudtButtons, pstrTitle, pudtIcon, pudtDefaultButton, pudtOptions)
  336.     End Sub
  337.  
  338.     'alternate buttons
  339.     Public Sub New(ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, ByVal pstrButton1Caption As String, ByVal pstrButton2Caption As String, ByVal pstrButton3Caption As String, Optional ByVal pudtButtons As MessageBoxButtons = MessageBoxButtons.OK, Optional ByVal pstrTitle As String = "", Optional ByVal pudtIcon As MessageBoxIcon = MessageBoxIcon.None, Optional ByVal pudtDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, Optional ByVal pudtOptions As MessageBoxOptions = MessageBoxOptions.DefaultDesktopOnly)
  340.         mstrButtonText(0) = pstrButton1Caption
  341.         mstrButtonText(1) = pstrButton2Caption
  342.         mstrButtonText(2) = pstrButton3Caption
  343.         Initialise(True, pudtOwnerHandle, pstrPrompt, pudtButtons, pstrTitle, pudtIcon, pudtDefaultButton, pudtOptions)
  344.     End Sub
  345.  
  346.     'checkbox
  347.     Public Sub New(ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, ByVal pstrMessageCheckboxText As String, ByVal pblnInitialCheckboxState As Boolean, Optional ByVal pudtButtons As MessageBoxButtons = MessageBoxButtons.OK, Optional ByVal pstrTitle As String = "", Optional ByVal pudtIcon As MessageBoxIcon = MessageBoxIcon.None, Optional ByVal pudtDefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, Optional ByVal pudtOptions As MessageBoxOptions = MessageBoxOptions.DefaultDesktopOnly)
  348.         mstrCheckboxText = pstrMessageCheckboxText
  349.         mblnCheckState = pblnInitialCheckboxState
  350.         Initialise(True, pudtOwnerHandle, pstrPrompt, pudtButtons, pstrTitle, pudtIcon, pudtDefaultButton, pudtOptions)
  351.     End Sub
  352.  
  353.     Private Sub Initialise(ByVal pblnDoShow As Boolean, ByVal pudtOwnerHandle As IWin32Window, ByVal pstrPrompt As String, ByVal pudtButtons As MessageBoxButtons, ByVal pstrTitle As String, ByVal pudtIcon As MessageBoxIcon, ByVal pudtDefaultButton As MessageBoxDefaultButton, ByVal pudtOptions As MessageBoxOptions)
  354.         mstrTitle = pstrTitle
  355.         mstrPrompt = pstrPrompt
  356.         mudtButtons = pudtButtons
  357.         mudtOwnerHandle = pudtOwnerHandle
  358.         mudtIcon = pudtIcon
  359.         mudtDefaultButton = pudtDefaultButton
  360.         mudtOptions = pudtOptions
  361.  
  362.         ' get screen coords
  363.         With Screen.PrimaryScreen.Bounds
  364.             mudtScreenSize.Width = .Width
  365.             mudtScreenSize.Height = .Height
  366.         End With
  367.         If pblnDoShow Then
  368.             ShowMessage()
  369.         End If
  370.     End Sub
  371.  
  372.     Public Function ShowMessage() As System.Windows.Forms.DialogResult
  373.         Dim udtTimerCountdown As System.Threading.Timer
  374.         Dim udtTimer As System.Threading.Timer
  375.         Dim blnFireHook As Boolean = False
  376.         Dim intLoop As Int32
  377.  
  378.         'only set hook if values have been set
  379.         If mintX > 0 Or mintY > 0 Then
  380.             'choosing to repos the messagebox
  381.             ' set hooking proc
  382.             blnFireHook = True
  383.         End If
  384.  
  385.         If mintPause > 0 Then
  386.             'set the timer to fire
  387.             udtTimer = New System.Threading.Timer(New TimerCallback(AddressOf SelfClosingTimerThread), Nothing, mintPauseMili, mintPauseMili)
  388.  
  389.             'no point in doing this unless they have set some text
  390.             If mstrSelfClosingMessageText.Length > 0 Then
  391.                 'create hook if not already done
  392.                 blnFireHook = True
  393.  
  394.                 'no point in doing this for 1 sec or less
  395.                 If mintPause > 1 Then
  396.                     'set the timer to fire
  397.                     udtTimerCountdown = New System.Threading.Timer(New TimerCallback(AddressOf SelfClosingTimerCountdownThread), mintPause, 1000, 1000)
  398.                 End If
  399.             End If
  400.         End If
  401.         If Not blnFireHook Then
  402.             For intLoop = LBound(mstrButtonText) To UBound(mstrButtonText)
  403.                 If Len(mstrButtonText(intLoop)) > 0 Then
  404.                     blnFireHook = True
  405.                     Exit For
  406.                 End If
  407.             Next intLoop
  408.         End If
  409.  
  410.         If blnFireHook Then
  411.             mintHook = API.SetWindowsHookEx(5, AddressOf MessageboxHook, 0, API.GetCurrentThreadId)
  412.         End If
  413.         'invoke Msgbox
  414.         Try
  415.             mudtMessageResult = MessageBox.Show(mudtOwnerHandle, mstrPrompt, mstrTitle, mudtButtons, mudtIcon, mudtDefaultButton, mudtOptions)
  416.         Catch
  417.             'if the window cannot have a parent then
  418.             mudtMessageResult = MessageBox.Show(mstrPrompt, mstrTitle, mudtButtons, mudtIcon, mudtDefaultButton, mudtOptions)
  419.         End Try
  420.         If mintPause > 0 Then
  421.             udtTimer.Dispose()
  422.             udtTimer = Nothing
  423.             If mstrSelfClosingMessageText.Length > 0 Then
  424.                 udtTimerCountdown.Dispose()
  425.                 udtTimerCountdown = Nothing
  426.             End If
  427.         End If
  428.  
  429.         Return mudtMessageResult
  430.     End Function
  431. #End Region
  432.  
  433. #Region " Iridium Threads "
  434.     Public Sub SelfClosingTimerCountdownThread(ByVal State As Object)
  435.         Dim intHandle As Int32
  436.         Static Dim intCountdown As Int32
  437.  
  438.         If intCountdown = 0 Then
  439.             'not set so initialise to max
  440.             intCountdown = mintPause
  441.         End If
  442.         intHandle = API.FindWindow("#32770", mstrTitle)
  443.         If intHandle <> 0 Then
  444.             If mintLabelHwnd > 0 Then
  445.                 API.SetWindowText(mintLabelHwnd, Replace(mstrSelfClosingMessageText, "%1", intCountdown.ToString))
  446.                 intCountdown -= 1
  447.                 If intCountdown = 0 Then intCountdown = -1
  448.             End If
  449.         End If
  450.     End Sub
  451.  
  452.     Public Sub SelfClosingTimerThread(ByVal State As Object)
  453.         Dim intHandle As Int32
  454.         ' A system class is a window class registered by the system which cannot
  455.         ' be destroyed by a processed, e.g. #32768 (a menu), #32769 (desktop
  456.         ' window), #32770 (dialog box), #32771 (task switch window) and
  457.         ' #32770 is a MessageBox
  458.         intHandle = API.FindWindow("#32770", mstrTitle)
  459.         If intHandle <> 0 Then
  460.             API.PostMessage(intHandle, API.WM_CLOSE, 0&, 0&)
  461.         End If
  462.  
  463.     End Sub
  464. #End Region
  465.  
  466. #Region " Iridium Hooks "
  467.     Private Function MessageboxHook(ByVal pintcode As Int32, ByVal pintwParam As Int32, ByVal pintlParam As Int32) As Int32 '(ByVal iHookCode As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  468.         ' Dim hdc As Int32 = API.GetDC(mintCaptionHwnd)
  469.         Dim intFont As Int32
  470.         Dim udtRect As API.RECT
  471.         Dim intHeight As Int32
  472.         Dim intLoop As Int32
  473.         Dim intEnumParam As Int32
  474.         Dim udtFont As Font
  475.         Static blnAddedCheckbox As Boolean
  476.  
  477.         If (0 > pintcode) Then
  478.             Return API.CallNextHookEx(mintHook, pintcode, pintwParam, pintlParam)
  479.         Else
  480.             If pintcode = 4 And mstrCheckboxText.Length > 0 Then
  481.                 'destroying
  482.                 'Returns the value of the checkbox on extended MsgBox
  483.                 mblnCheckState = (API.SendMessage(mintCheckHwnd, API.BM_GETSTATE, 0, 0&) <> 0)
  484.                 API.UnhookWindowsHookEx(mintHook)
  485.             ElseIf pintcode = 5 Then
  486.                 If blnAddedCheckbox Then
  487.                     'no need to do any more in here
  488.                     Return API.CallNextHookEx(mintHook, pintcode, pintwParam, pintlParam)
  489.                 End If
  490.                 'creating
  491.                 If mstrCheckboxText.Length = 0 Then
  492.                     'we only unhook if we are not doing the checkbox thing
  493.                     API.UnhookWindowsHookEx(mintHook)
  494.                 End If
  495.                 'this enumeration allows us to set the labels handle
  496.                 intEnumParam = 1
  497.                 For intLoop = LBound(mstrButtonText) To UBound(mstrButtonText)
  498.                     If Len(mstrButtonText(intLoop)) > 0 Then
  499.                         intEnumParam = 0
  500.                         Exit For
  501.                     End If
  502.                 Next intLoop
  503.                 API.EnumChildWindows(pintwParam, AddressOf UpdateButtonHook, intEnumParam)
  504.  
  505.                 API.GetWindowRect(pintwParam, udtRect)
  506.  
  507.                 'API.SetTextColor(pintwParam, 2345)
  508.                 'API.ReleaseDC(mintCaptionHwnd, hdc)
  509.                 'Get the font for the message window
  510.                 intFont = API.SendMessage(mintCaptionHwnd, API.WM_GETFONT, 0, 0)
  511.                 udtFont = Font.FromHfont(New IntPtr(intFont))
  512.                 intHeight = udtFont.Height
  513.  
  514.                 'should I add a checkbox
  515.                 If mstrCheckboxText.Length > 0 And mintCaptionHwnd > 0 Then
  516.                     If intFont <> 0 Then
  517.  
  518.                         'Create the checkbox control
  519.                         mintCheckHwnd = API.CreateWindowEx(0, _
  520.                                         "Button", _
  521.                                         mstrCheckboxText, _
  522.                                         API.WS_CHILD Or API.WS_VISIBLE Or API.WS_TABSTOP Or API.BS_AUTOCHECKBOX, _
  523.                                         5, (udtRect.Bottom - udtRect.Top) - intHeight - 15 + CType(IIf(mstrSelfClosingMessageText.Length > 0, intHeight, 0), Int32), _
  524.                                         udtRect.Right, intHeight, pintwParam, 0, 0, 0)
  525.  
  526.                         ' set the font of the checkbox to the same as the messagebox
  527.                         API.SendMessage(mintCheckHwnd, API.WM_SETFONT, intFont, 0)
  528.                         ' set the state to a default if true
  529.                         If mblnCheckState Then
  530.                             API.SendMessage(mintCheckHwnd, API.BM_SETCHECK, CType(mblnCheckState, Int32), 0)
  531.                         End If
  532.                         'move the msgbox (and size) to include the new checkbox
  533.                         With udtRect
  534.                             API.MoveWindow(pintwParam, .Left, .Top, .Right - .Left, .Bottom - .Top + intHeight, 1)
  535.                         End With
  536.                     End If
  537.                 End If
  538.                 blnAddedCheckbox = True
  539.  
  540.                 If mintX > 0 Or mintY > 0 Then
  541.                     With udtRect
  542.                         If mintX > (mudtScreenSize.Width - (.Right - .Left) - 1) Then
  543.                             mintX = (mudtScreenSize.Width - (.Right - .Left) - 1)
  544.                         End If
  545.                         If mintY > (mudtScreenSize.Height - (.Bottom - .Top) - 1) Then
  546.                             mintY = (mudtScreenSize.Height - (.Bottom - .Top) - 1)
  547.                         End If
  548.                     End With
  549.                     If mintX < 1 Then mintX = 1
  550.                     If mintY < 1 Then mintY = 1
  551.                 End If
  552.  
  553.                 If mstrSelfClosingMessageText.Length > 0 Then
  554.                     If intFont <> 0 Then
  555.                         'Create the label control
  556.                         mintLabelHwnd = API.CreateWindowEx(0, _
  557.                                         "Static", _
  558.                                         "Closing in xxx secs", _
  559.                                         API.WS_CHILD Or API.WS_VISIBLE Or API.WS_TABSTOP Or &H20, _
  560.                                         5, (udtRect.Bottom - udtRect.Top) - intHeight - 15, _
  561.                                         udtRect.Right, intHeight, pintwParam, 0, 0, 0)
  562.  
  563.                         ' set the font of the checkbox to the same as the messagebox
  564.                         API.SendMessage(mintLabelHwnd, API.WM_SETFONT, intFont, 0)
  565.  
  566.                         'move the msgbox (and size) to include the new checkbox
  567.                         With udtRect
  568.                             API.MoveWindow(pintwParam, .Left, .Top, .Right - .Left, .Bottom - .Top + intHeight + CType(IIf(mstrCheckboxText.Length > 0 And mintCaptionHwnd > 0, intHeight, 0), Int32), 1)
  569.                         End With
  570.                         SelfClosingTimerCountdownThread(Nothing)
  571.                     End If
  572.                 End If
  573.                 If mintX > 0 Or mintY > 0 Then
  574.                     API.SetWindowPos(pintwParam, API.HWND_TOPMOST, mintX, mintY, 0, 0, API.SWP_NOSIZE)
  575.                 End If
  576.             End If
  577.         End If
  578.         'udtFont.Dispose()
  579.     End Function
  580.  
  581.     Private Function UpdateButtonHook(ByVal hWnd As Int32, ByVal lParam As Int32) As Int32
  582.         Dim strClassName As String = API.GetClassName(hWnd)
  583.         Static intCurrent As Int32 = 0
  584.  
  585.         If String.Compare(strClassName, "button", True) = 0 And lParam = 0 Then
  586.             'check we have a caption to set
  587.             If Len(mstrButtonText(intCurrent)) > 0 Then
  588.                 API.SetWindowText(hWnd, mstrButtonText(intCurrent))
  589.             End If
  590.             'increment regardless (the developer may have only set the last param
  591.             intCurrent += 1
  592.         ElseIf String.Compare(strClassName, "static", True) = 0 And _
  593.           String.Compare(API.GetWindowText(hWnd), mstrPrompt, True) = 0 Then
  594.             mintCaptionHwnd = hWnd
  595.         End If
  596.         Return 1
  597.     End Function
  598. #End Region
  599.  
  600. End Class
  601.  
  602. Namespace API
  603.     Public Module API
  604. #Region " API Functions"
  605.         Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
  606.         Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  607.         Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Int32, ByRef lpRect As API.RECT) As Int32
  608.         Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  609.         Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String) As Int32
  610.         Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Int32, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Int32, ByVal x As Int32, ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal hWndParent As Int32, ByVal hMenu As Int32, ByVal hInstance As Int32, ByVal lpParam As Int32) As Int32
  611.         Public Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Int32, ByVal x As Int32, ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal bRepaint As Int32) As Int32
  612.         ' Public Declare Function GetDC Lib "user32" (ByVal hwnd As Int32) As Int32
  613.         ' Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Int32, ByVal hdc As Int32) As Int32
  614.         Public Declare Function GetCurrentThreadId Lib "kernel32" () As Int32
  615.         Public Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As Int32) As Int32
  616.         Public Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As Int32, ByVal ncode As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  617.         ' Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Int32, ByVal crColor As Int32) As Int32
  618.  
  619.         Public Delegate Function EnumChildWindowsCallBack(ByVal hWndParent As Int32, ByVal lParam As Int32) As Int32
  620.         Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Int32, ByVal lpEnumFunc As EnumChildWindowsCallBack, ByVal lParam As Int32) As Int32
  621.  
  622.         Public Delegate Function SetWindowsHookCallBack(ByVal ncode As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
  623.         Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Int32, ByVal lpfn As SetWindowsHookCallBack, ByVal hmod As Int32, ByVal dwThreadId As Int32) As Int32
  624.  
  625.         Public Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Int32, ByVal hWndInsertAfter As Int32, ByVal X As Int32, ByVal Y As Int32, ByVal cx As Int32, ByVal cy As Int32, ByVal wFlags As Int32)
  626.  
  627.         Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
  628.         Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Int32, ByVal lpClassName As String, ByVal nMaxCount As Int32) As Int32
  629.  
  630.         ' a friendlier version of the GetWindowText() API
  631.         Public Function GetWindowText(ByVal pintHandle As Int32) As String
  632.             Dim strValue As String
  633.             Dim intResult As Int32
  634.  
  635.             'init the string buffer
  636.             strValue = Space(256)
  637.             ' call api - the return is the no. of chars found
  638.             intResult = GetWindowText(pintHandle, strValue, strValue.Length)
  639.  
  640.             ' if all was ok
  641.             If intResult > 0 Then
  642.                 'return the trimmed result
  643.                 Return strValue.Substring(0, intResult)
  644.             Else
  645.                 Return ""
  646.             End If
  647.         End Function
  648.  
  649.         ' a friendlier version of the GetClassName() API
  650.         Public Function GetClassName(ByVal pintHandle As Int32) As String
  651.             Dim strValue As String
  652.             Dim intResult As Int32
  653.  
  654.             'init the string buffer
  655.             strValue = Space(256)
  656.             ' call api - the return is the no. of chars found
  657.             intResult = GetClassName(pintHandle, strValue, strValue.Length)
  658.  
  659.             ' if all was ok
  660.             If intResult > 0 Then
  661.                 'return the trimmed result
  662.                 Return strValue.Substring(0, intResult)
  663.             Else
  664.                 Return ""
  665.             End If
  666.         End Function
  667. #End Region
  668.  
  669. #Region " Structures"
  670.         <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
  671.         Public Structure RECT
  672.             Public Left As Int32
  673.             Public Top As Int32
  674.             Public Right As Int32
  675.             Public Bottom As Int32
  676.         End Structure
  677. #End Region
  678.  
  679. #Region " Constants"
  680.         Public Const WM_CLOSE As Int32 = &H10
  681.         Public Const WM_GETFONT As Int32 = &H31
  682.         Public Const WM_SETFONT As Int32 = &H30
  683.  
  684.         Public Const HWND_TOPMOST As Int32 = -1
  685.         Public Const SWP_NOSIZE As Int32 = &H1
  686.  
  687.         Public Const WS_CHILD As Int32 = &H40000000
  688.         Public Const WS_VISIBLE As Int32 = &H10000000
  689.         Public Const WS_TABSTOP As Int32 = &H10000
  690.  
  691.         Public Const BS_AUTOCHECKBOX As Int32 = &H3&
  692.  
  693.         Public Const BM_GETSTATE As Int32 = &HF2
  694.         Public Const BM_SETCHECK As Int32 = &HF1
  695.  
  696. #End Region
  697.  
  698.     End Module
  699. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment