I have some InputRequesters Commented out that I originally had working perfectly. The entered information would be entered into the ListIcongadget perfectly, but I got the idea to create a second window and have the user be able to put all the information in on one window with stringGadgets, but I have failed so far. Below is the current code I have that shows I have tried a couple of things, but have failed with the second window idea so far
I would like the ability for the user to hit the "Return key" to advance to the next StringGadget also, currently only the "Tab key" works to advance it. I have a feeling that is default for the "Tab key" anyway.
Edit: (technically the program has 3 windows, but I'm not working with the help window yet more than what is already there)
You get the second window to pop up by clicking on the "Add Med" button
Code: Select all
; enumerated constants
Enumeration Window
#Window
#Window_1 = 1
#Window_2 = 2
EndEnumeration
Enumeration File
#File = 3
#File_1 = 4
EndEnumeration
Enumeration gadget
#gadget = 5
#gadget_1 = 6
EndEnumeration
Enumeration Icongadget
#Icongadget = 7
#IconGadget_1 = 8
EndEnumeration
Enumeration ImageGadget
#ImageGadget = 9
#ImageGadget_1 = 10
EndEnumeration
Enumeration Button
#Button = 11 ; Add Med button #Window
#Button_1 = 12 ; Ok button #Window_1
EndEnumeration
Enumeration Toolbar
#TOOLBAR = 13
EndEnumeration
Enumeration StatusBar
#StatusBar = 14
EndEnumeration
Enumeration
#StringGadget = 15
#StringGadget_1 = 16
#StringGadget_2 =17
#StringGadget_3 = 18
#StringGadget_4 = 19
;#StringGadget_5 = 20
EndEnumeration
#LVM_GETHEADER = #LVM_FIRST + 31
; Globals
Global oldListIconCallback, hHeader, redbrush, bluebrush
redbrush=CreateSolidBrush_($9D9E9F)
bluebrush=CreateSolidBrush_($9D9E9F)
; Proc for subclassed ListIconGadget
Procedure SubclassedListIcon(hwnd, msg, wparam, lparam)
Protected hdi.hd_item
result = CallWindowProc_(oldListIconCallback, hwnd, msg, wparam, lparam)
Select msg
Case #WM_NOTIFY
*pnmh.NMHDR = lparam
;--> Get handle to ListIcon header control
If *pnmh\code = #NM_CUSTOMDRAW
*pnmcd.NMCUSTOMDRAW = lparam
;--> Determine drawing stage
Select *pnmcd\dwDrawStage
Case #CDDS_PREPAINT
result = #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
;Get header text.
text$=Space(100)
hdi\mask = #HDI_TEXT
hdi\psztext = @text$
hdi\cchtextmax = Len(text$)
SendMessage_(hHeader, #HDM_GETITEM,*pnmcd\dwItemSpec,hdi)
;Check button state.
If *pnmcd\uItemState & #CDIS_SELECTED
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
;Offset text because of the selected button.
InflateRect_(*pnmcd\rc,-1,-1)
Else
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
EndIf
;Draw background.
;Here we alternate red text on blue background.
InflateRect_(*pnmcd\rc,-1,-1)
SetBkMode_(*pnmcd\hdc,#TRANSPARENT)
If *pnmcd\dwItemSpec&1
FillRect_(*pnmcd\hdc, *pnmcd\rc, redbrush)
SetTextColor_(*pnmcd\hdc, $A0222222)
Else
FillRect_(*pnmcd\hdc, *pnmcd\rc, bluebrush)
SetTextColor_(*pnmcd\hdc, $A0222222)
EndIf
DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_CENTER | #DT_VCENTER | #DT_END_ELLIPSIS)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
; declare procedure to be able to place it at the bottom of program
Declare EnterInfo()
Declare MedsCompHelp()
Declare ButtonPressed()
; window constant settings
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget
; open a window to use for the program
If OpenWindow(#Window, 0, 0, 1024, 768, "Meds Companion", wFlags)
Global Med.s, DoseStrength.s, NumDoses.s, IntendedUse.s, MedUses.s
LoadFont(0, "Arial Black", 11, #PB_Font_Bold)
; toolbar menu
If CreateMenu(0, WindowID(#Window))
MenuTitle("Open")
MenuItem(1, "New List")
MenuItem(2, "Open List")
OpenSubMenu("Recent Files")
CloseSubMenu()
MenuItem(3, "Save" +Chr(9)+"Ctrl+S")
MenuItem(4, "Save as"+Chr(9)+"Ctrl+A")
MenuItem(5, "Close" +Chr(9)+"Ctrl+C")
MenuItem(6, "Quit")
MenuTitle("Help")
MenuItem(7, "Meds Companion help")
MenuItem(8, "Online Medication lookup")
EndIf
; create form to show and use information
LFlags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_MultiSelect | #LVS_NOSORTHEADER
; create gadget for medication list
ListIconGadget(#Icongadget, 1, 25, 1022, 700, "MEDICATION NAME", 150, LFlags)
hHeader = SendMessage_(GadgetID(#Icongadget), #LVM_GETHEADER, 0, 0)
;Subclass ListIcon so we can customdraw the header text
oldListIconCallback = SetWindowLong_(GadgetID(#Icongadget), #GWL_WNDPROC, @SubclassedListIcon())
;set the gadget font, back color And line color
SetGadgetFont(#Icongadget, FontID(0))
SetGadgetColor(#Icongadget, #PB_Gadget_BackColor, $D0CDCECE)
;SetGadgetColor(#gadget, #PB_Gadget_LineColor, $D048494A)
; add medication button
ButtonGadget(#Button, 10, 0, 100, 25, "Add Med")
; add category columns
AddGadgetColumn(#Icongadget, 1, "DOSAGE (mg)", 120)
AddGadgetColumn(#Icongadget, 2, "DAILY DOSES", 110)
AddGadgetColumn(#Icongadget, 3, "PRESCRIBED FOR", 240)
AddGadgetColumn(#Icongadget, 4, "Medication Uses", 397)
; create statusbar at the bottom
If CreateStatusBar(#StatusBar, WindowID(#Window))
AddStatusBarField(155) ; total medications
AddStatusBarField(83) ; blank and borderless
AddStatusBarField(90) ; doses daily(Either total doses or total of the highlighted medication in the list
AddStatusBarField(130) ;
AddStatusBarField(497)
EndIf
; statusbar field text
StatusBarText(#StatusBar, 0, "Total Medications", #PB_StatusBar_BorderLess)
StatusBarText(#StatusBar, 1, "", #PB_StatusBar_Center | #PB_StatusBar_BorderLess)
StatusBarText(#StatusBar, 2, "Total Daily Doses", #PB_StatusBar_Center | #PB_StatusBar_BorderLess)
FreeFont(0)
; main program loop
Repeat
Event = WaitWindowEvent()
; main menu detection
Select Event
Case #PB_Event_CloseWindow
FreeGadget(#Icongadget)
CloseWindow(#Window)
Case #PB_Event_Menu
Select EventMenu()
Case 1 ; start new medication list
ClearGadgetItems(#Icongadget)
Case 2 ; load saved medication list
Input$ = InputRequester("Meds Companion", "Enter saved list name", "")
If Input$ = ""
MessageRequester("Meds Companion", Input$)
Else
a$ = "The requester was canceled or there was nothing entered."
MessageRequester("Information", a$, 0)
EndIf
; save current medication list
Case 3
Input$ = SaveFileRequester("Meds Companion","Untitled.txt", "Text (*.txt)|*.txt;*.bat|*.txt;*.dat|All files (*.*)|*.*", 0)
; quit program
Case 6
ClearGadgetItems(#Icongadget)
FreeGadget(#Icongadget)
End
MessageRequester("Information", a$, 0)
Case 7
MedsCompHelp()
EndSelect
EndSelect
; enter new medication information
;If Event = #PB_Event_Gadget
If EventGadget() = #Button
EnterInfo()
EndIf
;EndIf
Until Event = #PB_Event_CloseWindow
EndIf
; enter medication procedure
Procedure EnterInfo()
InitSprite()
InitKeyboard()
OpenWindow(#Window_1, 0, 0, 290, 280, "Meds Companion", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, WindowID(#Window))
LoadFont(0, "Arial", 10)
CreateImage(0, 342, 300, 24, $D0D5D5D6)
StartDrawing(ImageOutput(0))
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5, 20, "Enter medication name", #Black, $D0A8A8A8)
StringGadget(#StringGadget, 5, 37, 250, 20, Med) ;medication
DrawText(5, 65, "Enter dosage strength", #Black, $D0A8A8A8)
StringGadget(#StringGadget_1, 5, 83, 250, 20, DoseStrength$) ; dosage strength
DrawText(5, 110, "Enter number of daily doses", #Black, $D0A8A8A8)
StringGadget(#StringGadget_2, 5, 129, 250, 20, NumDoses$) ; number of daily doses
DrawText(5, 152, "Enter what medication is proscribed for", #Black, $D0A8A8A8)
StringGadget(#StringGadget_3, 5, 170, 250, 20, IntendedUse$) ; proscribed for
DrawText(5, 195, " Enter medication uses", #Black, $D0A8A8A8)
StringGadget(#StringGadget_4, 5, 214, 250, 20, MedUses$) ; uses for medication
StopDrawing()
SetActiveGadget(15);#StringGadget)
ImageGadget(#ImageGadget, 0, 0, 342, 247, ImageID(0))
ButtonGadget(#Button_1, 196, 245, 60, 25, "Ok")
BindGadgetEvent(#Button_1, @ButtonPressed())
;Input_Med = StringGadget(#StringGadget,10, 130, 250, 20, "")
; Med = InputRequester("Medication Companion", "Enter medication name", "")
; DoseStrength = InputRequester("Medication Companion", "Enter dosage strength", "")
; NumDoses = InputRequester("Medication Companion", "Enter number of daily doses", "")
; IntendedUse = InputRequester("Medication Companion", "Enter what the medication is proscribed For", "")
; MedUses = InputRequester("Medication Companion", "Medication Uses", "")
;AddGadgetItem(#Icongadget, -1, Med$ + Chr(10) + DoseStrength$ + " mg" + Chr(10) + NumDoses$ + Chr(10) + IntendedUse$ + Chr(10) + MedUses$)
SetGadgetItemColor(#Icongadget, -1, #PB_Gadget_FrontColor, $A0AA2222, #PB_All)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
FreeGadget(12) ; button for window_1
For a = 15 To 19
FreeGadget(a)
Next a
CloseWindow(#Window_1)
Break
EndSelect
For i = 15 To 19
If GetGadgetState(i)
Debug i
Break
EndIf
Next
ForEver
EndProcedure
; help file procedure
Procedure MedsCompHelp()
; window constant settings
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget
OpenWindow(#Window_2, 0, 0, 950, 550, "Meds Companion help", wFlags, WindowID(#Window))
; open a window to use for the program
;OpenHelp("Help.chm", "Help\Help.html")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
CloseWindow(3)
Break
EndIf
ForEver
EndProcedure
Procedure ButtonPressed()
Protected i, Gadget = EventGadget()
Debug Gadget
For i = 15 To 19
If i = Gadget
Med = GetGadgetText(#StringGadget)
DoseStrength = GetGadgetText(#StringGadget_1)
NumDoses = GetGadgetText(#StringGadget_2)
IntendedUse = GetGadgetText(#StringGadget_3)
MedUses = GetGadgetText(#StringGadget_4)
AddGadgetItem(#Icongadget, -1, Med + Chr(10) + DoseStrength + " mg" + Chr(10) + NumDoses + Chr(10) + IntendedUse + Chr(10) + MedUses)
EndIf
Next i
EndProcedure