ScintillaSendMessage
Code: Select all
#Window = 0
#Sci = 0
#num_indicator = 0
Define *Text, nLine, start, length
If Not InitScintilla()
End
EndIf
If OpenWindow(#Window, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScintillaGadget(#Sci, 5, 5, 320, 80, 0)
*Text = UTF8("This is a simple ScintillaGadget with text..." + #LF$ + "More text" + #LF$ + "Even more text!")
ScintillaSendMessage(#Sci, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text)
ScintillaSendMessage(#Sci, #SCI_INDICSETSTYLE, #num_indicator, #INDIC_STRAIGHTBOX) ; first indicator with style 8 (0-19)
ScintillaSendMessage(#Sci, #SCI_INDICSETFORE, #num_indicator, #Red) ; first indicator with red color
ScintillaSendMessage(#Sci, #SCI_SETINDICATORCURRENT, #num_indicator, #INDIC_STRAIGHTBOX) ; makes the indicator current
ScintillaSendMessage(#Sci, #SCI_INDICSETUNDER, #num_indicator, 1) ; indicator under the text, i.e. doesn't obscure it
ScintillaSendMessage(#Sci, #SCI_INDICSETALPHA, #num_indicator, 127) ; Transparency
; ScintillaSendMessage(#Sci, #SCI_INDICGETOUTLINEALPHA, #num_indicator, 255) ; Border transparency
nLine = 1 ; line number starts from 0
start = ScintillaSendMessage(#Sci, #SCI_POSITIONFROMLINE, nLine)
length = ScintillaSendMessage(#Sci, #SCI_GETLINEENDPOSITION, nLine) - start
ScintillaSendMessage(#Sci, #SCI_INDICATORFILLRANGE, start, length) ; start and length
; ScintillaSendMessage(#Sci, #SCI_INDICATORFILLRANGE, 46, 9) ; start and length
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Chr
Here is an example of practical symbols that can be used as an icon on a button, as well as a loop showing the output of Latin letters.
Code: Select all
Debug Chr($2630) ; ☰
Debug Chr($25BC) ; ▼
For i = 65 To 90
Debug Chr(i)
Next
FindString
The one-line example follows the syntax in the title, so you can show a loop using position.
Code: Select all
Define String$ = "This is a simple line...."
Define Position, Last
Repeat
Last = Position
Position = FindString(String$ , "i", Position + 1)
Debug Position
Until Not Position
Debug Last
There are many examples in the French help file that are not in the English help. For example, look at the "FileSystem" section, in English there is almost no example there, but in French there are examples on every page.
WritePreferenceInteger
The peculiarity of the example is the absence of groups. That is, if the program has a small number of parameters, then you don’t have to create a group name.
Code: Select all
CreatePreferences(GetTemporaryDirectory()+"test.ini")
WritePreferenceInteger("x", 35)
WritePreferenceInteger("y", 46)
WritePreferenceInteger("w", 200)
WritePreferenceInteger("h", 100)
ClosePreferences()
OpenPreferences(GetTemporaryDirectory()+"test.ini")
Debug ReadPreferenceInteger("x", 0)
Debug ReadPreferenceInteger("y", 0)
Debug ReadPreferenceInteger("w", 400)
Debug ReadPreferenceInteger("h", 600)
ClosePreferences()
WritePreferenceString
Another way to use "Preferences" in a non-standard way
Code: Select all
; Use keys as data. In this case, the data must be unique and not duplicated.
CreatePreferences(GetTemporaryDirectory()+"ColorList.ini", #PB_Preference_NoSpace)
WritePreferenceString("FF0000", "")
WritePreferenceString("00FF00", "")
WritePreferenceString("0000FF", "")
WritePreferenceString("FF00FF", "")
ClosePreferences()
OpenPreferences(GetTemporaryDirectory()+"ColorList.ini")
ExaminePreferenceKeys()
While NextPreferenceKey()
Debug PreferenceKeyName()
Wend
ClosePreferences()
ExaminePreferenceGroups
Isn't it better to use "Debug"?
Code: Select all
MessageRequester("Groups", PreferenceGroupName())
ExaminePreferenceKeys
Isn't it better to use "Debug"? The loop and MessageRequester force me to click "OK" several times (4).
Code: Select all
MessageRequester("Key group 'Window'", PreferenceKeyName() + " = " + PreferenceKeyValue())
UncompressPackFile
Example with real files
Code: Select all
UseZipPacker()
Define Path$ = "C:\ProgramData\PureBasic\Examples\Sources\Data\"
If CreatePack(0, "C:\ProgramData\PureBasic\Examples\MyCompressedFiles.zip")
AddPackFile(0, Path$ + "world.png", "world.png")
AddPackFile(0, Path$ + "test.pref", "test.pref")
AddPackFile(0, Path$ + "CdPlayer.ico", "CdPlayer.ico")
AddPackFile(0, Path$ + "Background.bmp", "Background.bmp")
ClosePack(0)
EndIf
Path$ = "C:\ProgramData\PureBasic\Examples\test_delete\"
If OpenPack(0, "C:\ProgramData\PureBasic\Examples\MyCompressedFiles.zip")
Debug "opened"
If CreateDirectory(Path$) Or FileSize(Path$) = -2
Debug "created a folder"
If ExaminePack(0)
While NextPackEntry(0)
Debug "Name: " + PackEntryName(0) + ", Size: " + PackEntrySize(0)
If UncompressPackFile(0, Path$ + PackEntryName(0), PackEntryName(0)) = -1
Debug "unsuccessful unpacking of file: " + PackEntryName(0)
EndIf
Wend
EndIf
ClosePack(0)
RunProgram(Path$)
EndIf
EndIf
AddPackFile
Using a tree file structure
Code: Select all
UseZipPacker()
Define Path$ = "C:\ProgramData\PureBasic\Examples\Sources\"
If CreatePack(0, "C:\ProgramData\PureBasic\Examples\MyCompressedFiles.zip")
AddPackFile(0, Path$ + "Data\world.png", "Data\world.png")
AddPackFile(0, Path$ + "Data\test.pref", "Data\test.pref")
AddPackFile(0, Path$ + "Data\CdPlayer.ico", "Data\CdPlayer.ico")
AddPackFile(0, Path$ + "2DDrawing.pb", "2DDrawing.pb")
ClosePack(0)
EndIf
Path$ = "C:\ProgramData\PureBasic\Examples\test_delete\"
If OpenPack(0, "C:\ProgramData\PureBasic\Examples\MyCompressedFiles.zip")
Debug "opened"
If (CreateDirectory(Path$) And CreateDirectory(Path$ + "Data\")) Or FileSize(Path$ + "Data\") = -2
Debug "created a folder"
If ExaminePack(0)
While NextPackEntry(0)
Debug "Name: " + PackEntryName(0) + ", Size: " + PackEntrySize(0)
If UncompressPackFile(0, Path$ + PackEntryName(0), PackEntryName(0)) = -1
Debug "unsuccessful unpacking of file: " + PackEntryName(0)
EndIf
Wend
EndIf
ClosePack(0)
RunProgram(Path$)
EndIf
EndIf
ChangeSysTrayIcon
The example shows how to create a tray menu, as well as a memory occupancy sensor. You can shorten the example by removing the memory sensor and use it on the AddSysTrayIcon page.
Code: Select all
EnableExplicit
#TrayIcon = 0
#Window = 0
#Menu = 0
#Timer = 0
Global tt = MemoryStatus(#PB_System_TotalPhysical)/16
Global mem
If OpenWindow(#Window, 0, 0, 300, 100, "", #PB_Window_Invisible)
If CreateImage(0, 16, 16) And StartDrawing(ImageOutput(0))
Box(0, 0, 16 , 16, $00FFFF)
StopDrawing()
EndIf
If CreatePopupImageMenu(#Menu)
MenuItem(0, "Exit")
EndIf
AddSysTrayIcon(#TrayIcon, WindowID(#Window), ImageID(0))
AddWindowTimer(#Window, #Timer, 1000)
;- loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If StartDrawing(ImageOutput(0))
Box(0, 0, 16 , 16, $00FFFF)
mem = MemoryStatus(#PB_System_FreePhysical) / tt
Box(1, mem, 14, 16 - mem, $0000FF)
StopDrawing()
ChangeSysTrayIcon(#TrayIcon, ImageID(0))
EndIf
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_RightClick, #PB_EventType_LeftClick
DisplayPopupMenu(#Menu, WindowID(#Window)) ; show popup menu
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0 ; Exit
RemoveSysTrayIcon(#TrayIcon)
FreeMenu(#Menu)
CloseWindow(#Window)
End
EndSelect
EndSelect
ForEver
EndIf
AddSysTrayIcon
Code: Select all
EnableExplicit
#TrayIcon = 0
#Window = 0
#Menu = 0
If OpenWindow(#Window, 0, 0, 300, 100, "", #PB_Window_Invisible)
If CreatePopupImageMenu(#Menu)
MenuItem(0, "Exit")
EndIf
AddSysTrayIcon(#TrayIcon, WindowID(#Window), LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico"))
Repeat
Select WaitWindowEvent()
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_RightClick, #PB_EventType_LeftClick
DisplayPopupMenu(#Menu, WindowID(#Window)) ; show popup menu
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0 ; Exit
RemoveSysTrayIcon(#TrayIcon)
FreeMenu(#Menu)
CloseWindow(#Window)
End
EndSelect
EndSelect
ForEver
EndIf