Hello everyone
If you have been following along, you know our Desktop Clock Calendar has a pop up styled menu and we have looked at how to create one in an earlier lesson. What we did not discuss in the earlier lessons and is not explained in Alpha Software help is how to build the menu using code. This short video below gives a demonstration of how the menu will work and an overview of the code to create it.
As you can see from the video our options are endless. I give a quick overview of how we created our menu from an external table and we will now look at it in detail.
table.external_record_content_GET()
In order for this function to work, there must be a table to point to. The table we created is ApplicationList.dbf. How we populate this table will become part of the Setup Wizard in our design document and will be the focus of our next session. For now, we are working with the data that currently exist in the table which is comprised of links pointing to frequently used applications, documents and spreadsheets, web bookmarks and Windows Start Menu.
Our function needs to not only return the values of our table, but the output must also conform with the data input style for our pop up menu and finally it must allow us to use variable icon’s for each level of the menu design. A tall order, so lets begin.
subjectlist = ""
subjectlist = table.external_record_content_GET("applicationlist", "'{I=$$generic.favorite}TakeCharge Desktop |"\
" {I=$$folder}'+Alltrim(Menu_Name)+' |{I=$$folder.open}'+Alltrim(BtnGroup)+' |"\
"{I='+alltrim(Iname)+'}'+alltrim(File_Name)","Menu_Name + BtnGroup","alltrim(File_Name) <> 'Blank'")
First we set a variable for our control line feed list then we write the function. Since the function is long, I wrapped the code. Please note each segment ends with a quote and a backslash except the last line and each begins with a quote except the first line. The first part of our function calls the “C table name” followed by a comma. The next segment puts in the first layer icon and displayed name on the menu, followed by a pipe character ‘|’ then the icon for level two. This stirng is wrapped in hyphens because this text is added to the function and is not normally included. Next we include the menu_name field from our table and it is wrapped in plus signs ‘+’ The plus signs are actually linking the text to the fields and would not normally be included. We follow this process for the rest of our output section of our function.The next section is our Output Order which must order the output by layer or the menu will not display correctly. Finally we assign a filter to insure any blank values will not display. This filter is a carry over from an older quick launch application I wrote years ago and may not actually be necessary. If not needed I will remove it later.
Once the function runs, we must make it part of our menu system.
dim FileAddr as C
dim SHARED mymenu as C
style = <<%str%
menu.v_item_min_leftx=.25
color.menu_v_background=Dirty White
color.menu_v_left=Light Blue
color.menu_v_right=Blue White
font.menu=Tahoma,8,0
%str%
'vMenuItems = <<%a%
vMenuItems = subjectlist
vMenuItems = vMenuItems+ crlf() + <<%a%
{I=$$generic.favorite}TakeCharge Desktop | {I=$$generic.favorite}TC Start Menu
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.people}TC Contact Manager | {I=$$table.add}Company Setup Form
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.people}TC Contact Manager | {I=$$generic.people}Contacts by Company
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.people}TC Contact Manager | {I=$$generic.people}Contacts History
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.people}TC Contact Manager | {I=$$format.text.edit}Quick Note Organizer
{I=$$generic.favorite}TakeCharge Software | {I=$$format.text.edit}TC Message Center
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Games | {I=$$generic.favorite}TC Graphics Examples
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Games | {I=$$generic.favorite}TC Interactive Bar Graph
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Games | {I=$$generic.favorite}TC Pong
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Games | {I=$$generic.favorite}TC Sudoku Game
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Games | {I=$$generic.favorite}TC Powerball Nbr Generator
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.book.closed}TC King James Bible Reader | {I=$$code.library}TC King James Bible Reader
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.book.closed}TC King James Bible Reader | {I=$$generic.bookMark}My Book Marks
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.book.closed}TC King James Bible Reader | {I=$$code}Daily Verse
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Multi EMail Acct Mgr
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC To Do Tracking
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Note Organizer
{I=$$generic.favorite}TakeCharge Software | {I=$$generic.favorite}TC Suite
_____________________
{I=$$application.ms}Desktop Apps | {I=$$email}Email
{I=$$application.ms}Desktop Apps | {I=$$control.calculator}Calculator
{I=$$application.ms}Desktop Apps | {I=$$generic.tools}File Manager
{I=$$application.ms}Desktop Apps | {I=$$application.ms.ie}Internet
{I=$$application.ms}Desktop Apps | {I=$$generic.movie}Media Player
{I=$$application.ms}Desktop Apps | {I=$$generic.notepad}Notepad
{I=$$application.ms}Desktop Apps | {I=$$generic.palette}MS Paint
{I=$$application.ms}Desktop Apps | {I=$$application.ms.word}Word Pad
_____________________
{DATA=System Setup}{I=$$generic.tools}System Setup
{DATA=TC Control Panel}{I=$$control.image}TC Control Panel
{DATA=Exit}{I=$$generic.exit}Exit
%a%
mymenu = ui_popup_styled_menu(vMenuItems, style)
if mymenu = "" then
end
end if
We set our variables needed for the menu and then the style.
%str% 'vMenuItems = <<%a% vMenuItems = subjectlist vMenuItems = vMenuItems+ crlf() + <<%a%
The commented out line would be what you would use if you are building the list manually and we are not. Our procedure adds the subjectlist to our menu variable with a conrtol line feed at the end then adds the menu items we wish to hard code. Once the menu is created we need to have code to actually run the user choice. Now this can be a little complicated because we are opening internal forms, performing operations, opening other application modules, launching external applications, opening the web browser and accessing a specific bookmark, opening files by their associated application and finally launching applications using Windows Lnk files. Here is the rest of the code.
if mymenu = "{I=$$generic.favorite}TC Start Menu" then
ui_freeze(.t.)
form.load("TakeCharge","popup","","left","bottom")
TakeCharge.Activate()
TakeCharge.Show()
form.close()
ui_freeze(.f.)
Calendar:button43.activate()
else if mymenu = "{I=$$generic.favorite}TC Note Organizer" then
form.load("HTMLWriter","popup","","center","top")
HTMLWriter.Activate()
HTMLWriter.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$format.text.edit}TC Message Center" then
form.load("Sign In","popup","","center","top")
Sign In.Activate()
Sign In.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$generic.favorite}TC Powerball Nbr Generator" then
form.load("PowerBallGenerator","popup","","center","top")
PowerBallGenerator.Activate()
PowerBallGenerator.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$generic.favorite}TC Graphics Examples" then
form.load("Drw_Page","popup","","center","top")
Drw_Page.Activate()
Drw_Page.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$generic.favorite}TC Interactive Bar Graph" then
form.load("Graphing","popup","","center","top")
Graphing.Activate()
Graphing.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$generic.favorite}TC Pong" then
form.load("Pong","popup","","center","top")
Pong.Activate()
Pong.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$code.library}TC King James Bible Reader" then
form.load("TC_KJB_Reader","popup","","center","top")
TC_KJB_Reader.Activate()
TC_KJB_Reader.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$generic.bookMark}My Book Marks" then
form.load("MyBookmarks","popup","","center","center")
MyBookmarks.Activate()
MyBookmarks.Show()
form.close()
Calendar:button43.activate()
else if mymenu = "{I=$$email}Email" Then
filename = "c:\TC_Suite\License Files\E105658A539M.txt"
result = file.exists(filename)
if result = .f. then
popup.email(" ")
else
ui_freeze(.t.)
form.load("TakeCharge","popup","","left","bottom")
TakeCharge.Activate()
TakeCharge:btn2.Push()
TakeCharge.Show()
form.close()
ui_freeze(.f.)
end if
Calendar:button43.activate()
else if mymenu = "{I=$$table.add}Company Setup Form" Then
filename = "c:\TC_Suite\License Files\C83476CT8W.txt"
result = file.exists(filename)
if result = .f. then
'Enter No License Code Here'
else
ui_freeze(.t.)
if is_object("items_overdue") then
:items_overdue.hide()
end if
form.load("CompanyInformationForm","popup","","center","top")
CompanyInformationForm.Activate()
CompanyInformationForm.New_record()
CompanyInformationForm.Show()
form.close()
ui_freeze(.f.)
end if
Calendar:button43.activate()
else if mymenu = "{I=$$generic.people}Contacts by Company" Then
filename = "c:\TC_Suite\License Files\C83476CT8W.txt"
result = file.exists(filename)
if result = .f. then
'Enter No License Code Here'
else
ui_freeze(.t.)
if is_object("items_overdue") then
:items_overdue.hide()
end if
form.load("ContactsbyCompany","popup","","center","top")
ContactsbyCompany.Activate()
ContactsbyCompany.Show()
form.close()
ui_freeze(.f.)
end if
Calendar:button43.activate()
else if mymenu = "{I=$$generic.people}Contacts History" Then
filename = "c:\TC_Suite\License Files\C83476CT8W.txt"
result = file.exists(filename)
if result = .f. then
'Enter No License Code Here'
else
ui_freeze(.t.)
if is_object("items_overdue") then
:items_overdue.hide()
end if
form.load("People_cdc","popup","","center","top")
People_cdc.Activate()
People_cdc.Show()
form.close()
ui_freeze(.f.)
end if
Calendar:button43.activate()
else if mymenu = "{I=$$format.text.edit}Quick Note Organizer" Then
filename = "c:\TC_Suite\License Files\C83476CT8W.txt"
result = file.exists(filename)
if result = .f. then
'Enter No License Code Here
else
ui_freeze(.t.)
if is_object("People_cdc") then
:people_cdc.hide()
end if
form.load("QuickNoteOrganizer","popup","","center","top")
QuickNoteOrganizer.Activate()
QuickNoteOrganizer.Show()
form.close()
ui_freeze(.f.)
end if
Calendar:button43.activate()
else if mymenu = "{I=$$format.text.edit}Open Items" Then
filename = "c:\TC_Suite\License Files\C83476CT8W.txt"
result = file.exists(filename)
if result = .f. then
'Enter No License Code Here
else
if is_object("People_cdc") then
:people_cdc.hide()
end if
if is_object("items_overdue") then
:items_overdue.hide()
end if
query.filter = ""
query.order = ""
prompt_result = ui_get_print_or_preview("Preview ")
If prompt_result = "Print" then
:Report.Print("upcoming_events",query.filter,query.order)
Else if prompt_result = "Preview" then
:Report.SaveAs("upcoming_events","PDF",query.filter,query.order,"",.T.)
End if
end if
Calendar:button43.activate()
else if mymenu = "{I=$$control.calculator}Calculator" Then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "Calc" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$generic.tools}File Manager" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "File Manager" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$application.ms.ie}Internet" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "Internet" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$generic.movie}Media Player" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "Media Player" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$generic.notepad}Notepad" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "Notepad" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$generic.palette}MS Paint" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "MS Paint" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "{I=$$application.ms.word}Word Pad" then
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
if tbl.File_name = "Write" then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
sys_open(CLine)
Calendar:button43.activate()
else if mymenu = "TC Control Panel" Then
parentform.close()
a5.show()
else if mymenu = "System Setup" Then
form.load("SetupWizard","popup","","center","top")
SetupWizard.Activate()
SetupWizard.Show()
form.close()
else if mymenu = "Exit" Then
a5.close()
else
tbl = table.open("applicationlist")
tbl.batch_begin()
tbl.fetch_first()
while .NOT. tbl.fetch_eof()
'ui_msg_box("",""+mymenu)
if Alltrim(tbl.File_name) = Alltrim(mymenu) then
CLine = tbl.File_location
end if
tbl.Fetch_Next()
end while
tbl.Batch_End()
tbl.close()
if file.filename_parse(CLine,"E") = ".exe"
sys_shell(CLine,1)
else
if left(Alltrim(CLine),3) = "www" then
URL_var = Alltrim(Cline)
sys_open(URL_var)
else
sys_open(CLine)
end if
end if
end if
I am not going to explain each line of this code because most of it has been discussed several times in earlier lessons. I will however tell you to pay close attention to the last section of the code starting with else.
Here we handle any user choice which is not hard coded above and with some simple branching and the combined use of sys_shell() and sys_open() we are able to perform the expected operation for the user. That’s all for today. Next we will look at the Setup Wizard and the code needed to populate our applicationlist table.
Thanks again for stopping by and Remember, if you need help with an Alpha Software application or wish to inquire about a custom application for your business go to our website
and inquire or contact
NLawson@cdc-TakeCharge.com
Have a great day.
Leave a comment