home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Boring_ana2164141022009.psc / Form1.frm < prev    next >
Text File  |  2009-10-02  |  15KB  |  383 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   0  'None
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   1275
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   1500
  9.    Icon            =   "Form1.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1275
  12.    ScaleWidth      =   1500
  13.    ShowInTaskbar   =   0   'False
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.Timer Timer1 
  16.       Enabled         =   0   'False
  17.       Interval        =   200
  18.       Left            =   1740
  19.       Top             =   1380
  20.    End
  21. End
  22. Attribute VB_Name = "Form1"
  23. Attribute VB_GlobalNameSpace = False
  24. Attribute VB_Creatable = False
  25. Attribute VB_PredeclaredId = True
  26. Attribute VB_Exposed = False
  27. Option Explicit
  28. 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
  29. Private Declare Function SetTextColor Lib "gdi32" (ByVal HDC As Long, ByVal crColor As Long) As Long
  30. Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
  31. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  32. Private Declare Function ReleaseCapture Lib "user32" () As Long
  33. Private Declare Function StretchDIBits& Lib "gdi32" (ByVal HDC&, ByVal x&, ByVal y&, ByVal dX&, ByVal dy&, ByVal SrcX&, ByVal SrcY&, ByVal Srcdx&, ByVal Srcdy&, Bits As Any, BInf As Any, ByVal Usage&, ByVal Rop&)
  34. 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
  35. Private Declare Function SetBkMode Lib "gdi32" (ByVal HDC As Long, ByVal nBkMode As Long) As Long
  36. Private Declare Function CreateRoundRectRgn Lib "gdi32" (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
  37. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  38. Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
  39. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
  40. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  41. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  42. Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal nHeight As Long, ByVal nWidth As Long, ByVal nEscapement As Long, ByVal nOrientation As Long, ByVal fnWeight As Long, ByVal fdwItalic As Boolean, ByVal fdwUnderline As Boolean, ByVal fdwStrikeOut As Boolean, ByVal fdwCharSet As Long, ByVal fdwOutputPrecision As Long, ByVal fdwClipPrecision As Long, ByVal fdwQuality As Long, ByVal fdwPitchAndFamily As Long, ByVal lpszFace As String) As Long
  43. Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
  44. Private Declare Function DeleteDC Lib "gdi32" (ByVal HDC As Long) As Long
  45. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  46. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal HDC As Long, ByVal iCapabilitiy As Long) As Long
  47. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal HDC As Long) As Long
  48. Private Declare Function SelectObject Lib "gdi32" (ByVal HDC As Long, ByVal hObject As Long) As Long
  49. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  50.  
  51. Private SCRw&
  52. Private SCRh&
  53. Private CentreW&
  54. Private CentreH&
  55. Private ClockSize&
  56. Private m_oLine As LineGS
  57. Private mBlank As cDIBSection
  58. Private mBuffer As cDIBSection
  59.  
  60. Private SSAngle As Single
  61.  
  62. Const FW_DONTCARE = 0
  63. Const FW_THIN = 100
  64. Const FW_EXTRALIGHT = 200
  65. Const FW_LIGHT = 300
  66. Const FW_NORMAL = 400
  67. Const FW_MEDIUM = 500
  68. Const FW_SEMIBOLD = 600
  69. Const FW_BOLD = 700
  70. Const FW_EXTRABOLD = 800
  71. Const FW_HEAVY = 900
  72. Const FW_BLACK = FW_HEAVY
  73. Const FW_DEMIBOLD = FW_SEMIBOLD
  74. Const FW_REGULAR = FW_NORMAL
  75. Const FW_ULTRABOLD = FW_EXTRABOLD
  76. Const FW_ULTRALIGHT = FW_EXTRALIGHT
  77. 'used with fdwCharSet
  78. Const ANSI_CHARSET = 0
  79. Const DEFAULT_CHARSET = 1
  80. Const SYMBOL_CHARSET = 2
  81. Const SHIFTJIS_CHARSET = 128
  82. Const HANGEUL_CHARSET = 129
  83. Const CHINESEBIG5_CHARSET = 136
  84. Const OEM_CHARSET = 255
  85. 'used with fdwOutputPrecision
  86. Const OUT_CHARACTER_PRECIS = 2
  87. Const OUT_DEFAULT_PRECIS = 0
  88. Const OUT_DEVICE_PRECIS = 5
  89. 'used with fdwClipPrecision
  90. Const CLIP_DEFAULT_PRECIS = 0
  91. Const CLIP_CHARACTER_PRECIS = 1
  92. Const CLIP_STROKE_PRECIS = 2
  93. 'used with fdwQuality
  94. Const DEFAULT_QUALITY = 0
  95. Const DRAFT_QUALITY = 1
  96. Const PROOF_QUALITY = 2
  97. 'used with fdwPitchAndFamily
  98. Const DEFAULT_PITCH = 0
  99. Const FIXED_PITCH = 1
  100. Const VARIABLE_PITCH = 2
  101. Const OPAQUE = 2
  102. Const TRANSPARENT = 1
  103. Const HWND_TOPMOST = -1
  104. Const HWND_NOTOPMOST = -2
  105. Const SWP_NOSIZE = &H1
  106. Const SWP_NOMOVE = &H2
  107. Const SWP_NOACTIVATE = &H10
  108. Const SWP_SHOWWINDOW = &H40
  109. Const LOGPIXELSY = 90
  110. Const COLOR_WINDOW = 5
  111. Private Function CreateMyFont(nSize&, sFontFace$, bBold As Boolean, bItalic As Boolean) As Long
  112. Static r&, d&
  113.  
  114.     DeleteDC r: r = GetDC(0)
  115.     d = GetDeviceCaps(r, LOGPIXELSY)
  116.     CreateMyFont = CreateFont(-MulDiv(nSize, d, 72), 0, 0, 0, _
  117.                               IIf(bBold, FW_BOLD, FW_NORMAL), bItalic, False, False, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, _
  118.                               CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, sFontFace) 'gdi 2
  119. End Function
  120.  
  121. Private Sub SetFont(DC&, sFace$, nSize&)
  122. Static c&
  123.     ReleaseDC DC, c: DeleteDC c
  124.     c = CreateMyFont(nSize, sFace, False, False)
  125.     DeleteObject SelectObject(DC, c)
  126. End Sub
  127. Private Sub Form_DblClick()
  128.     Set mBlank = Nothing
  129.     Set mBuffer = Nothing
  130.     Set m_oLine = Nothing
  131.     Unload Me
  132.     End
  133. End Sub
  134. Sub SetAlpha()
  135.     Dim Ret&
  136.     Static AlphaOn As Boolean
  137.     Const LWA_COLORKEY = &H1
  138.     Const LWA_ALPHA = &H2
  139.     Const GWL_EXSTYLE = (-20)
  140.     Const WS_EX_LAYERED = &H80000
  141.     
  142.     Ret = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
  143.     Ret = Ret Or WS_EX_LAYERED
  144.     SetWindowLong Me.hwnd, GWL_EXSTYLE, Ret
  145.     
  146.     SetLayeredWindowAttributes Me.hwnd, 0, IIf(AlphaOn, 255, 96), LWA_ALPHA
  147.     AlphaOn = Not AlphaOn
  148.     SaveSetting "MTCLOCK", "Settings", "opacity", IIf(AlphaOn, "1", "0")
  149. End Sub
  150. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  151. If KeyCode = 27 Then CentreClock
  152. If KeyCode = 38 Then ClockSizeChange 1 'up
  153. If KeyCode = 40 Then ClockSizeChange -1 'up
  154. If KeyCode = 84 Then SetWindowTopmost Me.hwnd
  155. If KeyCode = 79 Then SetAlpha
  156. End Sub
  157.  
  158. Sub ClockSizeChange(nSize%)
  159.     If nSize < 0 And Me.Width <= 450 Then Exit Sub
  160.     If nSize > 0 And Me.Height > (Screen.Height * 0.8) Then Exit Sub
  161.     
  162.     Me.Height = Me.Height + (nSize * 150)
  163.     Me.Width = Me.Height
  164.     SetForm
  165. End Sub
  166. Sub SetForm()
  167. Dim h&
  168.     If Me.Height <> Me.Width Then
  169.         If Me.Height > Me.Width Then
  170.             Me.Height = Me.Width
  171.         Else
  172.             Me.Width = Me.Height
  173.         End If
  174.     End If
  175.  
  176.     'h = CreateRoundRectRgn(0, 0, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 21, 21)
  177.     h = CreateEllipticRgn(0, 0, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY)
  178.                             
  179.     SetWindowRgn Me.hwnd, h, False
  180. End Sub
  181. Private Sub Form_Load()
  182.  
  183.  
  184.     Set m_oLine = New LineGS
  185.     Set mBlank = New cDIBSection
  186.     Set mBuffer = New cDIBSection
  187.  
  188.     Me.Left = GetSetting("MTCLOCK", "Settings", "left", 0)
  189.     Me.Top = GetSetting("MTCLOCK", "Settings", "top", 0)
  190.     Me.Width = GetSetting("MTCLOCK", "Settings", "width", 1200)
  191.     If GetSetting("MTCLOCK", "Settings", "topmost", "0") = "1" Then SetWindowTopmost Me.hwnd
  192.     If GetSetting("MTCLOCK", "Settings", "opacity", "0") = "1" Then SetAlpha
  193.     
  194.     Me.Height = Me.Width
  195.     
  196.     SetForm
  197.  
  198.  
  199.     If Me.Top < 0 Or Me.Top > Screen.Height Or Me.Left < 0 Or Me.Left > Screen.Width Then CentreClock
  200.     
  201.     Timer1.Enabled = True
  202.     
  203. End Sub
  204. Sub CentreClock()
  205. Me.Move Screen.Width \ 2, Screen.Height \ 2, 1200, 1200
  206. SetForm
  207. End Sub
  208. Private Sub SplitRGB(ByVal clr&, r&, g&, b&)
  209.     r = clr And &HFF: g = (clr \ &H100&) And &HFF: b = (clr \ &H10000) And &HFF
  210. End Sub
  211. Private Sub Gradient(DC&, x&, y&, dX&, dy&, ByVal c1&, ByVal c2&, v As Boolean)
  212. Dim r1&, g1&, b1&, r2&, g2&, b2&, b() As Byte
  213. Dim i&, lR!, lG!, lB!, dR!, dG!, dB!, BI&(9), xx&, yy&, dd&, hRPen&
  214.     If dX = 0 Or dy = 0 Then Exit Sub
  215.     If v Then xx = 1: yy = dy: dd = dy Else xx = dX: yy = 1: dd = dX
  216.     SplitRGB c1, r1, g1, b1: SplitRGB c2, r2, g2, b2: ReDim b(dd * 4 - 1)
  217.     dR = (r2 - r1) / (dd - 1): lR = r1: dG = (g2 - g1) / (dd - 1): lG = g1: dB = (b2 - b1) / (dd - 1): lB = b1
  218.     For i = 0 To (dd - 1) * 4 Step 4: b(i + 2) = lR: lR = lR + dR: b(i + 1) = lG: lG = lG + dG: b(i) = lB: lB = lB + dB: Next
  219.     BI(0) = 40: BI(1) = xx: BI(2) = -yy: BI(3) = 2097153: StretchDIBits DC, x, y, dX, dy, 0, 0, xx, yy, b(0), BI(0), 0, vbSrcCopy
  220. End Sub
  221.  
  222. Function GimmeX(ByVal aIn As Single, lIn As Long) As Long
  223.     GimmeX = Sin(aIn * 0.01745329251994) * lIn
  224. End Function
  225. Function GimmeY(ByVal aIn As Single, lIn As Long) As Long
  226.     GimmeY = Cos(aIn * 0.01745329251994) * lIn
  227. End Function
  228. Function CorrectForAngle(aIn As Single) As Single
  229. CorrectForAngle = 180 - aIn
  230. If CorrectForAngle > 359 Then CorrectForAngle = CorrectForAngle - 360
  231. If CorrectForAngle < 0 Then CorrectForAngle = CorrectForAngle + 360
  232. End Function
  233. Sub DrawHands(the_HDC&)
  234. Dim aMM As Single
  235. Dim aHH As Single
  236. Dim aSS As Single
  237. Dim posX&(1), posY&(1)
  238. Dim hhSize&
  239. Dim mmSize&
  240. Dim ssSize&
  241.  
  242.  
  243.     hhSize = ClockSize * 0.5
  244.     mmSize = ClockSize * 0.8
  245.     ssSize = ClockSize
  246.  
  247.     aHH = CorrectForAngle((Format(Now, "HH") * 30) + (Format(Now, "NN") / 2))
  248.     aMM = CorrectForAngle(Format(Now, "NN") * 6)
  249.     aSS = CorrectForAngle(Format(Now, "ss") * 6)
  250.     
  251.     'hh
  252.     posX(0) = GimmeX(aHH, 5) + CentreW: posY(0) = GimmeY(aHH, 5) + CentreH
  253.     posX(1) = GimmeX(aHH, hhSize) + CentreW: posY(1) = GimmeY(aHH, hhSize) + CentreH
  254.     m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), 0
  255.     
  256.     'mm
  257.     posX(0) = GimmeX(aMM, 5) + CentreW: posY(0) = GimmeY(aMM, 5) + CentreH
  258.     posX(1) = GimmeX(aMM, mmSize) + CentreW: posY(1) = GimmeY(aMM, mmSize) + CentreH
  259.     m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), 0
  260.  
  261.     'ss
  262.     posX(0) = GimmeX(aSS, 5) + CentreW: posY(0) = GimmeY(aSS, 5) + CentreH
  263.     posX(1) = GimmeX(aSS, ssSize) + CentreW: posY(1) = GimmeY(aSS, ssSize) + CentreH
  264.     m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), RGB(110, 110, 110)
  265.     
  266.     
  267. End Sub
  268. Private Sub SetWindowTopmost(hwnd&)
  269. Static OnTop As Boolean
  270.  
  271.     If OnTop Then
  272.         SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
  273.     Else
  274.         SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
  275.     End If
  276.     
  277.     OnTop = Not OnTop
  278.     
  279.     SaveSetting "MTCLOCK", "Settings", "topmost", IIf(OnTop, "1", "0")
  280.     
  281. End Sub
  282. Sub DrawClockFace(the_HDC&)
  283. Dim a As Single, b As Single
  284. Dim posX&(1), posY&(1)
  285.  
  286.     For a = 0 To (ClockSize * 1.5) Step 6
  287.         m_oLine.CircleGP the_HDC, CentreW, CentreH, CLng(a), CLng(a), RGB(100, 150, 190)
  288.     Next
  289.     For a = 0 To 359 Step 6
  290.         posX(0) = GimmeX(a, ClockSize * 0.9) + CentreW
  291.         posY(0) = GimmeY(a, ClockSize * 0.9) + CentreH
  292.         
  293.         posX(1) = GimmeX(a, ClockSize * 0.95) + CentreW
  294.         posY(1) = GimmeY(a, ClockSize * 0.95) + CentreH
  295.         m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), RGB(100, 150, 190)
  296.     Next
  297.     For b = 0 To 5 Step 0.5
  298.         For a = b To 359 Step 30
  299.             posX(0) = GimmeX(a, ClockSize * 0.9) + CentreW
  300.             posY(0) = GimmeY(a, ClockSize * 0.9) + CentreH
  301.             
  302.             posX(1) = GimmeX(a, ClockSize) + CentreW
  303.             posY(1) = GimmeY(a, ClockSize) + CentreH
  304.             m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), 0
  305.         Next
  306.     Next
  307.     For a = 3 To 359 Step 30
  308.         posX(0) = GimmeX(a, ClockSize * 0.9) + CentreW
  309.         posY(0) = GimmeY(a, ClockSize * 0.9) + CentreH
  310.         
  311.         posX(1) = GimmeX(a, ClockSize) + CentreW
  312.         posY(1) = GimmeY(a, ClockSize) + CentreH
  313.         m_oLine.LineGP the_HDC, posX(0), posY(0), posX(1), posY(1), vbWhite
  314.     Next
  315.     
  316.     m_oLine.CircleGP the_HDC, CentreW, CentreH, 4, 4, 0, Thick
  317.     m_oLine.CircleGP the_HDC, CentreW, CentreH, 2, 2, 0
  318.     m_oLine.CircleGP the_HDC, CentreW, CentreH, 3, 3, vbWhite
  319.     
  320.     For b = 0 To 2
  321.         m_oLine.CircleGP the_HDC, CentreW, CentreH, ((Me.Width \ Screen.TwipsPerPixelX) \ 2) - b, ((Me.Height \ Screen.TwipsPerPixelY) \ 2) - b, 0, Thick
  322.     Next
  323. End Sub
  324.  
  325. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  326. If Button = vbLeftButton Then
  327.     ReleaseCapture
  328.     SendMessage Me.hwnd, &HA1, 2, 0&
  329. End If
  330. End Sub
  331.  
  332. Private Sub Form_Resize()
  333.  
  334.     SCRw = Me.Width / Screen.TwipsPerPixelX
  335.     SCRh = Me.Height / Screen.TwipsPerPixelY
  336.     CentreW = (SCRw / 2) - 1
  337.     CentreH = (SCRh / 2) - 1
  338.     ClockSize = IIf(CentreW > CentreH, CentreH, CentreW) * 0.9
  339.             
  340.     mBlank.ClearUp
  341.     mBlank.Create SCRw, SCRh
  342.     SetBkMode mBlank.HDC, TRANSPARENT
  343.     Gradient mBlank.HDC, 0, 0, SCRw, SCRh, RGB(100, 150, 190), RGB(200, 210, 240), True
  344.     
  345.     DrawClockFace mBlank.HDC
  346.             
  347.     mBuffer.ClearUp
  348.     mBuffer.Create SCRw, SCRh
  349.     SetBkMode mBuffer.HDC, TRANSPARENT
  350.     
  351.     SetFont mBuffer.HDC, "Small Caps", 7
  352.  
  353. End Sub
  354. Private Sub BlankToBuffer()
  355.     BitBlt mBuffer.HDC, 0, 0, SCRw, SCRh, mBlank.HDC, 0, 0, vbSrcCopy
  356. End Sub
  357. Private Sub BufferToScreen()
  358.     BitBlt Me.HDC, 0, 0, SCRw, SCRh, mBuffer.HDC, 0, 0, vbSrcCopy
  359. End Sub
  360.  
  361. Private Sub Form_Unload(Cancel As Integer)
  362.     SaveSetting "MTCLOCK", "Settings", "left", Me.Left
  363.     SaveSetting "MTCLOCK", "Settings", "top", Me.Top
  364.     SaveSetting "MTCLOCK", "Settings", "width", Me.Width
  365.  
  366. End Sub
  367.  
  368. Private Sub Timer1_Timer()
  369. Dim s$
  370.     s = Format(Now, "HH:NN:SS")
  371.     BlankToBuffer
  372.     
  373.     SetTextColor mBuffer.HDC, vbWhite
  374.     TextOut mBuffer.HDC, CentreW - 16, CentreH + 12, s, 8
  375.     SetTextColor mBuffer.HDC, RGB(50, 50, 50)
  376.     TextOut mBuffer.HDC, CentreW - 16, CentreH + 11, s, 8
  377.     
  378.     DrawHands mBuffer.HDC
  379.     BufferToScreen
  380. End Sub
  381.  
  382.  
  383.