Simple standard About-Dialog (easy extendable)

Share your advanced PureBasic knowledge/code with the community.
User avatar
shadow
User
User
Posts: 34
Joined: Thu Dec 16, 2010 1:25 pm
Location: Germany

Simple standard About-Dialog (easy extendable)

Post by shadow »

Hello,

this is just a simple about dialog i made for my tools.
Features:
- public domain :mrgreen:
- easy to call
- easy extensible
- modal and cross platform (win, linux, don't have mac) :!:
Feel free to use it in your apps :wink:

Code: Select all

;*************************************************************************
; dlgabout.pbi
; Simple dialog to display the information of an application.
;
; Author: Alexander Resner
;
; License:
;-------------------------------------------------------------------------
; 2011 June 23
;
; The author disclaims copyright To this source code. In place of
; a legal notice, here is a blessing:
;
;    May you do good And Not evil.
;    May you find forgiveness For yourself And forgive others.
;    May you share freely, never taking more than you give.
;
;*************************************************************************

Procedure OpenWindow_About(idParent.l, title$, version$, copyright$, email$)
	If (idParent >= 0) And (Not IsWindow(idParent))
		idParent = -1
	EndIf
	
	Protected dlgAbout.l
	Protected text_version.l, text_copyright.l, hl_email.l, menu_quit.l = $0AFF
	Protected fontVerdana.l, fontVerdanaBold.l, hVerdana.l, hVerdanaBold.l
	Protected eventid.l
	Protected dlgAboutQuit.b = #False
	
	If idParent >= 0
		dlgAbout = OpenWindow(#PB_Any, 0, 0, 350, 100, title$, #PB_Window_WindowCentered | #PB_Window_Tool | #PB_Window_SystemMenu, WindowID(idParent))
	Else
		dlgAbout = OpenWindow(#PB_Any, 0, 0, 350, 100, title$, #PB_Window_ScreenCentered | #PB_Window_Tool | #PB_Window_SystemMenu)	
	EndIf
  If dlgAbout = 0
  	MessageRequester("Error", "Can't open window!", #PB_MessageRequester_Ok)
    ProcedureReturn
  EndIf
  
  ; fonts
  fontVerdana = LoadFont(#PB_Any, "Verdana", 10)
  hVerdana = FontID(fontVerdana)
  fontVerdanaBold = LoadFont(#PB_Any, "Verdana", 10, #PB_Font_Bold)
  hVerdanaBold = FontID(fontVerdanaBold)
  ; gadgets
  text_version = TextGadget(#PB_Any, 10, 10, 330, 20, version$, #PB_Text_Border | #PB_Text_Center)
  SetGadgetFont(text_version, hVerdanaBold)
  text_copyright = TextGadget(#PB_Any, 10, 50, WindowWidth(dlgAbout) - 20, 20, copyright$, #PB_Text_Center)
  SetGadgetFont(text_copyright, hVerdana)
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  	hl_email = HyperLinkGadget(#PB_Any, 10, 70, WindowWidth(dlgAbout) - 20, 20, email$, RGB(0, 0, 255), #PB_Text_Center)
  CompilerElse
  	; Under Linux there's sadly no simple solution available to call the standard email program.
  	hl_email = TextGadget(#PB_Any, 10, 70, WindowWidth(dlgAbout) - 20, 20, email$, #PB_Text_Center)
  CompilerEndIf
  ResizeGadget(hl_email, (WindowWidth(dlgAbout) - GadgetWidth(hl_email))/2, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  SetGadgetFont(hl_email, hVerdana)
  ; keyboard shortcuts / menus
  AddKeyboardShortcut(dlgAbout, #PB_Shortcut_Escape, menu_quit)
  
  ; disable main window
  If idParent >= 0 And IsWindow(idParent)
  	DisableWindow(idParent, #True)
  	SetActiveWindow(dlgAbout)
  EndIf
  
  Repeat
  	eventid = WaitWindowEvent()
  	Select EventWindow()
  		Case dlgAbout
  			Select eventid
  				Case #PB_Event_CloseWindow
  					dlgAboutQuit = #True
  				Case #PB_Event_Menu
  					Select EventMenu()
  						Case menu_quit
  							dlgAboutQuit = #True
  					EndSelect
  				Case #PB_Event_Gadget
  					Select EventGadget()
  						Case hl_email
  							; Under Linux there's sadly no simple solution available to call the standard email program.
  							CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  								ShellExecute_(#Null, "open", "mailto:" + email$, #Null, #Null, #SW_SHOW)
  							CompilerEndIf
			      EndSelect
  			EndSelect
  	EndSelect
  Until dlgAboutQuit = #True
  
  If idParent >= 0 And IsWindow(idParent)
  	DisableWindow(idParent, #False)
  	SetActiveWindow(idParent)
  EndIf
  
  CloseWindow(dlgAbout)
  FreeFont(fontVerdana)
  FreeFont(fontVerdanaBold)
EndProcedure

;OpenWindow_About(-1, "Testtitel", "Testapp 0.00.00", "Copyright test", "test@test.de")
Edit:
- chnages for linux
- enable window before closing child
Last edited by shadow on Thu Jun 23, 2011 10:55 pm, edited 1 time in total.
ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Simple standard About-Dialog (easy extendable)

Post by ts-soft »

thx

it is better to enable the events for mainwindow before close aboutbox:

Code: Select all

  If idParent >= 0 And IsWindow(idParent)
    DisableWindow(idParent, #False)
    SetActiveWindow(idParent)
  EndIf
  
  CloseWindow(dlgAbout)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
shadow
User
User
Posts: 34
Joined: Thu Dec 16, 2010 1:25 pm
Location: Germany

Re: Simple standard About-Dialog (easy extendable)

Post by shadow »

:shock:
thank you for your advice :wink:
ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Simple standard About-Dialog (easy extendable)

Post by Tomi »

nice and useful :D
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Simple standard About-Dialog (easy extendable)

Post by rsts »

Great license :D

Thanks for sharing
Post Reply