How to list the days of month based year?
for xample:
VarYear=2020
VarMonth =12 (December)
for xample:
VarYear=2020
VarMonth =12 (December)
Option Explicit
Dim gdiplusToken As Long
Private Enum TextJustify
JustifyCenter
JustifyLeft
JustifyRight
End Enum
Dim stat As Long
Private Sub Form_Load()
Form1.Caption = "GDI+"
Form1.Width = Screen.TwipsPerPixelX * 600
Form1.Height = Screen.TwipsPerPixelY * 465
Form1.BackColor = &H8000000F
Form1.ScaleMode = vbPixels
Command1.Width = Form1.ScaleWidth
Command1.Height = 25
Command1.Left = 0
Command1.Top = Form1.ScaleHeight - Command1.Height
Command1.Caption = "execute"
Command1.ZOrder (0)
Picture1.Appearance = 0
Picture1.Left = 20
Picture1.Top = 20
Picture1.Height = 366
Picture1.Width = 552
Picture1.AutoRedraw = True
' Initialize Windows GDI+
Dim GdiplusStartupInput As GdiplusStartupInput
GdiplusStartupInput.GdiplusVersion = 1
GdiplusStartupInput.DebugEventCallback = 0
GdiplusStartupInput.SuppressBackgroundThread = False
GdiplusStartupInput.SuppressExternalCodecs = False
Dim status As GpStatus
status = GdiplusStartup(gdiplusToken, GdiplusStartupInput, 0)
If status <> Ok Then
MsgBox "Error loading GDI+!", vbCritical
Call GdiplusShutdown(gdiplusToken)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Clean up resources used by Windows GDI+
Call GdiplusShutdown(gdiplusToken)
End Sub
Private Sub Command1_Click()
Call GdipSample
End Sub
Private Sub GdipSample()
Picture1.Cls
Dim stat As Long
' Create Graphics object
Dim graphics As Long
stat = GdipCreateFromHDC(Picture1.hdc, graphics)
Dim fontFamily As Long
stat = GdipCreateFontFamilyFromName(StrPtr("Times New Roman"), 0, fontFamily)
stat = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAlias)
Call DrawTextRotated(graphics, _
"Whirligig", _
275, 195, _
JustifyCenter, _
fontFamily, FontStyleRegular, 96, _
45)
' Cleanup
stat = GdipDeleteFontFamily(fontFamily)
stat = GdipDeleteGraphics(graphics)
Picture1.Refresh
End Sub
Private Sub DrawTextRotated(G As Long, _
text As String, _
x As Single, y As Single, _
justify As TextJustify, _
fontFamily As Long, FontStyle As FontStyle, fontSize As Single, _
rotationAngle As Single)
'-------------------------------------------------------------------------------------------
' Get some font metrics
Dim fontEmSize As Single
fontEmSize = fontSize
Dim EmHeight As Integer
stat = GdipGetEmHeight(fontFamily, FontStyle, EmHeight)
Dim CellAscent As Integer
stat = GdipGetCellAscent(fontFamily, FontStyle, CellAscent)
Dim CellDescent As Integer
stat = GdipGetCellDescent(fontFamily, FontStyle, CellDescent)
Dim fontAscentInPixels As Single
fontAscentInPixels = (fontEmSize * CellAscent / EmHeight)
Dim fontDescentInPixels As Single
fontDescentInPixels = (fontEmSize * CellDescent / EmHeight)
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Set text baseline
Dim baselineX As Single
Dim baselineY As Single
baselineX = x
baselineY = y
baselineX = Int(baselineX)
baselineY = Int(baselineY)
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Set the text layout rect
Dim txtRect As RECTF
txtRect.Right = 0 'width (0 means no boundary)
txtRect.Bottom = 0 'height (0 means no boundary)
txtRect.Left = baselineX 'x
txtRect.Top = baselineY - fontAscentInPixels 'y
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Initialize GDI+ objects
Dim redPen As Long
stat = GdipCreatePen1(&HFFFF0000, 1, UnitPixel, redPen)
Dim bluePen As Long
stat = GdipCreatePen1(&HFF0000FF, 1, UnitPixel, bluePen)
Dim blackBrush As Long
stat = GdipCreateSolidFill(&HFF000000, blackBrush)
Dim txtFont As Long
stat = GdipCreateFont(fontFamily, fontEmSize, FontStyle, UnitPixel, txtFont)
Dim txtStringFormat As Long
stat = GdipStringFormatGetGenericTypographic(txtStringFormat)
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Adjust for Alignment
Select Case justify
Case JustifyCenter
stat = GdipSetStringFormatAlign(txtStringFormat, StringAlignmentCenter)
Case JustifyLeft
stat = GdipSetStringFormatAlign(txtStringFormat, StringAlignmentNear)
Case JustifyRight
stat = GdipSetStringFormatAlign(txtStringFormat, StringAlignmentFar)
End Select
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Draw Text
stat = GdipDrawString(G, StrPtr(text), -1, txtFont, txtRect, txtStringFormat, blackBrush)
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Draw position marker for the text
' horz baseline
stat = GdipDrawLine(G, redPen, _
baselineX - (fontSize / 2), baselineY, _
baselineX + (fontSize / 2), baselineY)
' vert alignment marker
stat = GdipDrawLine(G, redPen, _
baselineX, baselineY, _
baselineX, baselineY - fontAscentInPixels + fontDescentInPixels)
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Draw rotation point
' horz line
stat = GdipDrawLine(G, bluePen, _
baselineX - 10, _
baselineY - ((baselineY - _
(baselineY - fontAscentInPixels + fontDescentInPixels)) / 2), _
baselineX + 10, _
baselineY - ((baselineY - _
(baselineY - fontAscentInPixels + fontDescentInPixels)) / 2))
' vert line
stat = GdipDrawLine(G, bluePen, _
baselineX, _
baselineY - (((baselineY - _
(baselineY - fontAscentInPixels + fontDescentInPixels)) / 2) _
- 10), _
baselineX, _
baselineY - (((baselineY - _
(baselineY - fontAscentInPixels + fontDescentInPixels)) / 2) _
+ 10))
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
' Clean-up GDI+ objects
stat = GdipDeletePen(redPen)
stat = GdipDeletePen(bluePen)
stat = GdipDeleteBrush(blackBrush)
stat = GdipDeleteFont(txtFont)
stat = GdipDeleteStringFormat(txtStringFormat)
'-------------------------------------------------------------------------------------------
End Sub
Dim famName As String
stat = GdipGetFamilyName(fontFamily, famName, 0)
Public Declare Function GdipGetFamilyName Lib "gdiplus" _
(ByVal family As Long, ByVal name As String, ByVal language As Integer) As GpStatus
Dim famName As String
stat = GdipGetFamilyName(fontFamily, famName, 0)
Public Declare Function GdipGetFamilyName Lib "gdiplus" _
(ByVal family As Long, ByVal name As String, ByVal language As Integer) As GpStatus
Timer1_timer
picturebox.left=picturebox.left+5
picturebox.autoredraw=true