Dialog box "About the program"

Share your advanced PureBasic knowledge/code with the community.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Dialog box "About the program"

Post by AZJIO »

Simplified version using MessageRequester

Code: Select all

Macro __About__
; 	"Автор: AZJIO" + #CRLF$ + "Version 1.0.0 from 04.10.2023" + #CRLF$ + #CRLF$ + "Want to visit the discussion thread" + #CRLF$ + "and hear about updates?"
	"Author: AZJIO" + #CRLF$ + "Version 1.0.0 from 10/04/2023" + #CRLF$ + #CRLF$ + "Would you like to visit the author's website" + #CRLF$ + "and learn about other programs?"
EndMacro

CompilerSelect #PB_Compiler_OS
	CompilerCase #PB_OS_Windows
		If MessageRequester("About the program",
		                    __About__ , #MB_OKCANCEL) = #IDOK
			RunProgram("https://your_website/")
		EndIf
	CompilerCase #PB_OS_Linux
		If MessageRequester("About the program",
		                    __About__, #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
			RunProgram("https://your_website/")
		EndIf
CompilerEndSelect
Own window

Code: Select all

EnableExplicit

#Font_Text_0 = 0

;- Enumeration
Enumeration
	#Win0
	#Win_About
EndEnumeration

Enumeration
	#w0_btn
	
	#tAboutVT
	#tAboutVTN
	#tAboutLT
	#tAboutLink
	#tAboutCr
	#tAboutNP
	#tAboutBG
	#tAboutLine
	#tAboutYT
	#tAboutYN
EndEnumeration

Global About$, ProgName$, Version$, Site$, Service$
Global link$ = "https://azjio.ucoz.ru/"

Declare Win_About(ProgName$, Width = 270, Height = 170, WinID = -1)


Define UserIntLang, *Lang

If OpenLibrary(0, "kernel32.dll")
	*Lang = GetFunction(0, "GetUserDefaultUILanguage")
	If *Lang
		UserIntLang = CallFunctionFast(*Lang)
	EndIf
	CloseLibrary(0)
EndIf

; En
ProgName$ = "ProgName"
About$ = "About"
Version$ = "Version:"
Site$ = "Site:"
Service$ = "yoomoney:"

; Ru
If UserIntLang = 1049
	ProgName$ = "Имя программы"
	About$ = "О программе"
	Version$ = "Версия:"
	Site$ = "Сайт:"
	Service$ = "ЮМани:"
EndIf

CompilerSelect #PB_Compiler_OS
	CompilerCase #PB_OS_Windows
		Global Font$ = "Arial"
; 		Global FontSize = 20
	CompilerCase #PB_OS_Linux
		Global Font$ = "Sans"
; 		Global FontSize = 17
CompilerEndSelect

;- GUI
OpenWindow(#Win0, 0, 0, 420, 300, "Win", #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)

ButtonGadget(#w0_btn, 20, 20, 110, 30, About$)
; TextGadget(#StatusBar, 20, 60, 330, 150 , "")

;- Loop
Repeat
	Select WaitWindowEvent()
		Case #PB_Event_Gadget
			Select EventGadget()
				Case #w0_btn
					Win_About(ProgName$, 300, 220, #Win0)
			EndSelect
		Case #PB_Event_CloseWindow
			CloseWindow(#Win0)
			End
	EndSelect
ForEver


Procedure Win_About(ProgName$, Width = 270, Height = 170, WinID = -1)
	Protected hWnd, nFont, indent, y2, wf
	If Width < 170
		Width = 170
	EndIf
	If WinID > -1
		hWnd = WindowID(WinID)
		DisableWindow(WinID, #True)
	Else
		hWnd = 0
	EndIf


	If OpenWindow(#Win_About, #PB_Ignore, #PB_Ignore, Width, Height, About$, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered, WindowID(#Win0))
		; 		HideWindow(#Window_Main, 1)
		CompilerIf #PB_Compiler_OS = #PB_OS_Linux
			gtk_window_set_icon_(WindowID(#Win_About), ImageID(0)) ; назначаем иконку в заголовке
		CompilerEndIf
		; 		SetWindowColor(#Win_About, $E1E3E7)

		TextGadget(#tAboutNP, 0, 0, Width, 73, #LF$ + ProgName$, #PB_Text_Center)
		SetGadgetColor(#tAboutNP, #PB_Gadget_FrontColor, $7e6a3a)
		SetGadgetColor(#tAboutNP, #PB_Gadget_BackColor, $EFF1F1)
		nFont = LoadFont(#Font_Text_0, Font$, 16, #PB_Font_Bold | #PB_Font_HighQuality)
		If nFont
			SetGadgetFont(#tAboutNP, nFont)
		EndIf
		indent = Width / 5

		; 		фон
		TextGadget(#tAboutBG, 0, 73, Width, Height - 73, "")
		CompilerIf #PB_Compiler_OS = #PB_OS_Windows
			TextGadget(#tAboutLine, 2, 73, Width - 1, 2, "", #SS_ETCHEDHORZ) ; line
		CompilerEndIf
		SetGadgetColor(#tAboutBG, #PB_Gadget_BackColor, $E7E3E1)
		y2 = 100
		wf = 60
		TextGadget(#tAboutVT, indent, y2, wf, 22, Version$)
		SetGadgetColor(#tAboutVT, #PB_Gadget_FrontColor, 0)
		SetGadgetColor(#tAboutVT, #PB_Gadget_BackColor, $E7E3E1)
		TextGadget(#tAboutVTN, indent + wf, y2, Width - indent - wf, 22, "1.5   (2023.10.04)")
		SetGadgetColor(#tAboutVTN, #PB_Gadget_FrontColor, 0)
		SetGadgetColor(#tAboutVTN, #PB_Gadget_BackColor, $E7E3E1)
		y2 + 25
		wf = 40
		TextGadget(#tAboutLT, indent, y2, wf, 22, Site$)
		SetGadgetColor(#tAboutLT, #PB_Gadget_FrontColor, 0)
		SetGadgetColor(#tAboutLT, #PB_Gadget_BackColor, $E7E3E1)
		HyperLinkGadget(#tAboutLink, indent + wf, y2, Width - indent - wf, 22, link$, $FF0099)
		SetGadgetColor(#tAboutLink, #PB_Gadget_BackColor, $E7E3E1)
		SetGadgetColor(#tAboutLink, #PB_Gadget_FrontColor, $DD0000)
		y2 + 25
; 		wf = 70 ; Ru
		wf = 80 ; En
		TextGadget(#tAboutYT, indent, y2, wf, 22, Service$)
		SetGadgetColor(#tAboutYT, #PB_Gadget_FrontColor, 0)
		SetGadgetColor(#tAboutYT, #PB_Gadget_BackColor, $E7E3E1)
		HyperLinkGadget(#tAboutYN, indent + wf, y2, Width - indent - wf, 22, "4100117604217624", $FF0099)
		SetGadgetColor(#tAboutYN, #PB_Gadget_BackColor, $E7E3E1)
		SetGadgetColor(#tAboutYN, #PB_Gadget_FrontColor, $DD0000)
		GadgetToolTip(#tAboutYN, "Copy")
		y2 + 25
		TextGadget(#tAboutCr, indent, y2, Width - indent, 22, "Copyright AZJIO © 2023")
		SetGadgetColor(#tAboutCr, #PB_Gadget_FrontColor, 0)
		SetGadgetColor(#tAboutCr, #PB_Gadget_BackColor, $E7E3E1)

		Repeat
			Select WaitWindowEvent()
				Case #PB_Event_Gadget
					Select EventGadget()
						Case #tAboutLink
							RunProgram(link$)
						Case #tAboutYN
							SetClipboardText(GetGadgetText(#tAboutYN))
					EndSelect
				Case #PB_Event_CloseWindow
					Break
			EndSelect
		ForEver

		If hWnd
			DisableWindow(WinID, #False)
		EndIf
		CloseWindow(#Win_About)
		ProcedureReturn 0
	EndIf
EndProcedure
Criticize...
Maybe you have your own style with a large text of gratitude to all project participants. But I did it for small programs. The disadvantage of a custom window is that the window style in Linux can have a black style and this will not be taken into account.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Dialog box "About the program"

Post by BarryG »

Your second example is the better one and looks nice.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Dialog box "About the program"

Post by RSBasic »

I like the second variant too. The design reminds me of my About me window back then :D :
Image
Image
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Dialog box "About the program"

Post by Kwai chang caine »

Very nice, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply