Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource Icon, logo, "files/calendar.ico"
$Days = "Sun Mon Tue Wed Thu Fri Sat"
%IDC_LabelLeft = 500
%IDC_LabelRight = 501
Global hDlg,hFont As Dword
Global CY,CM As Long 'CY = calendar year CM = calendar month (1st of n)
Global Opacity As Long
Global CS As Long 'CS is calendar start day of week
Global DM As Long 'DM is days in month
Global DT As IPowerTime
Function PBMain() As Long
Dialog New Pixels, 0, "Layered Window",300,10,225,200, %WS_Popup, %WS_Ex_Layered To hDlg
Dialog Set Icon hDlg, "logo"
Dialog Set Color hDlg, %Black, %White
Control Add Label, hDlg, %IDC_LabelLeft, "", 10,10,15,15, %SS_Notify
Control Set Color hDlg, %IDC_LabelLeft, %Red, %Red
Control Add Label, hDlg, %IDC_LabelRight, "", 195,10,15,15, %SS_Notify
Control Set Color hDlg, %IDC_LabelRight, %Red, %Red
Dialog Show Modal hDlg Call DlgProc
End Function
Sub Settings_INI(Task$)
Local x,y As Long, xResult, yResult, INIFileName, tempz As WStringZ * %Max_Path
INIFileName = Exe.Path$ + "gbcalendar.ini"
'set ini filename
If Task$ = "get" Then
'get dialog top/left from INI file and use to set Dialog location
Getprivateprofilestring "All", "Left", "400", xResult, %Max_Path, INIFileName
Getprivateprofilestring "All", "Top", "400", yResult, %Max_Path, INIFileName
Dialog Set Loc hDlg, Val(xResult), Val(yResult) 'left/top
'get dialog width/height from INI file and use to set Dialog size
GetPrivateProfileString "All", "Width", "225", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "200", yResult, %Max_Path, INIFileName
Dialog Set Client hDlg,Val(xResult), Val(yResult) 'width/height
CY = Val(Right$(Date$,4)) : CM = Val(Mid$(Date$,4,2))
'get value for string variables
' Getprivateprofilestring "All", "HistoryFile", Exe.Path$ + "history.txt", tempz, %Max_Path, INIFileName : HistoryFile = tempz
'get value for numeric variables
Getprivateprofilestring "All", "CY", Right$(Date$,4), tempz, %Max_Path, INIFileName: CY = Val(tempz)
Getprivateprofilestring "All", "CM", Left$(Date$,2), tempz, %Max_Path, INIFileName: CM = Val(tempz)
Getprivateprofilestring "All", "Opacity", "128", tempz, %Max_Path, INIFileName: Opacity = Val(tempz)
End If
If Task$ = "save" Then
If Len(Dir$(INIFileName)) Then Kill INIFileName
'save dialog size/location unless minimized or maximized
If IsFalse(IsIconic(hDlg) Or IsZoomed(hDlg)) Then
Dialog Get Loc hDlg To x,y
WritePrivateProfileString "All", "Left", Str$(x), INIFileName
WritePrivateProfileString "All", "Top", Str$(y), INIFileName
Dialog Get Client hDlg To x,y
WritePrivateProfileString "All", "Width", Str$(x), INIFileName
WritePrivateProfileString "All", "Height", Str$(y), INIFileName
End If
'save string variables
' WritePrivateProfileString "All", "HistoryFile",HistoryFile, INIFileName
'save numeric variables
WritePrivateProfileString "All", "CY", (Str$(CY)), INIFileName
WritePrivateProfileString "All", "CM", (Str$(CM)), INIFileName
WritePrivateProfileString "All", "Opacity", (Str$(Opacity)), INIFileName
End If
End Sub
CallBack Function DlgProc() As Long
Local PS As PaintStruct, hDC As Dword, temp$, i,j,x,y As Long
Select Case Cb.Msg
Case %WM_InitDialog
Settings_INI "get"
Let DT = Class "PowerTime"
DT.NewDate CY, CM, 1
CS = DT.DayOfWeek '0-6 corresponding to Sun-Sat
DM = DT.DaysInMonth
SetLayeredWindowAttributes(hDlg, %White, Opacity, %LWA_ALPHA Or %LWA_Colorkey)
Case %WM_ContextMenu
Dialog End hDlg
Case %WM_LButtonDown
If Cb.WParam = %MK_LBUTTON Then SendMessage hDlg, %WM_NCLButtonDown, %HTCaption, ByVal %Null ' force drag
Case %WM_Destroy
Settings_INI "save"
Case %WM_Paint
hDC = BeginPaint(hDlg, PS)
temp$ = MonthName$(CM) + " " + Str$(CY)
Textout hDC, 75,10, (temp$), Len(temp$)
Textout hDC, 10,30, ($Days), Len($Days)
For i = 1 To DM
temp$ = LTrim$(Str$(i))
x = ((i+CS-1) Mod 7) * 30 + 10
y = ((i+CS-1) \ 7) * 20 + 50
Textout hDC, x,y, (temp$), Len(temp$)
Next i
EndPaint hDlg, PS
End Select
End Function
'gbs_01293
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm