Archive

Archive for July, 2008

Open The window at start menu

‘declaration
Private Declare Sub keybd_event Lib “user32″ (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const MENU_KEYCODE = 91

‘form
‘ Press start button
keybd_event MENU_KEYCODE, 0, 0, 0

‘ Release start button
keybd_event MENU_KEYCODE, 0, KEYEVENTF_KEYUP, 0

Upper and Lower case

‘add 2 command buttons and 1 text

Private Sub Command1_Click()
Text1.Text = CapFirst$(Text1.Text)
End Sub

Private Sub Command2_Click()
Text1.Text = LCase$(Text1.Text)
End Sub

‘add 1 module
Declare Function CapFirst$ Lib “CAPFIRST.DLL” Alias “CAPFIRST” (ByVal St$)

Categories: Source Code Tags:

Time Zone

the Time Conversion Zone.”

Listing 1

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION_REG
Bias As Long
StandardBias As Long
DaylightBias As Long
StandardDate As SYSTEMTIME
DaylightDate As SYSTEMTIME
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Sub CopyMemory Lib _
“kernel32″ Alias “RtlMoveMemory” (lpvDest As Any, _
lpvSource As Any, ByVal cbCopy As Long)

Private Declare Function GetTimeZoneInformation Lib “kernel32″ _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Listing 2

Private Function DateFromSYSTEMTIME _
(aSYSTEMTIME As SYSTEMTIME, _
Optional iRefYear As Integer) As Variant

‘Returns either a Date or Null using values in
‘SYSTEMTIME structure

With aSYSTEMTIME
If .wDay = 0 And .wDayOfWeek = 0 And _.wHour = 0 And _
.wMilliseconds = 0 And .wMinute = 0 And .wMonth = 0 And _
.wSecond = 0 And .wYear = 0 Then

‘all structure fields contain 0 indicating invalid date
DateFromSYSTEMTIME = Null
Else
If .wYear = 0 Then
‘day-in-month format; uses wMonth, wDayOfWeek,
‘wDay to identify a specific occurance of
‘a weekday in that month. The year is specified by
‘iRefYear or the current year.

‘if no year passed in, use current year
If iRefYear = 0 Then iRefYear = Year(Date)

DateFromSYSTEMTIME = _
WeekdayOccurance _
(iRefYear, .wMonth, (.wDayOfWeek + 1), _
.wDay) + TimeSerial(.wHour, .wMinute, _
.wSecond)
Else
‘absolute format; includes year
DateFromSYSTEMTIME = _
DateSerial(.wYear, .wMonth, .wDay) + _
TimeSerial(.wHour, .wMinute, .wSecond)
End If
End If
End With
End Function

Listing 3

Public Sub Refresh()

‘Fills time zone information from registry and/or api call

Dim strTimeZoneKey As String
Dim vRet As Variant
Dim bytArray() As Byte
Dim tziTimeZoneInfoStruct As _
TIME_ZONE_INFORMATION
Dim oSystem As New CSystem
Dim objRegKey As RegKey
Dim sKey As String

If mlngID = tzcTimeZoneSystem Then
‘get current system time zone settings
vRet = GetTimeZoneInformation(tziTimeZoneInfoStruct)
With tziTimeZoneInfoStruct
mstrStandardShortName = StripNull(StrConv( _
.StandardName, vbFromUnicode))
mstrDaylightShortName = StripNull(StrConv( _
.DaylightName, vbFromUnicode))
mtzrTimeZoneInfoRegistryStruct.Bias = .Bias
mtzrTimeZoneInfoRegistryStruct.DaylightBias = _
.DaylightBias
mtzrTimeZoneInfoRegistryStruct.DaylightDate = _
.DaylightDate
mtzrTimeZoneInfoRegistryStruct.StandardBias = _
.StandardBias
mtzrTimeZoneInfoRegistryStruct.StandardDate = _
.StandardDate
End With

mlngID = GetIDFromShortName(mstrStandardShortName)
strTimeZoneKey = GetTimeZoneRegKeyFromID(mlngID)
If Len(strTimeZoneKey) > 0 Then

If oSystem.Platform = emsOSPlatformWindowsNT Then
sKey = TZ_REG_KEY_NT & strTimeZoneKey
Else
sKey = TZ_REG_KEY_95 & strTimeZoneKey
End If

Set objRegKey = RegKeyFromString( _
“\HKEY_LOCAL_MACHINE\” & sKey)

‘ DisplayName is not returned in TIME_ZONE_INFORMATION
‘ structure, read from registry
mstrDisplayName = objRegKey.Values.Item( _
“Display”).Value
End If

Else
‘get specified time zone from registry

strTimeZoneKey = GetTimeZoneRegKeyFromID(mlngID)
If Len(strTimeZoneKey) > 0 Then

If oSystem.Platform = emsOSPlatformWindowsNT Then
sKey = TZ_REG_KEY_NT & strTimeZoneKey
Else
sKey = TZ_REG_KEY_95 & strTimeZoneKey
End If

Set objRegKey = RegKeyFromString( _
“\HKEY_LOCAL_MACHINE\” & sKey)
mstrDisplayName = objRegKey.Values.Item( _
“Display”).Value
mstrDaylightShortName = objRegKey.Values.Item( _
“Dlt”).Value
mstrStandardShortName = objRegKey.Values.Item( _
“Std”).Value

vRet = objRegKey.Values.Item(“TZI”).Value

If IsEmpty(vRet) Then
Err.Raise vbObjectError, , _
“Registry key or value not valid.”
End If

bytArray = vRet
‘assigns byte array in variant to dynamic byte array

‘copy bytes into appropriate structure locations
CopyMemory mtzrTimeZoneInfoRegistryStruct, _
bytArray(0), Len(mtzrTimeZoneInfoRegistryStruct)

End If
End If

‘if the wMonth entry is 0 then time zone doesn’t support
‘daylight savings and therefore will not have values for
‘StandardDate and DaylightDate

If mtzrTimeZoneInfoRegistryStruct.StandardDate.wMonth _
= 0 Then
mbolSupportDaylight = False
Else
mbolSupportDaylight = True
End If
End Sub

Categories: Source Code Tags:

Obtaining the hWnd for the WebBrowser control

‘Obtaining the hWnd for the WebBrowser control

Add this code to a Module:

Option Explicit

Public Const GW_CHILD = 5
Public Declare Function GetWindow Lib “user32″ (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Public Declare Function GetClassName Lib “user32″ Alias “GetClassNameA” _
(ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long

Public Function GetBrowserWindow(hwndBrowserContainer As Long) As Long

Dim RetVal As Long
Dim Result As Long
Dim hwndChild As Long
Dim hwnd As Long
Dim ClassString As String * 256

hwnd = hwndBrowserContainer
hwndChild = hwnd

While (Result = 0) And (hwndChild <> 0)
hwndChild = GetWindow(hwnd, GW_CHILD)
If hwndChild <> 0 Then
hwnd = hwndChild
RetVal = GetClassName(hwnd, ClassString, 256)
If Left$(ClassString, InStr(ClassString, Chr$(0)) – 1) = _
“HTML_Internet Explorer” Then
Result = 1
End If
End If
Wend

GetBrowserWindow = hwnd

End Function

Categories: Source Code Tags: