Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
IDC_ListBox
IDM_Debug
End Enum
Global hDlg As Dword, Debug As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Trace",400,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Push", 10,10, 100, 20
Control Add ListBox, hDlg, %IDC_ListBox, , 10,40, 100, 120
ListBox Add hDlg, %IDC_ListBox, "One" : ListBox Add hDlg, %IDC_ListBox, "Two"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Settings_INI "get" '<--- read Debug variable from INI
BuildAcceleratorTable '<--- allows use of Ctrl-D to toggle Debug/Trace mode
ManageDebug '<--- turn Debug/Trace mode on/off
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
If Debug Then Txt.Print "button pressed" '<--- just for show in this example
Case %IDC_ListBox
If Cb.CtlMsg = %LBN_SelChange Then
If Debug Then Txt.Print "New selection" '<--- just for show in this example
End If
Case %IDM_Debug '<--- called by Ctrl-D
Debug = Debug Xor 1 '<--- toggle Debug/Trace mode
ManageDebug '<---
End Select
Case %WM_Destroy
Settings_ini "save" '<--- save Debug variable value, to be used on startup
End Select
End Function
Sub ManageDebug
If Debug Then Txt.Print FuncName$
Local hDebug As Long
If Debug Then
Txt.Window "Debug", 100,100,40,40 To hDebug '<--- choose your own startup location
Txt.Print "TXT Window Opened"
Else
Txt.End
End If
End Sub
Sub BuildAcceleratorTable
If Debug Then Txt.Print FuncName$
Local c As Long, ac() As ACCELAPI, hAccelerator As Dword ' for keyboard accelator table values
Dim ac(1)
ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key = %VK_D : ac(c).cmd = %IDM_Debug : Incr c
Accel Attach hDlg, AC() To hAccelerator
End Sub
Sub Settings_INI(Task$)
Local x As Long, y As Long
Local xResult, yResult, temp, INIFileName As WStringZ*%Max_Path
INIFileName = Exe.Path$ + Exe.Name$ + ".ini"
If Task$ = "get" Then
'get dialog top/left from INI file and use to set Dialog location
Getprivateprofilestring "All", "Left", "600", xResult, %Max_Path, INIFileName
Getprivateprofilestring "All", "Top", "300", 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", "200", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "200", yResult, %Max_Path, INIFileName
Dialog Set Size hDlg,Val(xResult), Val(yResult) 'width/height
'get value for numeric variables
Getprivateprofilestring "All", "Debug", "0", temp, %Max_Path, INIFileName: Debug = Val(temp)
End If
If Task$ = "save" Then
'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 Size hDlg To x,y
WritePrivateProfileString "All", "Width", Str$(x), INIFileName
WritePrivateProfileString "All", "Height", Str$(y), INIFileName
End If
'save numeric variables
WritePrivateProfileString "All", "Debug", (Str$(Debug)), INIFileName
End If
End Sub
'gbs_01254
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm