Printing File PDF In PowerBuilder Using utility PDFtoPrinter is a program for printing PDF files from the Windows command line
Source code
nov_runprinter from nonvisualobject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 |
forward global type nov_runprinter from nonvisualobject end type type process_information from structure within nov_runprinter end type type startupinfo from structure within nov_runprinter end type type shellexecuteinfo from structure within nov_runprinter end type type str_security_attributes from structure within nov_runprinter end type end forward type process_information from structure long hprocess long hthread long dwprocessid long dwthreadid end type type startupinfo from structure long cb string lpreserved string lpdesktop string lptitle long dwx long dwy long dwxsize long dwysize long dwxcountchars long dwycountchars long dwfillattribute long dwflags unsignedinteger wshowwindow unsignedinteger cbreserved2 long lpreserved2 long hstdinput long hstdoutput long hstderror end type type shellexecuteinfo from structure unsignedlong cbsize unsignedlong fmask long hwnd string lpverb string lpfile string lpparameters string lpdirectory long nshow long hinstapp long lpidlist string lpclass long hkeyclass long hicon long hmonitor long hprocess end type type str_security_attributes from structure long nLength long lpSecurityDescriptor long bInheritHandle end type global type nov_runprinter from nonvisualobject autoinstantiate end type type prototypes Function Boolean CreateProcess ( & String lpApplicationName, & Ref String lpCommandLine, & long lpProcessAttributes, & long lpThreadAttributes, & Boolean bInheritHandles, & Long dwCreationFlags, & long lpEnvironment, & String lpCurrentDirectory, & STARTUPINFO lpStartupInfo, & Ref PROCESS_INFORMATION lpProcessInformation & ) Library "kernel32.dll" Alias For "CreateProcessW" Function Long WaitForSingleObject ( & long hHandle, & Long dwMilliseconds & ) Library "kernel32.dll" Function Boolean CloseHandle ( & long hObject & ) Library "kernel32.dll" Function Boolean GetExitCodeProcess ( & long hProcess, & Ref Long lpExitCode & ) Library "kernel32.dll" Function Boolean TerminateProcess ( & long hProcess, & Long uExitCode & ) Library "kernel32.dll" Function Long ExpandEnvironmentStrings ( & String lpSrc, & Ref String lpDst, & Long nSize & ) Library "kernel32.dll" Alias For "ExpandEnvironmentStringsW" Function Boolean ShellExecuteEx ( & Ref SHELLEXECUTEINFO lpExecInfo & ) Library "shell32.dll" Alias For "ShellExecuteExW" FUNCTION ulong GetModuleFileName (ulong hinstModule, ref string lpszPath, ulong cchPath ) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetModuleFileNameA;ansi" // ;ansi required for PB10 or better Subroutine SleepMS ( & ulong dwMilliseconds & ) Library "kernel32.dll" Alias For "Sleep" Function long GetDesktopWindow ( & ) Library "user32.dll" Function long GetWindow ( & long hWnd, & ulong uCmd & ) Library "user32.dll" Function long GetWindowText ( & long hWnd, & Ref string lpString, & long nMaxCount & ) Library "user32.dll" Alias For "GetWindowTextW" Function ulong GetWindowThreadProcessId ( & long hWnd, & Ref ulong lpdwProcessId & ) Library "user32.dll" Function long SetParent ( & long hWndChild, & long hWndNewParent & ) Library "user32.dll" Function boolean MoveWindow ( & long hWnd, & long xpos, & long ypos, & long nWidth, & long nHeight, & boolean bRepaint & ) Library "user32.dll" Function boolean ShowWindow ( & long hWnd, & long nCmdShow & ) Library "user32.dll" Function Long SetWindowLong( & long hWnd, & long nIndex, & ulong dwNewLong & ) Library "user32.dll" Alias For "SetWindowLongW" FUNCTION ulong CreatePipe(ref ulong phReadPipe,ref ulong phWritePipe, & ref str_security_attributes lpPipeAttributes,ulong nSize) LIBRARY "kernel32.dll" function long ReadFile( ulong hFile, ref blob lpBuffer, long nNumberOfBytesToRead, & ref long lpNumberOfBytesRead, ulong lpOverlapped) library "kernel32.dll" function ulong GetLastError() library "kernel32.dll" FUNCTION ulong PeekNamedPipe(ulong hNamedPipe,ref blob lpBuffer,ulong nBufferSize,& ref ulong lpBytesRead,ref ulong lpTotalBytesAvail,ref ulong lpBytesLeftThisMessage) LIBRARY "kernel32.dll" //length of the ansi string private function long lstrlenA(long lpString1)library "kernel32.dll" alias for "lstrlenA" private function long lstrlenA(ref blob b)library 'kernel32' alias for 'lstrlenA' //convert multibyte to wide char private function long MultiByteToWideChar(ulong CodePage, long dwFlags, long lpMBStr, long cchMB, ref string lpWStr, long cchWStr)library 'kernel32.dll' alias for 'MultiByteToWideChar' private function long MultiByteToWideChar(ulong CodePage, long dwFlags, readonly blob lpMBStr, long cchMB, ref string lpWStr, long cchWStr)library 'kernel32.dll' alias for 'MultiByteToWideChar' private function long WideCharToMultiByte(ulong CodePage,long dwFlags,readonly string lpWideCharStr,long cchWideChar,long mbstr,long cchMultiByte,long lpDefaultChar, ref long lpUsedDefaultChar)library 'kernel32.dll' alias for 'WideCharToMultiByte' private function long WideCharToMultiByte(ulong CodePage,long dwFlags,readonly string lpWideCharStr,long cchWideChar,ref blob mbstr,long cchMultiByte,long lpDefaultChar, long lpUsedDefaultChar)library 'kernel32.dll' alias for 'WideCharToMultiByte' Function ULong SHGetFolderPath(ULong hwndOwner, Long nFolder, ULong hToken, Long dwFlags, Ref String pszPath) Library 'shell32.dll' Alias For "SHGetFolderPathA;Ansi" end prototypes type variables long il_ansi_cp Boolean ib_terminate Long il_millsecs Constant Long INFINITE = -1 Constant Long WAIT_ABANDONED = 128 Constant Long WAIT_COMPLETE = 0 Constant Long WAIT_OBJECT_0 = 0 Constant Long WAIT_TIMEOUT = 258 Constant Long SW_HIDE = 0 Constant Long SW_SHOWNORMAL = 1 Constant Long SW_NORMAL = 1 Constant Long SW_SHOWMINIMIZED = 2 Constant Long SW_SHOWMAXIMIZED = 3 Constant Long SW_MAXIMIZE = 3 Constant Long SW_SHOWNOACTIVATE = 4 Constant Long SW_SHOW = 5 Constant Long SW_MINIMIZE = 6 Constant Long SW_SHOWMINNOACTIVE = 7 Constant Long SW_SHOWNA = 8 Constant Long SW_RESTORE = 9 Constant Long SW_SHOWDEFAULT = 10 Constant Long SW_FORCEMINIMIZE = 11 Constant Long SW_MAX = 11 Constant Long STARTF_USESHOWWINDOW = 1 Constant Long STARTF_USESIZE = 2 Constant Long STARTF_USEPOSITION = 4 Constant Long STARTF_USECOUNTCHARS = 8 Constant Long STARTF_USEFILLATTRIBUTE = 16 Constant Long STARTF_RUNFULLSCREEN = 32 Constant Long STARTF_FORCEONFEEDBACK = 64 Constant Long STARTF_FORCEOFFFEEDBACK = 128 Constant Long STARTF_USESTDHANDLES = 256 Constant Long STARTF_USEHOTKEY = 512 Constant Long CREATE_DEFAULT_ERROR_MODE = 67108864 Constant Long CREATE_FORCEDOS = 8192 Constant Long CREATE_NEW_CONSOLE = 16 Constant Long CREATE_NEW_PROCESS_GROUP = 512 Constant Long CREATE_NO_WINDOW = 134217728 Constant Long CREATE_SEPARATE_WOW_VDM = 2048 Constant Long CREATE_SHARED_WOW_VDM = 4096 Constant Long CREATE_SUSPENDED = 4 Constant Long CREATE_UNICODE_ENVIRONMENT = 1024 Constant Long DEBUG_PROCESS = 1 Constant Long DEBUG_ONLY_THIS_PROCESS = 2 Constant Long DETACHED_PROCESS = 8 Constant Long HIGH_PRIORITY_CLASS = 128 Constant Long IDLE_PRIORITY_CLASS = 64 Constant Long NORMAL_PRIORITY_CLASS = 32 Constant Long REALTIME_PRIORITY_CLASS = 256 Constant Long Null = 0 Constant Long GWL_STYLE = -16 Constant ULong GW_HWNDNEXT = 2 Constant ULong GW_OWNER = 4 Constant ULong GW_CHILD = 5 Constant ULong WS_POPUP = 2147483648 Constant ULong WM_SIZE = 5 Constant ULong WM_CLOSE = 16 Long il_hWnd String is_commandline String is_message String is_printexe end variables forward prototypes public subroutine of_set_options (boolean ab_terminate, decimal adec_seconds) private function long of_run (string as_exefullpath, long al_showwindow) public function long of_run (string as_exefullpath, trigevent a_windowstate) public function long of_run (string as_exefullpath, windowstate a_windowstate) public function string of_get_shellexecute (string as_filename, string as_shellverb) public function long of_shellrun (string as_filename, string as_shellverb, long al_showwindow) public function long of_shellrun (string as_filename, string as_shellverb, trigevent a_windowstate) public function long of_shellrun (string as_filename, string as_shellverb, windowstate a_windowstate) public function integer of_lastpos (string as_str1, string as_str2) public function string of_getcurfolderfile (string as_path) public function string of_getfilename (string as_path) public function string of_getfolder (string as_path) public function string of_getmodulepath () public function integer of_readfile_encode (string as_file, ref string as_returnstring) public function integer of_readfile (string as_file, ref string as_returnstring) public subroutine of_parse (string as_parse, string as_list, ref string as_array[]) public subroutine of_createlocalfolders (string as_filename) public function string of_replaceall (string as_oldstring, string as_findstr, string as_replace) private function long of_run_hand (string as_exefullpath, long al_showwindow) public subroutine of_resize (integer newwidth, integer newheight) private function long of_getmbcp (boolean ab_utf8) public function long of_string2mb (boolean ab_utf8, string src, ref blob dst) public function boolean of_writetext_utf8 (string filename, string text, encoding e, ref string as_error) public function string of_getappname () public function string of_getappname_notextention () public function string of_getsysdir () public function string of_getappdirtemp () public subroutine of_cleardirtemp (string as_remark) public subroutine of_cleardirtemp () public function integer of_parse (string as_string, ref string as_array[], ref integer ai_count, string as_delimiter) public function integer of_printing (string as_filepdf, string as_printername) public function string of_getprinterdefalut () public function integer of_getprinterlist (ref string as_printer_name[]) end prototypes public subroutine of_set_options (boolean ab_terminate, decimal adec_seconds);//==================================================================== // Function: n_ftpcs.of_set_options() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // boolean ab_terminate // decimal adec_seconds //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== ib_terminate = ab_terminate il_millsecs = adec_seconds * 1000 end subroutine private function long of_run (string as_exefullpath, long al_showwindow);//==================================================================== // Function: n_ftpcs.of_run() //-------------------------------------------------------------------- // Description: Run And Read Message //-------------------------------------------------------------------- // Arguments: // string as_exefullpath // long al_showwindow //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== //constant ulong STARTF_USESHOWWINDOW = 1 //constant ulong STARTF_USESTDHANDLES = 256 Constant ULong DUPLICATE_SAME_ACCESS = 2 Constant ULong BUFSIZE = 1024 Constant ULong PIPE_READMODE_BYTE = 0 Constant ULong PIPE_NOWAIT = 1 str_security_attributes lstr_secure_attrib startupinfo lstr_si process_information lstr_pi Long ll_null, ll_creationflags, ll_exitcode, ll_msecs String ls_null, ls_message, ls_messtemp UnsignedLong lul_null, luoverlapped, lul_err UnsignedLong hpiperead,hpipewrite UnsignedLong lpbytesread, lptotalbytesavail, lpbytesleft, lpbufoutlen Boolean lb_created Blob lbl_read Long lbytesread, lpipeoutlen Long ll_flagmess // initialize arguments lbl_read = Blob(Space(BUFSIZE)) SetNull(ll_null) SetNull(ls_null) SetNull(lul_null) luoverlapped = 0 lstr_secure_attrib.nLength = 12 lstr_secure_attrib.bInheritHandle = 1 lstr_secure_attrib.lpSecurityDescriptor = 0 //lstr_si.cb = 72 lstr_si.cb = 17 *4 //lstr_si.dwFlags = STARTF_USESHOWWINDOW lstr_si.dwFlags = STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES lstr_si.wShowWindow = al_showwindow //ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS ll_creationflags = 0 If CreatePipe(hpiperead, hpipewrite, lstr_secure_attrib, 0) = 0 Then //messageBox("error", "create pipe failed") Return -1 End If lstr_si.hStdOutput = hpipewrite lstr_si.hStdError = hpipewrite lstr_si.hStdInput = hpipewrite // create process/thread and execute the passed program If CreateProcess(ls_null, as_exefullpath, ll_null, ll_null, True, ll_creationflags, ll_null, ls_null, lstr_si, lstr_pi) Then // wait for the process to complete If il_millsecs > 0 Then // wait until process ends or timeout period expires ll_exitcode = WaitForSingleObject(lstr_pi.hProcess, il_millsecs) // terminate process if not finished If ib_terminate And ll_exitcode = WAIT_TIMEOUT Then TerminateProcess(lstr_pi.hProcess, -1) ll_exitcode = WAIT_TIMEOUT Else // check for exit code GetExitCodeProcess(lstr_pi.hProcess, ll_exitcode) End If Else // close hPipeWrite and thread handles CloseHandle(hpipewrite) CloseHandle(lstr_pi.hThread) //redirect out message lbytesread = ReadFile( hpiperead, lbl_read, BUFSIZE,lpipeoutlen, 0) If lbytesread = 0 Then lul_err = GetLastError() If lul_err = 109 Then //messagebox("error reading", "error 109 - broken pipe") Else //messagebox("error reading", string(lul_err)) End If End If ls_message = "" ll_flagmess = 0 Do While lbytesread > 0 And lpipeoutlen > 0 ls_messtemp = String(BlobMid(lbl_read,1, lpipeoutlen), EncodingUTF8!) lbytesread = ReadFile( hpiperead, lbl_read, BUFSIZE,lpipeoutlen, 0) If ll_flagmess > 0 Then if len(trim(ls_messtemp)) > 0 then ls_message += ls_messtemp end if End If If Pos(ls_messtemp, "JOBSTARTFLAG") > 0 Then ll_flagmess ++ End If Loop is_message = ls_message // wait until process ends WaitForSingleObject(lstr_pi.hProcess, INFINITE) // check for exit code GetExitCodeProcess(lstr_pi.hProcess, ll_exitcode) End If // close process and hPipeRead closeHandle(hpiperead) CloseHandle(lstr_pi.hProcess) //CloseHandle(lstr_pi.hThread) Else // return failure ll_exitcode = -1 End If Return ll_exitcode /* //==================================================================== // Function: n_ftpcs.of_run() //-------------------------------------------------------------------- // Description: Run And Read Message //-------------------------------------------------------------------- // Arguments: // string as_exefullpath // long al_showwindow //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== //constant ulong STARTF_USESHOWWINDOW = 1 //constant ulong STARTF_USESTDHANDLES = 256 Constant ULong DUPLICATE_SAME_ACCESS = 2 Constant ULong BUFSIZE = 1024 Constant ULong PIPE_READMODE_BYTE = 0 Constant ULong PIPE_NOWAIT = 1 str_security_attributes lstr_secure_attrib startupinfo lstr_si process_information lstr_pi Long ll_null, ll_creationflags, ll_exitcode, ll_msecs String ls_null, ls_message UnsignedLong lul_null, luoverlapped, lul_err UnsignedLong hpiperead,hpipewrite UnsignedLong lpbytesread, lptotalbytesavail, lpbytesleft, lpbufoutlen Boolean lb_created Blob lbl_read Long lbytesread, lpipeoutlen Long ll_row, ll_pos String ls_tmp // initialize arguments lbl_read = Blob(Space(BUFSIZE)) SetNull(ll_null) SetNull(ls_null) SetNull(lul_null) luoverlapped = 0 lstr_secure_attrib.nLength = 12 lstr_secure_attrib.bInheritHandle = 1 lstr_secure_attrib.lpSecurityDescriptor = 0 //lstr_si.cb = 72 lstr_si.cb = 17 *4 //lstr_si.dwFlags = STARTF_USESHOWWINDOW lstr_si.dwFlags = STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES lstr_si.wShowWindow = al_showwindow //ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS ll_creationflags = 0 If CreatePipe(hpiperead, hpipewrite, lstr_secure_attrib, 0) = 0 Then //messageBox("error", "create pipe failed") Return -1 End If lstr_si.hStdOutput = hpipewrite lstr_si.hStdError = hpipewrite lstr_si.hStdInput = hpipewrite // create process/thread and execute the passed program If CreateProcess(ls_null, as_exefullpath, ll_null, ll_null, True, ll_creationflags, ll_null, ls_null, lstr_si, lstr_pi) Then // wait for the process to complete If il_millsecs > 0 Then // wait until process ends or timeout period expires ll_exitcode = WaitForSingleObject(lstr_pi.hProcess, il_millsecs) // terminate process if not finished If ib_terminate And ll_exitcode = WAIT_TIMEOUT Then TerminateProcess(lstr_pi.hProcess, -1) ll_exitcode = WAIT_TIMEOUT Else // check for exit code GetExitCodeProcess(lstr_pi.hProcess, ll_exitcode) End If Else // close hPipeWrite and thread handles CloseHandle(hpipewrite) CloseHandle(lstr_pi.hThread) //redirect out message lbytesread = ReadFile( hpiperead, lbl_read, BUFSIZE,lpipeoutlen, 0) If lbytesread = 0 Then lul_err = GetLastError() If lul_err = 109 Then //messagebox("error reading", "error 109 - broken pipe") Else //messagebox("error reading", string(lul_err)) End If End If ls_message = "" ll_row = 0 ls_tmp = "" Do While lbytesread > 0 And lpipeoutlen > 0 ls_tmp = String(BlobMid(lbl_read,1, lpipeoutlen), encodingANSI!) If ll_row > 0 Then ls_message += ls_tmp End If If ll_row = 0 Then ll_pos = Pos(ls_tmp, "CONNECT_DATA", 1) If ll_pos > 0 Then ll_row ++ End If End If lbytesread = ReadFile( hpiperead, lbl_read, BUFSIZE,lpipeoutlen, 0) Loop is_message = ls_message // wait until process ends WaitForSingleObject(lstr_pi.hProcess, INFINITE) // check for exit code GetExitCodeProcess(lstr_pi.hProcess, ll_exitcode) End If // close process and hPipeRead closeHandle(hpiperead) CloseHandle(lstr_pi.hProcess) //CloseHandle(lstr_pi.hThread) Else // return failure ll_exitcode = -1 End If Return ll_exitcode */ end function public function long of_run (string as_exefullpath, trigevent a_windowstate);//==================================================================== // Function: n_ftpcs.of_run() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_exefullpath // trigevent a_windowstate //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_rtn CHOOSE CASE a_windowstate CASE Hide! // run the passed program ll_rtn = this.of_Run(as_exefullpath, SW_HIDE) //ll_rtn = this.of_Run_hand(as_exefullpath, SW_HIDE) CASE ELSE // valid trigevent but invalid windowstate SetNull(ll_rtn) END CHOOSE Return ll_rtn end function public function long of_run (string as_exefullpath, windowstate a_windowstate);//==================================================================== // Function: n_ftpcs.of_run() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_exefullpath // windowstate a_windowstate //-------------------------------------------------------------------- // Returns: long //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_rtn CHOOSE CASE a_windowstate CASE Normal! ll_rtn = this.of_Run(as_exefullpath, SW_SHOWNORMAL) CASE Maximized! ll_rtn = this.of_Run(as_exefullpath, SW_SHOWMAXIMIZED) CASE Minimized! ll_rtn = this.of_Run(as_exefullpath, SW_SHOWMINIMIZED) END CHOOSE Return ll_rtn end function public function string of_get_shellexecute (string as_filename, string as_shellverb);//==================================================================== // Function: n_ftpcs.of_get_shellexecute() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_filename // string as_shellverb //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_regkey, ls_class, ls_runcmd String ls_regcmd, ls_regcmdex, ls_subkeys[] Integer li_rc, li_pos1, li_pos2 // get file extension classname ls_regkey = "HKEY_CLASSES_ROOT\." + Right(as_filename, 3) RegistryGet(ls_regkey, "", RegString!, ls_class) If ls_class = "" Then MessageBox( "of_Get_ShellExecute Error", & "There is no association for the file type!", StopSign!) Return "" End If // get default shell verb if not given ls_regkey = "HKEY_CLASSES_ROOT\" + ls_class + "\shell" If as_shellverb = "" Then RegistryGet(ls_regkey, "", RegString!, as_shellverb) If as_shellverb = "" Then // get list of verb keys RegistryKeys(ls_regkey, ls_subkeys) If UpperBound(ls_subkeys) = 0 Then MessageBox( "of_Get_ShellExecute Error", & "There are no shell verbs for the file type!", StopSign!) Return "" Else // default to first one as_shellverb = ls_subkeys[1] End If End If End If // get command string for the given shell verb ls_regkey = ls_regkey + "\" + as_shellverb + "\command" li_rc = RegistryGet(ls_regkey, "", RegString!, ls_regcmdex) If li_rc = 1 Then ls_regcmd = Space(500) ExpandEnvironmentStrings(ls_regcmdex, ls_regcmd, 500) Else li_rc = RegistryGet(ls_regkey, "", RegExpandString!, ls_regcmdex) If li_rc = 1 Then ls_regcmd = Space(500) ExpandEnvironmentStrings(ls_regcmdex, ls_regcmd, 500) Else MessageBox( "of_Get_ShellExecute Error", & "The verb is invalid for the file type!", StopSign!) Return "" End If End If // add file name to command string li_pos1 = Pos(ls_regcmd, "%1") If li_pos1 = 0 Then ls_runcmd = ls_regcmd + " ~"" + as_filename + "~"" Else li_pos2 = Pos(ls_regcmd, "~"%1~"") If li_pos2 = 0 Then ls_runcmd = Replace(ls_regcmd, li_pos1, 2, "~"" + as_filename + "~"") Else ls_runcmd = Replace(ls_regcmd, li_pos1, 2, as_filename) End If End If Return ls_runcmd end function public function long of_shellrun (string as_filename, string as_shellverb, long al_showwindow);// ----------------------------------------------------------------------------- // SCRIPT: n_runandwait.of_ShellRun // // PURPOSE: This function starts the program that is defined to perform // the action on the file. It then waits for it to finish. // If a timeout period has been set, it optionally can terminate // the process. // // ARGUMENTS: as_exefullpath - Path of program to execute // as_shellverb - Shell action verb (blank for default) // ai_showwindow - Show window option // // RETURN: Return code of the program or: // -1 = Create Process failed // 258 = Process terminated after timeout // // DATE PROG/ID DESCRIPTION OF CHANGE / REASON // ---------- -------- ----------------------------------------------------- // 07/16/2003 RolandS Initial Coding // ----------------------------------------------------------------------------- CONSTANT Long SEE_MASK_NOCLOSEPROCESS = 64 SHELLEXECUTEINFO lstr_sei Long ll_ExitCode // initialize structure values lstr_sei.cbSize = 60 lstr_sei.fMask = SEE_MASK_NOCLOSEPROCESS lstr_sei.hWnd = Handle(this) lstr_sei.lpVerb = as_shellverb lstr_sei.lpFile = as_filename lstr_sei.nShow = al_showwindow If ShellExecuteEx(lstr_sei) Then // wait for the process to complete If il_millsecs > 0 Then // wait until process ends or timeout period expires ll_ExitCode = WaitForSingleObject(lstr_sei.hProcess, il_millsecs) // terminate process if not finished If ib_terminate And ll_ExitCode = WAIT_TIMEOUT Then TerminateProcess(lstr_sei.hProcess, -1) ll_ExitCode = WAIT_TIMEOUT Else // check for exit code GetExitCodeProcess(lstr_sei.hProcess, ll_ExitCode) End If Else // wait until process ends WaitForSingleObject(lstr_sei.hProcess, INFINITE) // check for exit code GetExitCodeProcess(lstr_sei.hProcess, ll_ExitCode) End If // close process and thread handles CloseHandle(lstr_sei.hProcess) Else // return failure ll_ExitCode = -1 End If Return ll_ExitCode end function public function long of_shellrun (string as_filename, string as_shellverb, trigevent a_windowstate);// ----------------------------------------------------------------------------- // SCRIPT: n_runandwait.of_ShellRun // // PURPOSE: This function takes the Hide! enumerated value and // passes SW_HIDE to the form of the function that // actually does the processing. // // ARGUMENTS: as_exefullpath - Path of program to execute // as_shellverb - Shell action verb (blank for default) // a_windowstate - Show window option // // RETURN: Return code from processing // // DATE PROG/ID DESCRIPTION OF CHANGE / REASON // ---------- -------- ----------------------------------------------------- // 07/16/2003 RolandS Initial Coding // ----------------------------------------------------------------------------- Long ll_rtn CHOOSE CASE a_windowstate CASE Hide! // run the passed file ll_rtn = this.of_ShellRun(as_filename, as_shellverb, SW_HIDE) CASE ELSE // valid trigevent but invalid windowstate SetNull(ll_rtn) END CHOOSE Return ll_rtn end function public function long of_shellrun (string as_filename, string as_shellverb, windowstate a_windowstate);// ----------------------------------------------------------------------------- // SCRIPT: n_runandwait.of_ShellRun // // PURPOSE: This function takes the Normal!, Maximized and // Minimized! enumerated values and passes the // corresponding value to the form of the function // that actually does the processing. // // ARGUMENTS: as_exefullpath - Path of program to execute // as_shellverb - Shell action verb (blank for default) // a_windowstate - Show window option // // RETURN: Return code from processing // // DATE PROG/ID DESCRIPTION OF CHANGE / REASON // ---------- -------- ----------------------------------------------------- // 07/16/2003 RolandS Initial Coding // ----------------------------------------------------------------------------- Long ll_rtn CHOOSE CASE a_windowstate CASE Normal! ll_rtn = this.of_ShellRun(as_filename, as_shellverb, SW_SHOWNORMAL) CASE Maximized! ll_rtn = this.of_ShellRun(as_filename, as_shellverb, SW_SHOWMAXIMIZED) CASE Minimized! ll_rtn = this.of_ShellRun(as_filename, as_shellverb, SW_SHOWMINIMIZED) END CHOOSE Return ll_rtn end function public function integer of_lastpos (string as_str1, string as_str2);//==================================================================== // Function: of_lastpos() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_str1 // string as_str2 //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2018.10.09 //-------------------------------------------------------------------- // Copyright (c) 2018 PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_pos Integer li_rtn If ((((IsNull(as_str1)) Or (IsNull(as_str2))) Or (Trim(as_str1) = "")) Or (Trim(as_str2) = "")) Then Return 0 End If Do li_rtn = li_pos li_pos = Pos(as_str1,as_str2,li_pos + 1) Loop While li_pos > 0 Return li_rtn end function public function string of_getcurfolderfile (string as_path);//==================================================================== // Function: n_ftpcs.of_getcurfolderfile() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_path //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_pos String ls_fullfolder , ls_curfolderfile , ls_curpath li_pos = of_lastpos(as_path,"/") If li_pos > 0 Then ls_fullfolder = Mid(as_path,1,li_pos - 1) else ls_fullfolder = as_path End If li_pos = of_lastpos(ls_fullfolder,"//") If li_pos > 0 Then ls_curfolderfile = Mid(ls_fullfolder,li_pos + 2) Else ls_curfolderfile = ls_fullfolder End If li_pos = pos(ls_curfolderfile,"/") If li_pos > 0 Then ls_curpath = Mid(ls_curfolderfile,li_pos + 1) Else ls_curpath = ls_curfolderfile End If Return ls_curpath end function public function string of_getfilename (string as_path);//==================================================================== // Function: n_ftpcs.of_getfilename() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_path //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_pos li_pos = of_lastpos(as_path,"/") If li_pos > 0 Then Return Mid(as_path,li_pos + 1) Else Return "" End If end function public function string of_getfolder (string as_path);//==================================================================== // Function: of_getfolder() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_path //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/01/16 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_pos String ls_folder li_pos = of_lastpos(as_path,"/") If li_pos > 0 Then ls_folder = Mid(as_path,1,li_pos - 1) End If Return ls_folder end function public function string of_getmodulepath ();//==================================================================== // Function: n_ftpcs.of_getmodulepath() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== string ls_AppPath string ls_FullPath string ls_Exe int li_Ret int li_Pos = 0 ulong lul_handle, lul_length = 1024 ClassDefinition lcd ls_Fullpath = Space (1024) IF handle(getapplication()) = 0 THEN // running from the IDE lcd=getapplication().classdefinition ls_FullPath = lcd.libraryname if len(ls_FullPath) > 0 then li_ret = 1 else li_ret = 0 end if else // running from EXE lul_handle = handle( getapplication() ) ls_fullpath=space(lul_length) li_ret = GetModuleFilename( lul_handle, ls_FullPath, lul_length ) end if if li_Ret > 0 then // ls_AppPath will be something line <drive><full path>\<exe name> // You can then strip off the exe name using: do while (Pos (ls_FullPath, "\", li_Pos + 1) > 0) li_Pos = Pos (ls_FullPath, "\", li_Pos + 1) loop ls_AppPath = Mid (ls_FullPath, 1, li_Pos - 1) ls_Exe = Mid (ls_FullPath, li_Pos + 1) //ls_apppath //ls_fullpath // ls_exe return ls_apppath end if return "" end function public function integer of_readfile_encode (string as_file, ref string as_returnstring);//==================================================================== // Function: n_ftpcs.of_readfile_encode() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_file // ref string as_returnstring //-------------------------------------------------------------------- // Returns: tring //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_FileNum, loops, j Long flen, bytes_read Integer fh, ret Blob b, tot_b,C String ls_string Long ll_rowerror flen = FileLength(as_file) li_FileNum = FileOpen(as_file, StreamMode!, Read!, LockRead!) If li_FileNum < 0 Then //messagebox('thong bao', 'doc file loi ' +as_file) Return 1 End If If flen > 32765 Then If Mod(flen, 32765) = 0 Then loops = flen/32765 Else loops = (flen/32765) + 1 End If Else loops = 1 End If For j = 1 To loops bytes_read = FileRead(li_FileNum, b) tot_b = tot_b + b Next FileClose(li_FileNum) as_returnstring = String(tot_b, EncodingUTF8!) Return 0 end function public function integer of_readfile (string as_file, ref string as_returnstring);//==================================================================== // Function: n_ftpcs.of_readfile() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_file // ref string as_returnstring //-------------------------------------------------------------------- // Returns: tring //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Integer li_loops, li_i Integer li_FileNum Long ll_fLen, ll_bRead, ll_NewPos String ls_tmp, ls_string_file // Get the file length and open the file ll_fLen = FileLength(as_file) li_FileNum = FileOpen(as_file,StreamMode!, Read!, Shared!) If li_FileNum < 0 Then //messagebox('thong bao', 'doc file loi ' +as_file) FileClose(li_FileNum) Return 1 End If // Determine how many times to call FileRead If ll_fLen > 32765 Then If Mod(ll_fLen, 32765) = 0 Then li_loops = ll_fLen/32765 Else li_loops = (ll_fLen/32765) + 1 End If Else li_loops = 1 End If // Read the file ls_tmp = '' ls_string_file = '' ll_NewPos = 1 For li_i = 1 To li_loops ll_bRead = FileRead(li_FileNum, ls_tmp) If ll_bRead < 0 Then //messagebox('thong bao', 'doc file loi ' +as_file) FileClose(li_FileNum) Return 1 End If ls_string_file = ls_string_file + ls_tmp Next FileClose(li_FileNum) as_returnstring = ls_string_file Return 0 end function public subroutine of_parse (string as_parse, string as_list, ref string as_array[]);//==================================================================== // Function: n_ftpcs.of_parse() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_parse // string as_list // ref string as_array[] //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_pos, ll_cnt, ll_start String ls_empty[] Integer li_next as_array = ls_empty as_list = Trim(as_list) If Right(as_list, 1) <> as_parse Then as_list = as_list + as_parse End If ll_start = 1 ll_pos = Pos(as_list, as_parse, ll_start) do while ll_pos > 1 li_next = UpperBound(as_array) + 1 as_array[li_next] = Mid(as_list, ll_start, (ll_pos - ll_start)) ll_start = ll_pos + 1 ll_pos = Pos(as_list, as_parse, ll_start) loop end subroutine public subroutine of_createlocalfolders (string as_filename);//==================================================================== // Function: n_ftpcs.of_createlocalfolders() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_filename //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_parts[], ls_path Integer li_idx, li_max of_Parse("\", as_filename, ls_parts) li_max = UpperBound(ls_parts) - 1 For li_idx = 1 To li_max If li_idx > 1 Then ls_path += "\" End If ls_path += ls_parts[li_idx] If Not DirectoryExists(ls_path) Then CreateDirectory(ls_path) End If Next end subroutine public function string of_replaceall (string as_oldstring, string as_findstr, string as_replace);//==================================================================== // Function: n_ftpcs.of_replaceall() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // string as_oldstring // string as_findstr // string as_replace //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/12/14 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_newstring Long ll_findstr, ll_replace, ll_pos // get length of strings ll_findstr = Len(as_findstr) ll_replace = Len(as_replace) // find first occurrence ls_newstring = as_oldstring ll_pos = Pos(ls_newstring, as_findstr) Do While ll_pos > 0 // replace old with new ls_newstring = Replace(ls_newstring, ll_pos, ll_findstr, as_replace) // find next occurrence ll_pos = Pos(ls_newstring, as_findstr, (ll_pos + ll_replace)) Loop Return ls_newstring end function private function long of_run_hand (string as_exefullpath, long al_showwindow);// ----------------------------------------------------------------------------- // SCRIPT: n_runandwait.of_Run // // PURPOSE: This function starts the process and waits for it to // finish. If a timeout period has been set, it // optionally can terminate the process. // // ARGUMENTS: as_exefullpath - Path of program to execute // ai_showwindow - Show window option // // RETURN: Return code of the program or: // -1 = Create Process failed // 258 = Process terminated after timeout // // DATE PROG/ID DESCRIPTION OF CHANGE / REASON // ---------- -------- ----------------------------------------------------- // 07/16/2003 RolandS Initial Coding // ----------------------------------------------------------------------------- /* STARTUPINFO lstr_si PROCESS_INFORMATION lstr_pi Long ll_null, ll_CreationFlags, ll_ExitCode, ll_msecs String ls_null Long ll_loop Long ll_hWnd ULong lul_hProcess, lul_hThread Long al_hwnd // initialize arguments SetNull(ll_null) SetNull(ls_null) //lstr_si.cb = 72 //lstr_si.dwFlags = STARTF_USESHOWWINDOW //lstr_si.wShowWindow = al_showwindow //ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS // initialize arguments lstr_si.cb = 68 lstr_si.dwFlags = STARTF_USESHOWWINDOW lstr_si.wShowWindow = SW_HIDE ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS // create process/thread and execute the passed program If CreateProcess(ls_null, as_exefullpath, ll_null, & ll_null, False, ll_CreationFlags, ll_null, & ls_null, lstr_si, lstr_pi) Then // close process and thread handles CloseHandle(lstr_pi.hProcess) CloseHandle(lstr_pi.hThread) // find the external program's main window For ll_loop = 1 To 100 // wait 10 milliseconds SleepMS(10) // walk through all open windows ll_hWnd = GetWindow(GetDesktopWindow(), GW_CHILD) Do Until ll_hWnd = 0 // get the thread/process that owns the window lul_hThread = GetWindowThreadProcessId(ll_hWnd, lul_hProcess) If lul_hProcess = lstr_pi.dwProcessId Then // make sure it is a main window If GetWindow(ll_hWnd, GW_OWNER) = 0 Then Open(w_hand_progress) al_hwnd = Handle(w_hand_progress) //is_commandline = as_commandline SetParent(ll_hWnd, al_hwnd) SetWindowLong(ll_hWnd, GWL_STYLE, WS_POPUP) ShowWindow(ll_hWnd, SW_NORMAL) of_Resize(w_hand_progress.WorkspaceWidth() , w_hand_progress.WorkspaceHeight()) exit End If End If ll_hWnd = GetWindow(ll_hWnd, GW_HWNDNEXT) Loop Next // wait until process ends WaitForSingleObject(lul_hProcess, INFINITE) // check for exit code GetExitCodeProcess(lul_hProcess, ll_ExitCode) // // wait until process ends // WaitForSingleObject(lstr_pi.hProcess, INFINITE) // // check for exit code // GetExitCodeProcess(lstr_pi.hProcess, ll_ExitCode) If ll_hWnd > 0 Then Send(ll_hWnd, WM_CLOSE, 0, 0) End If close(w_hand_progress) Else // return failure ll_ExitCode = -1 End If Return ll_ExitCode */ return 1 end function public subroutine of_resize (integer newwidth, integer newheight);// Resize the attached window Long ll_width, ll_height If il_hWnd > 0 Then ll_width = UnitsToPixels(newwidth, XUnitsToPixels!) ll_height = UnitsToPixels(newheight, YUnitsToPixels!) MoveWindow(il_hWnd, 0, 0, ll_width, ll_height, True) End If end subroutine private function long of_getmbcp (boolean ab_utf8);//returns multibyte charset for internal use for WidechartoMultibyte and vice-versa long CP_ACP=0 // long CP_UTF8=65001 long CP_THREAD_ACP=3 if ab_utf8 then return CP_UTF8 return il_ansi_cp //return CP_THREAD_ACP end function public function long of_string2mb (boolean ab_utf8, string src, ref blob dst);//returns the length of the blob in bytes long len long cp cp=of_getMbCP(ab_utf8) len=WideCharToMultiByte( cp,0,src,-1, dst,0,0,0) dst=blob(space(len+1),EncodingANSI!) //+1 because PB removes zerochar at the end of string :( WideCharToMultiByte( cp,0,src,-1, dst,len+1,0,0) return len end function public function boolean of_writetext_utf8 (string filename, string text, encoding e, ref string as_error);int f long i blob b if e=EncodingANSI! then //for ansi use winapi convert, because PB uses system instead of user conversation f=FileOpen(filename, StreamMode!, Write!, LockWrite!, Replace!) elseif e=EncodingUTF8! then //for utf8 avoid adding BOM! //required by isql??? f=FileOpen(filename, StreamMode!, Write!, LockWrite!, Replace!) else f=FileOpen(filename, TextMode!, Write!, LockWrite!, Replace!,e) end if if f=-1 then as_error = "Can't create the file~r~n~""+filename+'"' return false end if if e=EncodingANSI! then //i=gn_unicode.of_string2mb( /*boolean ab_utf8*/ false, text, b) i= of_string2mb(true, text, b) i=len(text) i=FileWriteEx(f, b ,i) elseif e=EncodingUTF8! then //for utf8 avoid adding BOM! //required by isql??? i=FileWriteEx(f, blob(text,EncodingUTF8!) ) else i=FileWriteEx(f, text) end if FileClose(f) return true end function public function string of_getappname ();//==================================================================== // Function: n_inboundfunsys.of_getappname() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/11/21 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_AppPath String ls_FullPath String ls_Exe Int li_Ret Int li_Pos = 0 ULong lul_handle, lul_length = 1024 ClassDefinition lcd ls_FullPath = Space (1024) If Handle(GetApplication()) = 0 Then // running from the IDE lcd = GetApplication().ClassDefinition ls_FullPath = lcd.LibraryName If Len(ls_FullPath) > 0 Then li_Ret = 1 Else li_Ret = 0 End If Else // running from EXE lul_handle = Handle( GetApplication() ) ls_FullPath = Space(lul_length) li_Ret = GetModuleFilename( lul_handle, ls_FullPath, lul_length ) End If If li_Ret > 0 Then // ls_AppPath will be something line <drive><full path>\<exe name> // You can then strip off the exe name using: Do While (Pos (ls_FullPath, "\", li_Pos + 1) > 0) li_Pos = Pos (ls_FullPath, "\", li_Pos + 1) Loop ls_AppPath = Mid (ls_FullPath, 1, li_Pos - 1) ls_Exe = Mid (ls_FullPath, li_Pos + 1) //ls_apppath //ls_fullpath // ls_exe Return ls_Exe End If Return "" end function public function string of_getappname_notextention ();String ls_exe Int li_Pos ls_exe = of_getappname() li_Pos = Pos (ls_exe, ".", 1) ls_exe = Mid(ls_exe, 1 ,li_Pos - 1) Return ls_exe end function public function string of_getsysdir ();//==================================================================== // Function: n_inboundfunsys.of_getsysdir() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/11/21 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Constant Long CSIDL_PERSONAL = 5 // current user My Documents Constant Long CSIDL_APPDATA = 26 // current user Application Data Constant Long CSIDL_LOCAL_APPDATA = 28 // local settings Application Data Constant Long CSIDL_COMMON_DOCUMENTS = 46 // all users My Documents Constant Long CSIDL_COMMON_APPDATA = 35 // all users Application Data String ls_path ULong lul_handle, lul_rc, lul_hToken ls_path = Space(256) lul_handle = Handle(This) SetNull(lul_hToken) lul_rc = SHGetFolderPath(lul_handle, CSIDL_LOCAL_APPDATA, lul_hToken, 0, ls_path) Return ls_path // path end function public function string of_getappdirtemp ();//==================================================================== // Function: n_inboundfunsys.of_getappdirtemp() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/11/21 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_dirsys ls_dirsys = of_getsysdir() + "\" + of_getappname_notextention() If Not DirectoryExists ( ls_dirsys ) Then CreateDirectory (ls_dirsys ) End If Return ls_dirsys end function public subroutine of_cleardirtemp (string as_remark);//==================================================================== // Function: n_inboundfunsys.of_cleardirtemp() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_remark //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2019/11/21 //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_sysdir, ls_filename Int li_items , li_i ls_sysdir = of_getsysdir() + "\" + of_getappname_notextention() If Not (IsNull(as_remark) Or Len(Trim(as_remark)) = 0) Then ls_sysdir += "\" + as_remark End If window lw_tmp listbox llb_tmp Open( lw_tmp ) lw_tmp.Visible = False lw_tmp.OpenUserObject( llb_tmp ) llb_tmp.DirList(ls_sysdir,0) li_items = llb_tmp.TotalItems() For li_i = 1 To li_items ls_filename = llb_tmp.Text( li_i ) If FileExists ( ls_sysdir + '\' + ls_filename ) Then FileDelete ( ls_sysdir + '\' + ls_filename ) Next lw_tmp.CloseUserObject( llb_tmp ) Close( lw_tmp ) end subroutine public subroutine of_cleardirtemp ();of_cleardirtemp("") end subroutine public function integer of_parse (string as_string, ref string as_array[], ref integer ai_count, string as_delimiter);//==================================================================== // Function: nov_runjobs.of_parse() //-------------------------------------------------------------------- // Description: Takes a string and separates elements into an array //-------------------------------------------------------------------- // Arguments: // value string as_string Source string containing values delimited by as_delimiter // reference string as_array[] Destination array, passed by value // reference integer ai_count Returns count of items in array // value string as_delimiter delimiter value //-------------------------------------------------------------------- // Returns: integer 0 = success 1 = error //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2023/07/24 //-------------------------------------------------------------------- // Usage: nov_runjobs.of_parse ( string as_string, ref string as_array[], ref integer ai_count, string as_delimiter ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Int li_pos // position of commas Int li_len // string parsing Int li_start // string parsing String ls_item // single item parsed from string If Len( as_string ) < 1 Then ai_count = 0 Return 1 End If // parse out items and insert into array li_pos = 1 li_start = 1 ai_count = 0 Do While li_pos > 0 li_pos = Pos ( as_string, as_delimiter, li_start ) If li_pos = 0 Then ls_item = Mid ( as_string, li_start ) Else ls_item = Mid ( as_string, li_start, li_pos - li_start ) End If ls_item = Trim ( ls_item ) If Len ( ls_item ) > 0 Then ai_count++ as_array[ai_count] = ls_item End If li_start = li_pos + 1 Loop Return 0 end function public function integer of_printing (string as_filepdf, string as_printername);If IsNull(is_printexe) Or Len(Trim(is_printexe)) = 0 Then is_message = "printexe is null " Return -1 End If If Not FileExists(is_printexe) Then is_message = "printexe Is Not Exists " + is_printexe Return -1 End If If Not FileExists(as_filepdf) Then is_message = "file PDF Is Not Exists " + is_printexe Return -1 End If String ls_execute If IsNull(as_printername) Or Len(Trim(as_printername)) = 0 Then ls_execute = '"' + is_printexe + '" "' + as_filepdf +'"' Else ls_execute = '"' + is_printexe + '" "' + as_filepdf + '" "' + as_printername + '"' End If Long ll_rc ll_rc = of_run(ls_execute, Hide!) Choose Case ll_rc Case 1 //OK Return ll_rc Case -1 Return -1 Case Else Return -1 End Choose Return ll_rc end function public function string of_getprinterdefalut ();String ls_name , ls_fullstring Long ll_place ls_fullstring = PrintGetPrinter() ll_place = Pos (ls_fullstring, "~t") ls_name = Left(ls_fullstring, ll_place -1) Return ls_name end function public function integer of_getprinterlist (ref string as_printer_name[]);String ls_prntrs String ls_printer[] Int li_cnt, li_rtn, li_i Long ll_pos ls_prntrs = PrintGetPrinters ( ) li_rtn = of_parse(ls_prntrs,ls_printer, li_cnt, "~n") If li_rtn = -1 Then Return 0 For li_i = 1 To UpperBound(ls_printer) ll_pos = Pos (ls_printer[li_i], "~t") as_printer_name[UpperBound(as_printer_name) + 1] = Left(ls_printer[li_i], ll_pos -1) Next Return UpperBound(as_printer_name) end function on nov_runprinter.create call super::create TriggerEvent( this, "constructor" ) end on on nov_runprinter.destroy TriggerEvent( this, "destructor" ) call super::destroy end on event constructor;is_printexe = of_getmodulepath( ) + "\printer.exe" end event |
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
forward global type w_main from window end type type lb_file from listbox within w_main end type type cb_1 from commandbutton within w_main end type type lb_printer from listbox within w_main end type end forward global type w_main from window integer width = 2203 integer height = 1672 boolean titlebar = true string title = "Printing" boolean controlmenu = true boolean minbox = true boolean maxbox = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true lb_file lb_file cb_1 cb_1 lb_printer lb_printer end type global w_main w_main type variables nov_runprinter invo_printer end variables on w_main.create this.lb_file=create lb_file this.cb_1=create cb_1 this.lb_printer=create lb_printer this.Control[]={this.lb_file,& this.cb_1,& this.lb_printer} end on on w_main.destroy destroy(this.lb_file) destroy(this.cb_1) destroy(this.lb_printer) end on event open; String ls_printer_name[] Int li_i, li_rtn li_rtn = invo_printer.of_getprinterlist(ls_printer_name) For li_i = 1 To UpperBound(ls_printer_name) lb_printer.InsertItem ( ls_printer_name[li_i], li_i) Next If lb_printer.TotalItems( ) > 0 Then String ls_name ls_name = invo_printer.of_getprinterdefalut() lb_printer.SelectItem( ls_name, 1) End If String ls_path ls_path = invo_printer.of_getmodulepath( ) lb_file.AddItem(ls_path + "\cust1.pdf") lb_file.AddItem(ls_path + "\cust2.pdf") end event type lb_file from listbox within w_main integer x = 73 integer y = 768 integer width = 2048 integer height = 736 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type cb_1 from commandbutton within w_main integer x = 73 integer y = 608 integer width = 402 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Printing" end type event clicked;Int li_i String ls_printer, ls_pdf ls_printer = lb_printer.Text(lb_printer.SelectedIndex( )) For li_i = 1 To lb_file.TotalItems( ) ls_pdf = lb_file.Text(li_i) invo_printer.of_printing( ls_pdf, ls_printer) Next end event type lb_printer from listbox within w_main integer x = 73 integer y = 32 integer width = 2048 integer height = 544 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 boolean sorted = false borderstyle borderstyle = stylelowered! end type |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments