(the drag and drop part I think I got from Netmaestro)
There have been times that I needed to create a simple help window for quick
viewing and printing if needed. But it was always a hassle to do all the carefull
string and (" ") coding manually. So I wrote this program that takes a simple help text
file that you create in notepad, and then you drag and drop it on this program, and
codes it for use in an help Window's EditorGadget.
It's not fancy like the ones with all the links etc., but it works. And you can always make
any changes you like to it.
For Example: Take the following text and copy it to note pad and save it as helptest.txt
Code: Select all
This program takes a help text file that you drag and drop on it,
and codes it for use in an help Window's EditorGadget.
You first use notepad and type out what you want to put in your simple help message.
You can even use " characters in your help file.
Then you run this program and drag and drop that file on this programs window.
The converted file is created with the same name, but as a pb file, and is
displayed in Notepad when done.
You can copy and paste it to where you need it in your code, or load the file
in the editor to run and test it, and handle it from there.
You will just need to add the Help screen title to the help_title$ string below.
The created code helptest.pb, will open up in notepad for your viewing, but you can
also run it in the editor to check it too.
Code: Select all
;This program takes a help text file that you drag and drop on it,
;and codes it for use in an help Window's EditorGadget.
;You first use notepad and type out what you want to put in your simple help message.
;You can even use " characters in your help file.
;Then you run this program and drag and drop that file on this programs window.
;The converted file is created with the same name, but as a pb file, and is
;displayed in Notepad when done.
;You can copy and paste it to where you need it in your code, or load the file
;in the editor to run and test it, and handle it from there.
;You will just need to add the Help screen title to the help_title$ string below.
#MainWin=0
#WinX=300
#WinY=200
#WinW=220
#WinH=100
#BufferLength = 1000
#MEM_DROPFILES = 10
*Buffer = AllocateMemory(#BufferLength)
hWnd = OpenWindow(#MainWin, #WinX,#WinY, #WinW,#WinH, "Drag & Drop Help txt file here", #PB_Window_SystemMenu)
If hWnd
DragAcceptFiles_(WindowID(#MainWin), 1)
Repeat
Event= WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = 1
Case #WM_DROPFILES
*DropHandle = EventwParam()
;Debug *DropHandle
If *DropHandle
NbDroppedFiles = DragQueryFile_ (*DropHandle, $FFFFFFFF, *Buffer, #BufferLength)
DragQueryFile_(*DropHandle, k, *Buffer, #BufferLength)
DragFinish_(*DropHandle)
fn$=PeekS(*Buffer)
Goto convert
EndIf
EndSelect
Until Quit = 1
EndIf
End
convert:
If ReadFile(1,fn$) ; if file exists
;fn$=file name nf$=new file
;"+chr(34)+"
nf$=Left(fn$,Len(fn$)-3)+"pb"
CreateFile(2,nf$)
WriteStringN(2, "Enumeration")
WriteStringN(2, " #helpwin")
WriteStringN(2, " #help_EG")
WriteStringN(2, " #help_Print_btn")
WriteStringN(2, " #help_Close_btn")
WriteStringN(2, "EndEnumeration")
WriteStringN(2, " ")
WriteStringN(2, "Procedure helpwin(help_title$)")
WriteStringN(2, " OpenWindow(#helpwin,0,0,550,520,help_title$,#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu)")
WriteStringN(2, " EditorGadget(#help_EG, 5, 5, 540, 480 , #PB_Editor_ReadOnly)")
WriteStringN(2, " ButtonGadget(#help_Print_btn, 10, 490, 50, 20, "+Chr(34)+"Print"+Chr(34)+");have it first clear all")
WriteStringN(2, " ButtonGadget(#help_Close_btn, 275, 490, 50, 20, "+Chr(34)+"Close"+Chr(34)+")")
WriteStringN(2, " Define lf$=Chr(10)")
WriteStringN(2, " ls$="+Chr(34)+" "+Chr(34)+";leading space adjust")
WriteStringN(2, " lf$=Chr(10)")
WriteStringN(2, " hm$="+Chr(34)+Chr(34))
Repeat
dat$=ReadString(1)
If Trim(dat$)=""
WriteStringN(2," hm$=hm$"+Chr(43)+"lf$")
Else
;String$ = ReplaceString(String$, StringToFind$, StringToReplace$ [, Mode [, StartPosition]])
dat$ = ReplaceString(dat$, Chr(34), Chr(34)+"+Chr(34)+"+Chr(34))
WriteStringN(2," hm$=hm$+ls$"+Chr(43)+Chr(34)+dat$+Chr(34)+Chr(43)+"lf$")
EndIf
Until Eof(1)<>0
CloseFile(1)
WriteStringN(2, " SetGadgetText(#help_EG,hm$)")
WriteStringN(2, "EndProcedure")
WriteStringN(2, " ")
WriteStringN(2, "help_title$="+Chr(34)+Chr(34)+";put help title name here.")
WriteStringN(2, "helpwin(help_title$)")
WriteStringN(2, " ")
WriteStringN(2, ";Use this part just to test the created helpwin, or use in your code.")
WriteStringN(2, "Repeat")
WriteStringN(2, " Select WaitWindowEvent(5)")
WriteStringN(2, " Case #PB_Event_Gadget")
WriteStringN(2, " Select EventGadget()")
WriteStringN(2, " Case #help_Print_btn;-Print Help")
WriteStringN(2, " If GetActiveWindow()=#helpwin")
WriteStringN(2, " If Print_OpenPrinter("+Chr(34)+Chr(34)+","+Chr(34)+"PAPERSIZE="+Chr(34)+"+Str(#DMPAPER_LETTER)+"+Chr(34)+",ORIENTATION="+Chr(34)+"+Str(#DMORIENT_PORTRAIT))")
WriteStringN(2, " Print_StartPrinting("+Chr(34)+"MyData"+Chr(34)+")")
WriteStringN(2, " ")
WriteStringN(2, " y = 6 ; initial Y position")
WriteStringN(2, " Print_Font("+Chr(34)+"Lucida Console"+Chr(34)+",9);, #PB_Font_Default)")
WriteStringN(2, " ")
WriteStringN(2, " tlc=CountGadgetItems(#help_EG)")
WriteStringN(2, " If tlc>0")
WriteStringN(2, " For pl=0 To tlc-1")
WriteStringN(2, " ;If y<100;save as a test to save paper")
WriteStringN(2, " Result$ = GetGadgetItemText(#help_EG, pl,1)")
WriteStringN(2, " If Result$ ="+Chr(34)+"-pb-"+Chr(34)+";page break")
WriteStringN(2, " y=6")
WriteStringN(2, " Print_NewPage()")
WriteStringN(2, " Else")
WriteStringN(2, " Print_Text(0,y, Result$) ; 0,y is the line position")
WriteStringN(2, " y = y + 3 ; move down... for my font, 3 seemed about right")
WriteStringN(2, " If y>240")
WriteStringN(2, " ;The following takes care of the printer spooler never clears bug if the last")
WriteStringN(2, " ;print line would trigger the Print_NewPage() command.")
WriteStringN(2, " If pl<tlc-1")
WriteStringN(2, " Print_NewPage()")
WriteStringN(2, " y=6")
WriteStringN(2, " EndIf")
WriteStringN(2, " EndIf")
WriteStringN(2, " EndIf")
WriteStringN(2, " Next pl")
WriteStringN(2, " Print_StopPrinting()")
WriteStringN(2, " Else")
WriteStringN(2, " MessageRequester("+Chr(34)+"Print Data"+Chr(34)+","+Chr(34)+"Nothing To Print ..."+Chr(34)+",0)")
WriteStringN(2, " EndIf")
WriteStringN(2, " Else")
WriteStringN(2, " err$=Print_GetLastError()")
WriteStringN(2, " MessageRequester("+Chr(34)+"Print_StartPrinting()"+Chr(34)+",err$,0)")
WriteStringN(2, " EndIf")
WriteStringN(2, " Delay(1000);just to show printing else it's too fast.")
WriteStringN(2, " EndIf")
WriteStringN(2, " ")
WriteStringN(2, " Case #help_Close_btn")
WriteStringN(2, " If GetActiveWindow()=#helpwin")
WriteStringN(2, " CloseWindow(#helpwin)")
WriteStringN(2, " Break")
WriteStringN(2, " ;SetActiveWindow(Window_0)")
WriteStringN(2, " ;UseGadgetList(#Window_0)")
WriteStringN(2, " EndIf")
WriteStringN(2, " EndSelect")
WriteStringN(2, " Case #PB_Event_CloseWindow")
WriteStringN(2, " Select EventWindow()")
WriteStringN(2, " Case #helpwin")
WriteStringN(2, " CloseWindow(#helpwin)")
WriteStringN(2, " Break")
WriteStringN(2, " EndSelect")
WriteStringN(2, " EndSelect")
WriteStringN(2, "ForEver")
CloseFile(2)
RunProgram("notepad.exe" , nf$, Left(nf$,1))
EndIf