this program will capture text from the clipboard, meaning an name and address.
It will do a little cleaning of the name and zip code line
The printout goes to a predetermined printer, we are using a printer named "XXenvelope". If you do not like that one you can patch the envprint.exe and put your own printer name in it.
This is the first time i have programmed using a windows printer driver, so that is why it is so simple, but is going to work for me.
An ini file will be used if it exist with the next version.
We have OKIDATA 320 printers and i wanted this program to work with those and it does, but there has been little testing but it should work fine.
The program ask you to confirm the print job before it prints.
A nice little ini file to help this program along would be nice.
If you do not have a printer named XXenvelope this program will still run, just not print. Some people might use this program to clean up an address then copy it back to the clipboard for another program to use.
You can code the function cleansetextbox to do your dirty cleaning of the address for your special reasons.
It will do a little cleaning of the name and zip code line
The printout goes to a predetermined printer, we are using a printer named "XXenvelope". If you do not like that one you can patch the envprint.exe and put your own printer name in it.
This is the first time i have programmed using a windows printer driver, so that is why it is so simple, but is going to work for me.
An ini file will be used if it exist with the next version.
We have OKIDATA 320 printers and i wanted this program to work with those and it does, but there has been little testing but it should work fine.
The program ask you to confirm the print job before it prints.
A nice little ini file to help this program along would be nice.
If you do not have a printer named XXenvelope this program will still run, just not print. Some people might use this program to clean up an address then copy it back to the clipboard for another program to use.
You can code the function cleansetextbox to do your dirty cleaning of the address for your special reasons.
Code:
'envprint.bas 'compiled with powerbasic 'pbwin ver 9.01 'program is designed to copy and paste an address 'then print it out to a predetermined designated printer ' 'i am not good with printing in a windows enviroment 'i leave that headache for you 'see the XPRINT statments for adjusting print spacing and 'see FONT NEW for creating a font #PBFORMS CREATED V1.51 '------------------------------------------------------------------------------ ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '------------------------------------------------------------------------------ #COMPILE EXE #DIM ALL '------------------------------------------------------------------------------ ' ** Includes ** '------------------------------------------------------------------------------ #PBFORMS BEGIN INCLUDES #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF #INCLUDE "PBForms.INC" #PBFORMS END INCLUDES '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ #PBFORMS BEGIN CONSTANTS %IDD_DIALOG1 = 101 %IDC_TEXTBOX1 = 999 %IDC_BUTTON1 = 1001 %IDC_BUTTON2 = 1002 %IDC_BUTTON3 = 1003 %IDC_BUTTON4 = 1004 %IDC_BUTTON5 = 1005 %IDC_BUTTON6 = 1006 #PBFORMS END CONSTANTS GLOBAL gstextbox AS STRING GLOBAL gstextboxold AS STRING GLOBAL gstemp AS STRING GLOBAL gltemp AS LONG GLOBAL gltemp2 AS LONG GLOBAL hDlg AS DWORD '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG FUNCTION printenvelope() AS LONG LOCAL I AS LONG LOCAL J AS LONG LOCAL atemp AS STRING LOCAL sfonttemp AS STRING LOCAL ifonttemp AS LONG LOCAL sprintername AS STRING sprintername="XXenvelope " sprintername=TRIM$(sprintername) j=PARSECOUNT(gstextbox,$CRLF) DIM a(1 TO j) AS STRING PARSE gstextbox,a(),$CRLF XPRINT ATTACH sprintername,"Envelope using envprint.exe" IF XPRINT$="" THEN MSGBOX ("There has to exist a windows printer named "+$CRLF+sprintername+$CRLF+" for this program to print to.") EXIT FUNCTION END IF FONT NEW sfonttemp,12,0,1,1,0 TO ifonttemp 'this is a fixed font, see FONT NEW for details REM below starting on the 11 line using the above font REM then spacing over 33 spaces before printing XPRINT SET FONT ifonttemp FOR i=1 TO 10 XPRINT NEXT i FOR i=1 TO j gstemp= SPACE$(33)+A(i) XPRINT gstemp NEXT i XPRINT FORMFEED XPRINT CLOSE CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, "" gstextboxold=gstextbox END FUNCTION FUNCTION cleansetextbox() AS LONG gstextboxold=gstextbox gstextbox=TRIM$(gstextbox) gstextbox=UCASE$(gstextbox): REM convert the text to uppercase if desired in the cleanse process gltemp=INSTR(UCASE$(gstextbox)," ZIP ") IF gltemp THEN gstextbox=LEFT$(gstextbox,gltemp)+RIGHT$(gstextbox,LEN(gstextbox)-gltemp-4) END IF REM remove extra blank lines and any spaces prior and after any CRLF WHILE INSTR(gstextbox, " "+$CRLF) REPLACE " "+$CRLF WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+" ") REPLACE $CRLF+" " WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+$CRLF) REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND IF gstextbox=$CRLF THEN gstextbox="" REM CRLF from the beginning of the textbox if it exist IF LEN(gstextbox)>1 THEN IF LEFT$(gstextbox,2)=$CRLF THEN gstextbox=RIGHT$(gstextbox,LEN(gstextbox)-2) END IF END IF gltemp=INSTR(gstextbox,$CRLF) IF gltemp AND INSTR(LEFT$(gstextbox,gltemp-1),",") THEN gstemp=LEFT$(gstextbox,gltemp-1) gltemp=INSTR(-1,gstemp,",") gstemp=RIGHT$(gstemp,LEN(gstemp)-gltemp)+" "+LEFT$(gstemp,gltemp-1) gltemp=INSTR(gstextbox,$CRLF) gstextbox=TRIM$(gstemp)+RIGHT$(gstextbox,LEN(gstextbox)-gltemp+1) END IF END FUNCTION #PBFORMS DECLARATIONS '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ FUNCTION PBMAIN() gstextbox="" ShowDIALOG1 %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowDIALOG1Proc() SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler DIALOG SEND CBHNDL, %WM_CHANGEUISTATE, MAKLNG(%UIS_CLEAR, %UISF_HIDEACCEL), 0 CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_TEXTBOX1 CASE %IDC_BUTTON1 REM print the text from textbox1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstextbox gstextbox=TRIM$(gstextbox) gstextbox=UCASE$(gstextbox): REM convert the text to uppercase if desired in the printing process REM remove the word " zip " if it exist on any line gltemp=INSTR(UCASE$(gstextbox)," ZIP ") IF gltemp THEN gstextbox=LEFT$(gstextbox,gltemp)+RIGHT$(gstextbox,LEN(gstextbox)-gltemp-4) END IF REM remove extra blank lines and any spaces prior and after any CRLF WHILE INSTR(gstextbox, " "+$CRLF) REPLACE " "+$CRLF WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+" ") REPLACE $CRLF+" " WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+$CRLF) REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND IF gstextbox=$CRLF THEN gstextbox="" REM CRLF from the beginning of the textbox if it exist IF LEN(gstextbox)>1 THEN IF LEFT$(gstextbox,2)=$CRLF THEN gstextbox=RIGHT$(gstextbox,LEN(gstextbox)-2) END IF END IF IF gstextbox<>"" THEN gltemp=MSGBOX (gstextbox, %MB_YESNO OR %MB_DEFBUTTON2,"Confirm print") IF gltemp=6 THEN printenvelope() END IF END IF CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 CASE %IDC_BUTTON2 REM clear the text in textbox1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstextbox WHILE INSTR(gstextbox, " "+$CRLF) REPLACE " "+$CRLF WITH $CRLF IN gstextbox REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND WHILE INSTR(gstextbox, $CRLF+$CRLF) REPLACE $CRLF+$CRLF WITH $CRLF IN gstextbox WEND IF gstextbox=$CRLF THEN gstextbox="" IF gstextbox<>"" THEN gstextboxold=gstextbox CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, "" END IF CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 CASE %IDC_BUTTON3 REM cleanse the text in textbox1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstextbox IF TRIM$(gstextbox)<>"" THEN cleansetextbox() CONTROL SET TEXT HDLG,%IDC_TEXTBOX1,gstextbox END IF CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 CASE %IDC_BUTTON4 REM undo IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstemp gstextbox=gstextboxold gstextboxold=gstemp CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, gstextbox CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END IF CASE %IDC_BUTTON5 REM send text to clipboard IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstemp IF gstemp<>"" THEN FOR gltemp=1& TO 100& CLIPBOARD RESET, gltemp2 IF gltemp2 THEN EXIT FOR SLEEP 20 NEXT gltemp FOR gltemp=1 TO 100& CLIPBOARD SET TEXT gstemp,gltemp2 IF gltemp2 THEN EXIT FOR SLEEP 30 NEXT gltemp CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END IF END IF CASE %IDC_BUTTON6 REM get text from clipboard IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN FOR gltemp=1 TO 100& CLIPBOARD GET TEXT gstemp,gltemp2 IF gltemp2 THEN EXIT FOR SLEEP 30 NEXT gltemp IF gltemp2 THEN CONTROL GET TEXT HDLG,%IDC_TEXTBOX1 TO gstextboxold gstextbox=gstemp cleansetextbox() CONTROL SET TEXT HDLG,%IDC_TEXTBOX1, gstextbox CONTROL SET FOCUS hDlg, %IDC_TEXTBOX1 END IF END IF END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_DIALOG1->-> ' LOCAL hDlg AS DWORD LOCAL hFont1 AS DWORD DIALOG NEW hParent, "Envelope print", 70, 70, 331, 88, %WS_POPUP OR _ %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 0, 3, 330, 60, %WS_CHILD OR _ %WS_VISIBLE OR %WS_TABSTOP OR %ES_LEFT OR %ES_MULTILINE OR _ %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "&Print", 112, 65, 100, 22, _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER _ OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "&Clear", 304, 70, 26, 15, _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON3, "Cleanse", 62, 70, 35, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON4, "Undo", 274, 70, 26, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON5, "To clipboard", 224, 70, 44, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD BUTTON, hDlg, %IDC_BUTTON6, "&Import clipboard", 2, 70, 55, 15,_ %WS_CHILD OR %WS_VISIBLE OR %BS_TEXT OR %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING hFont1 = PBFormsMakeFont("Courier", 10, 400, %FALSE, %FALSE, %FALSE, _ %ANSI_CHARSET) CONTROL SEND hDlg, %IDC_TEXTBOX1, %WM_SETFONT, hFont1, 0 #PBFORMS END DIALOG DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt #PBFORMS BEGIN CLEANUP %IDD_DIALOG1 DeleteObject hFont1 #PBFORMS END CLEANUP FUNCTION = lRslt END FUNCTION '------------------------------------------------------------------------------
Comment