roulette.zip![Name: Noname.bmp
Views: 27
Size: 414.0 KB]()
My version of roulette. Tried to imitate the slowing of the wheel. Drag chips onto board and spin. Good luck.
My version of roulette. Tried to imitate the slowing of the wheel. Drag chips onto board and spin. Good luck.
'FORM1.FRM
Dim NewCursor As Long, OldCursor As Long
'add 2 control: Text1,picture1
Private Sub Command1_Click()
Dim bt() As Byte
'bt = OpenBinFile(App.Path & "\02.ico")
Dim SizeArr() As String
SizeArr = GetIcoSizeArr(bt)
MsgBox Join(SizeArr, vbCrLf)
NewCursor = LoadIcoByByte(bt, 256, 32)
'NewCursor = LoadIcoByByte(bt, 0)
Text1.MousePointer = vbCustom
OldCursor = SetClassLong(Text1.hwnd, GCL_HCURSOR, NewCursor)
Picture1.Width = 256 * Screen.TwipsPerPixelX + Picture1.Width - Picture1.ScaleWidth
Picture1.Height = 256 * Screen.TwipsPerPixelY + Picture1.Height - Picture1.ScaleHeight
DrawIconEx Picture1.Hdc, 0, 0, NewCursor, 256, 256, 0, 0, DI_NORMAL
Picture1.Refresh
End Sub
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Command1_Click
End Sub'*.BAS
Option Explicit
Private Declare Function CreateIconFromResourceEx Lib "user32" (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Type ICONDIRENTRY
bWidth As Byte
bHeight As Byte
bColorCount As Byte
bReserved As Byte
wPlanes As Integer
wBitCount As Integer
dwBytesInRes As Long
dwImageOffset As Long
End Type
Public Const GCL_HCURSOR = -12
Public Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const DI_NORMAL = &H3 '用常规方式绘图 (DI_IMAGE 和 DI_MASK)
Public Declare Function DrawIconEx Lib "user32" (ByVal Hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Public Function GetIcoSizeArr(mIcon() As Byte) As String()
'good
'从字节数组内存流中创建ICO图标
Dim SizeArr() As String
Dim IDETY As ICONDIRENTRY
Dim W As Long, H As Long
Dim i As Long, iLen As Long, pData As Long, id As Long
iLen = LenB(IDETY)
pData = VarPtr(mIcon(0))
ReDim SizeArr(mIcon(4) - 1)
For i = 1 To mIcon(4) '第5个字节就是子图标的数目
CopyMemory IDETY, ByVal pData + 6 + (i - 1) * iLen, iLen '读 图标目录 结构数据
W = IDETY.bWidth
H = IDETY.bHeight
If W = H Then
If W = 0 Then W = 256: H = 256
SizeArr(id) = W & "*" & H & "," & IIf(IDETY.wBitCount = 0, "32位透明", IDETY.wBitCount)
id = id + 1
Else
Exit For
End If
Next
If id > 0 Then
ReDim Preserve SizeArr(id - 1)
Else
ReDim SizeArr(-1 To -1)
End If
GetIcoSizeArr = SizeArr
End Function
Public Function LoadIcoByByte(mIcon() As Byte, Optional ByVal iSize As Long = 16&, Optional BitCount As Long) As Long
'version 2021-5-13
'good
'从字节数组内存流中创建ICO图标,条件:大小,位度
Dim IDETY As ICONDIRENTRY, FindSize As Long
Dim i As Long, iLen As Long, pData As Long
Dim FindBitCount As Boolean
If iSize = 0 Then iSize = 256
If iSize = 256 Then
FindSize = 0
Else
FindSize = iSize
End If
iLen = LenB(IDETY)
pData = VarPtr(mIcon(0))
For i = 1 To mIcon(4) '第5个字节就是子图标的数目
CopyMemory IDETY, ByVal pData + 6 + (i - 1) * iLen, iLen '读 图标目录 结构数据
If BitCount = 0 Then
FindBitCount = True
Else
FindBitCount = IDETY.wBitCount = BitCount
End If
If FindBitCount Then
If iSize = -1 Then
iSize = IDETY.bWidth
If iSize = 0 Then iSize = 256 'edit:2021-5-13
GoTo DoLoadIco
ElseIf IDETY.bWidth = FindSize Then '寻找符合尺寸的子图标
DoLoadIco:
LoadIcoByByte = CreateIconFromResourceEx(mIcon(IDETY.dwImageOffset) _
, IDETY.dwBytesInRes, -1, &H30000, iSize, iSize, 0)
Exit For
End If
End If
Next
End Function
Function OpenBinFile(filename As String, Optional ErrInfo As String) As Byte()
'[mycode_id:1903],edittime:2011/7/11 13:27:34
On Error Resume Next
Dim hFile As Integer
hFile = FreeFile
Open filename For Binary As #hFile
ReDim OpenBinFile(LOF(hFile) - 1)
Get #hFile, , OpenBinFile
Close #hFile
End FunctionSub Main()
Dim AsyncBeep2 As New AsyncBeep
AsyncBeep2.Play 1000, 2024
MsgBox "ok"
End Sub' 异步版 Beep,作者YY菌,技术交流群(QQ):250264265
'AsyncBeep.cls
'Asynchronous version of Beep, author YY bacteria, technical exchange group (QQ): 250264265
Option Explicit
'Input and output status
Private Type IO_STATUS_BLOCK
Status As Long
Information As Long
End Type
'Unicode string
Private Type UNICODE_STRING
Length As Integer
MaximumLength As Integer
Buffer As String
End Type
'Object properties
Private Type OBJECT_ATTRIBUTES
Length As Long
RootDirectory As Long
ObjectName As Long
Attributes As Long
SecurityDescriptor As Long
SecurityQualityOfService As Long
End Type
'Beep parameter
Private Type BEEP_SET_PARAMETERS
Frequency As Long
Duration As Long
End Type
'Beep related constants
Const BEEP_FREQUENCY_MINIMUM& = &H25&
Const BEEP_FREQUENCY_MAXIMUM& = &H7FFF&
Const IOCTL_BEEP_SET& = &H10000
Const DD_BEEP_DEVICE_NAME$ = "\Device\Beep"
'Permission constant
Private Enum ACCESS_MASK
FILE_READ_DATA = &H1&
FILE_WRITE_DATA = &H2&
End Enum
'Open constant
Private Enum CREATE_DISPOSITION
CREATE_NEW = 1
CREATE_ALWAYS = 2
OPEN_EXISTING = 3
OPEN_ALWAYS = 4
TRUNCATE_EXISTING = 5
End Enum
'API statement
Private Declare Function NtCreateFile Lib "ntdll" (ByRef FileHandle As Long, ByVal DesiredAccess As ACCESS_MASK, ObjectAttributes As OBJECT_ATTRIBUTES, IoStatusBlock As IO_STATUS_BLOCK, ByVal AllocationSize As Long, ByVal FileAttributes As Long, ByVal ShareAccess As ACCESS_MASK, ByVal CreateDisposition As CREATE_DISPOSITION, ByVal CreateOptions As Long, EaBuffer As Any, ByVal EaLength As Long) As Long
Private Declare Function NtDeviceIoControlFile Lib "ntdll" (ByVal FileHandle As Long, ByVal EventHandle As Long, ByVal ApcRoutine As Long, ByVal ApcContext As Long, IoStatusBlock As IO_STATUS_BLOCK, ByVal IoControlCode As Long, InputBuffer As Any, ByVal InputBufferLength As Long, OutputBuffer As Any, ByVal OutputBufferLength As Long) As Long
Private Declare Function NtClose Lib "ntdll" (ByVal FileHandle As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Device handle
Dim hDev As Long
'Constructor (open the Beep device)
Private Sub Class_Initialize()
Dim iosb As IO_STATUS_BLOCK
Dim path As UNICODE_STRING
Dim objAttr As OBJECT_ATTRIBUTES
With path
.Buffer = DD_BEEP_DEVICE_NAME
.Length = LenB(.Buffer)
.MaximumLength = .Length + 2
End With
With objAttr
.Length = path.Length
.ObjectName = VarPtr(path)
End With
NtCreateFile hDev, FILE_WRITE_DATA, objAttr, iosb, 0&, 0&, FILE_READ_DATA Or FILE_WRITE_DATA, OPEN_EXISTING, 0&, ByVal 0&, 0&
End Sub
'Destructor (close the Beep device)
Private Sub Class_Terminate()
NtClose hDev
End Sub
'Get Beep device handle
Public Property Get Handle() As Long
Handle = hDev
End Property
'Play the sound of the specified frequency and duration
Public Function Play(ByVal dwFreq As Long, ByVal dwDuration As Long) As Boolean
Dim iosb As IO_STATUS_BLOCK
Dim bsp As BEEP_SET_PARAMETERS
With bsp
.Frequency = dwFreq
.Duration = dwDuration
End With
Play = NtDeviceIoControlFile(hDev, 0&, 0&, 0&, iosb, IOCTL_BEEP_SET, bsp, LenB(bsp), ByVal 0&, 0&) >= 0
End FunctionPrivate Type MODULEINFO
lpBaseDLL As Long
ImageSize As Long
EntryPoint As Long
End Type
Private Declare Function GetModuleInformation Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, mInfo As MODULEINFO, ByVal cbSize As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Function GetVBHeader() As Long
Dim mInfo As MODULEINFO
GetModuleInformation GetCurrentProcess(), &H400000, mInfo, 12
If mInfo.EntryPoint Then CopyMemory GetVBHeader, ByVal mInfo.EntryPoint + 1, 4
End FunctionOption Explicit
Private Declare Function EndDoc Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function EndPage Lib "gdi32" (ByVal hDC As Long) As Long
Private Type DOCINFO
cbSize As Long
DocName As String
Output As String
Datatype As String
fwType As Long
End Type
Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" ( _
ByVal hDC As Long, _
ByRef DOCINFO As DOCINFO) As Long
Private Declare Function StartPage Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" ( _
ByVal hDC As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal Text As String, _
ByVal nCount As Long) As Long
Private Sub Main()
Const LMARGIN As Long = 300
Const TMARGIN As Long = 500
Dim P As Printer
Dim DOCINFO As DOCINFO
Dim LineHeight As Long
Dim Y As Long
Dim I As Long
Dim Text As String
For Each P In Printers
If P.DeviceName = "Microsoft Print to PDF" Then
Set Printer = P
GoTo FoundPDF
End If
Next
MsgBox "No ""Microsoft Print to PDF"" driver!", vbExclamation
Exit Sub
FoundPDF:
'We can't use Printer.EndPage, Printer.EndDoc, Printer.Print, Printer.PaintPicture,
'etc. because we need StartDoc() which VB6 will try to do for us "automagically,"
'thus preventing us from designating the output file programmatically. I.e. the
'user will always see the driver's dialog to pick an output file.
With Printer
On Error Resume Next
Kill App.Path & "\specific.pdf"
On Error GoTo 0
With DOCINFO
.cbSize = LenB(DOCINFO)
.DocName = "To specific file"
.Output = App.Path & "\specific.pdf"
End With
StartDoc .hDC, DOCINFO
With .Font
.Name = "Arial"
.Size = 12
End With
LineHeight = Int(.ScaleY(.TextHeight("X"), .ScaleMode, vbPixels))
StartPage .hDC
Y = TMARGIN
For I = 1 To 10
Text = "Hello"
TextOut .hDC, LMARGIN, Y, Text, Len(Text)
Y = Y + LineHeight
Text = "world!"
TextOut .hDC, LMARGIN + 250, Y, Text, Len(Text)
Y = Y + LineHeight * 2 'Double-space here.
Next
EndPage .hDC
EndDoc .hDC
End With
MsgBox "Complete"
End Sub'Dim WithEvents mSocket As SimpleSock
'Set mSocket = New SimpleSockOption Explicit
Private Const PROG_TOTAL As Long = 500
Private ProgCompleted As Long
Private WithEvents TaskbarList3 As TaskbarList3
Private Sub Command1_Click()
TaskbarList3.SetProgressState TBPF_NORMAL
Command1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Form_Initialize()
'Could also do this in a Form_Load event handler instead:
Set TaskbarList3 = New TaskbarList3
TaskbarList3.ConnectFormToShell32 Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Redundant since we are unloading anyway. But normally you'd do this once
'the action's indicated progress has completed, so we'll show it here:
With TaskbarList3
If .Connected Then .SetProgressState TBPF_NOPROGRESS
End With
End Sub
Private Sub TaskbarList3_Connected()
Command1.Enabled = True
End Sub
Private Sub Timer1_Timer()
With TaskbarList3
If .Connected Then 'Redundant test here, because to get here the Connected
'event has been raised so that Command1 got enabled so that
'the user could have pressed it so that Timer1 got enabled.
ProgCompleted = ProgCompleted + 1
If ProgCompleted > PROG_TOTAL Then ProgCompleted = 0
.SetProgressValue ProgCompleted, PROG_TOTAL
End If
End With
End Sub