Date: 02-16-2022
Return to Index
created by gbSnippets
'Most apps have a Help / About menu selection which pops up
'a modal dialog with information about the application.
'Key features include:
'Multiple font sizes to emphasize some information over others
'The fonts are created and destroyed solely for the purpose of the About dialog
'Active URL (changes color when cursor moves over URL, click to open the URL)
'ImageX control to display a logo or some other graphic of interest.
'Primary Code:
Sub DisplayAboutDialog()
'this defines the about Dialog. Note the icon selection, multiple fonts, and ImageX
'control used to display an image
Local hAboutFont1 As Dword, hAboutFont2 As Dword
Dialog New Pixels, hDlg, "About gbSnippets", 100, 100, 280, 175, %WS_SysMenu Or %WS_Caption Or %WS_ClipChildren To hAbout
Dialog Set Icon hAbout, "aainfo"
Font New "MS Sans Serif", 14, 1 To hAboutFont1
Font New "MS Sans Serif", 9, 1 To hAboutFont2
Control Add Label, hAbout, 1000, "gbSnippets 8.1", 40, 10, 200, 40, %SS_Center
Control Add Label, hAbout, 1010, "Copyright 2009, Gary L. Beene", 40, 40, 200, 20, %SS_Center
Control Add Label, hAbout, 1020, "Gary Beene's Information Center", 40, 55, 200, 20, %SS_Center
Control Add Label, hAbout, 1030, "http://www.garybeene.com", 40, 70, 200, 20, %SS_Center Or %SS_Notify
Control Set Font hAbout, 1000, hAboutFont1
Control Set Font hAbout, 1010, hAboutFont2
Control Set Font hAbout, 1020, hAboutFont2
Control Set Font hAbout, 1030, hAboutFont2
Control Add ImageX, hAbout, 1040,"about", 10,100,259,66, %SS_Notify
Dialog Show Modal hAbout Call AboutProc()
Font End hAboutFont1
Font End hAboutFont2
End Sub
CallBack Function AboutProc() As Long
'this is the Callback function for the About dialog. It changes the URL color
'when the mouse is over that label. It also captures the mouse click and opens
'a URL in the default browser (using the ShellExecute API).
Local URL As Asciiz * %Max_Path, iReturn As Long
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = 1030 AND CB.Ctlmsg = %STN_Clicked Then
URL$ = "http://www.garybeene.com/"
iReturn = ShellExecute(hDlg, "Open", URL, $Nul, $Nul, %SW_ShowNormal)
End If
Case %WM_SetCursor
Select Case GetDlgCtrlID (CB.wParam)
Case 1030
Control Set Color hAbout, 1030, %Red, -1
Dialog Redraw hAbout
Case Else
Control Set Color hAbout, 1030, %Black, -1
Dialog Redraw hAbout
End Select
End Select
End Function
'Compilable Example: (Jose Includes)
'First, here's the PBMain part of the example. It has a Help menu which has
'a submenu that calls the About dialog. I use regularly use global values to
'hold handles - but not all programmers like this practice.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
%ID_MenuHelpAbout = 100
Global hDlg As Dword, hMenu As Dword, hMenuHelp As Dword
Global hMenuHelpAbout As Dword, hAbout As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
AddMenu
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
'this is the Callback function for the main dialog. It captures clicking the
'Menu\About menu item.
If CB.Msg = %WM_Command AND CB.Ctl = %ID_MenuHelpAbout Then DisplayAboutDialog
End Function
Sub AddMenu()
'sub to add the Help menu with an About submenu
Menu New Bar To hMenu
Menu New Popup To hMenuHelp
Menu Add Popup, hMenu, "&Help", hMenuHelp, %MF_Enabled
Menu Add String, hMenuHelp, "&About", %ID_MenuHelpAbout, %MF_Enabled
Menu Attach hMenu, hDlg
End Sub
Sub DisplayAboutDialog()
'this defines the about Dialog. Note the icon selection, multiple fonts, and ImageX
'control used to display an image
Local hAboutFont1 As Dword, hAboutFont2 As Dword
Dialog New Pixels, hDlg, "About gbSnippets", 100, 100, 280, 175, %WS_SysMenu Or %WS_Caption Or %WS_ClipChildren To hAbout
Dialog Set Icon hAbout, "aainfo"
Font New "MS Sans Serif", 14, 1 To hAboutFont1
Font New "MS Sans Serif", 9, 1 To hAboutFont2
Control Add Label, hAbout, 1000, "gbSnippets 8.1", 40, 10, 200, 40, %SS_Center
Control Add Label, hAbout, 1010, "Copyright 2009, Gary L. Beene", 40, 40, 200, 20, %SS_Center
Control Add Label, hAbout, 1020, "Gary Beene's Information Center", 40, 55, 200, 20, %SS_Center
Control Add Label, hAbout, 1030, "http://www.garybeene.com", 40, 70, 200, 20, %SS_Center Or %SS_Notify
Control Set Font hAbout, 1000, hAboutFont1
Control Set Font hAbout, 1010, hAboutFont2
Control Set Font hAbout, 1020, hAboutFont2
Control Set Font hAbout, 1030, hAboutFont2
Control Add ImageX, hAbout, 1040,"about", 10,100,259,66, %SS_Notify
Dialog Show Modal hAbout Call AboutProc()
Font End hAboutFont1
Font End hAboutFont2
End Sub
CallBack Function AboutProc() As Long
'this is the Callback function for the About dialog. It changes the URL color
'when the mouse is over that label. It also captures the mouse click and opens
'a URL in the default browser (using the ShellExecute API).
Local URL As Asciiz * %Max_Path, iReturn As Long
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = 1030 AND CB.Ctlmsg = %STN_Clicked Then
URL$ = "http://www.garybeene.com/"
iReturn = ShellExecute(hDlg, "Open", URL, $Nul, $Nul, %SW_ShowNormal)
End If
Case %WM_SetCursor
Select Case GetDlgCtrlID (CB.wParam)
Case 1030
Control Set Color hAbout, 1030, %Red, -1
Dialog Redraw hAbout
Case Else
Control Set Color hAbout, 1030, %Black, -1
Dialog Redraw hAbout
End Select
End Select
End Function
'gbs_00035
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm