delphi公共函数 UMyPubFuncFroc--版权所有 (C) 2008 勇者工作室
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 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 | {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 勇者工作室 } { } {*******************************************************} unit UMyPubFuncFroc; interface uses ComCtrls, Forms, Windows, Classes, SysUtils, ComObj, ActiveX, ShlObj, Messages, Graphics, Registry, Dialogs, Controls, uProcess, uCpuUsage, StrUtils, CommCtrl, jpeg, WinInet, ShellAPI, SHFolder, ADODB, WinSock; { 保存日志文件 } procedure YzWriteLogFile(Msg: String ); { 延时函数,单位为毫秒 } procedure YzDelayTime(MSecs: Longint ); { 判断字符串是否为数字 } function YzStrIsNum(Str: string ): boolean ; { 判断文件是否正在使用 } function YzIsFileInUse(fName: string ): boolean ; { 删除字符串列表中的空字符串 } procedure YzDelEmptyChar(AList: TStringList); { 删除文件列表中的"Thumbs.db"文件 } procedure YzDelThumbsFile(AList: TStrings); { 返回一个整数指定位数的带"0"字符串 } function YzIntToZeroStr(Value, ALength: Integer ): string ; { 取日期年份分量 } function YzGetYear(Date: TDate): Integer ; { 取日期月份分量 } function YzGetMonth(Date: TDate): Integer ; { 取日期天数分量 } function YzGetDay(Date: TDate): Integer ; { 取时间小时分量 } function YzGetHour(Time: TTime): Integer ; { 取时间分钟分量 } function YzGetMinute(Time: TTime): Integer ; { 取时间秒钟分量 } function YzGetSecond(Time: TTime): Integer ; { 返回时间分量字符串 } function YzGetTimeStr(ATime: TTime;AFlag: string ): string ; { 返回日期时间字符串 } function YzGetDateTimeStr(ATime: TTime;ADate: TDate): string ; { 获取计算机名称 } function YzGetComputerName(): string ; { 通过窗体子串查找窗体 } procedure YzFindSpecWindow(ASubTitle: string ); { 判断进程CPU占用率 } procedure YzJudgeCPU(ProcessName: string ;CPUUsage: Single ); { 分割字符串 } procedure YzSeparateTerms(Source: string ;Separator: Char ;Terms: TStringList); { 切换页面控件的活动页面 } procedure YzGotoNewPage(AOwerPage: TPageControl;ANewPage: TTabSheet); { 设置页面控件标签的可见性 } procedure YzSetTableVisible(PageControl: TPageControl;ShowFlag: Boolean ); { 根据产品名称获取产品编号 } function YzGetLevelCode(AName: string ;ProductList: TStringList): string ; { 取文件的主文件名 } function YzGetMainFileName(AFileName: string ): string ; { 按下一个键 } procedure YzPressOneKey(AByteCode: Byte );overload; { 按下一个指定次数的键 } procedure YzPressOneKey(AByteCode: Byte ;ATimes: Integer );overload; { 按下二个键 } procedure YzPressTwoKeys(AFirstByteCode, ASecByteCode: Byte ); { 按下三个键 } procedure YzPressThreeKeys(AFirstByteCode, ASecByteCode, AThirdByteCode: Byte ); { 创建桌面快捷方式 } procedure YzCreateShortCut( const sPath: string ; sShortCutName: WideString ); { 删除桌面快捷方式 } procedure YzDeleteShortCut(sShortCutName: WideString ); { 通过光标位置进行鼠标左键单击 } procedure YzMouseLeftClick(X, Y: Integer );overload; { 鼠标左键双击 } procedure YzMouseDoubleClick(X, Y: Integer ); { 通过窗口句柄进行鼠标左键单击 } procedure YzMouseLeftClick(lpClassName, lpWindowName: PAnsiChar );overload; { 通过光标位置查找窗口句柄 } function YzWindowFromPoint(X, Y: Integer ): THandle; { 等待窗口在指定时间后出现 } function YzWaitWindowExist(lpClassName, lpWindowName: PAnsiChar ; ASecond: Integer = 0 ): THandle;overload; { 通光标位置,窗口类名与标题查找窗口是否存在 } function YzWaitWindowExist(X, Y: Integer ;AClassName, AWinName: string ; ASecond: Integer = 0 ):THandle; overload; { 等待指定窗口消失 } procedure YzWaitWindowClose(lpClassName, lpWindowName: PAnsiChar ; ASecond: Integer = 0 ); { 通过窗口句柄设置文本框控件文本 } procedure YzSetEditText(lpClassName, lpWindowName: PAnsiChar ; AText: string );overload; { 通过光标位置设置文本框控件文本 } procedure YzSetEditText(X, Y: Integer ;AText: string );overload; { 获取Window操作系统语言 } function YzGetWindowsLanguageStr: String ; { 清空动态数组 } procedure YzDynArraySetZero( var A); { 动态设置屏幕分辨率 } function YzDynamicResolution(X, Y: WORD ): Boolean ; { 检测系统屏幕分辨率 } function YzCheckDisplayInfo(X, Y: Integer ): Boolean ; type TFontedControl = class (TControl) public property Font; end ; TFontMapping = record SWidth : Integer ; SHeight: Integer ; FName: string ; FSize: Integer ; end ; procedure YzFixForm(AForm: TForm); procedure YzSetFontMapping; {--------------------------------------------------- 以下是关于获取系统软件卸载的信息的类型声明和函数 ----------------------------------------------------} type TUninstallInfo = array of record RegProgramName: string ; ProgramName : string ; UninstallPath : string ; Publisher : string ; PublisherURL : string ; Version : string ; HelpLink : string ; UpdateInfoURL : string ; RegCompany : string ; RegOwner : string ; end ; { GetUninstallInfo 返回系统软件卸载的信息 } function YzGetUninstallInfo : TUninstallInfo; { 检测Java安装信息 } function YzCheckJavaInfo(AUninstallInfo: TUninstallInfo;CheckJava6 : Boolean = False ): Boolean ; { 窗口自适应屏幕大小 } procedure YzAdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer ); { 设置窗口为当前窗体 } procedure YzBringMyAppToFront(AppHandle: THandle); { 获取文件夹大小 } function YzGetDirSize(Dir: string ;SubDir: Boolean ): LongInt ; { 获取文件夹文件数量 } function YzGetDirFiles(Dir: string ;SubDir: Boolean ): LongInt ; { 获取文件大小(KB) } function YzGetFileSize( const FileName: String ): LongInt ; { 获取文件大小(字节) } function YzGetFileSize_Byte( const FileName: String ): LongInt ; { 算术舍入法的四舍五入取整函数 } function YzRoundEx ( const Value: Real ): LongInt ; { 弹出选择目录对话框 } function YzSelectDir( const iMode: integer ; const sInfo: string ): string ; { 获取指定路径下文件夹的个数 } procedure YzListFolders( const Path: String ; const ShowPath: Boolean ; var List: TStrings); { 禁用窗器控件的所有子控件 } procedure YzSetSubCtlState(AOwer: TWinControl;AState: Boolean ); { 模拟键盘按键操作(处理字节码) } procedure YzFKeyent(byteCard: byte ); overload; { 模拟键盘按键操作(处理字符串 } procedure YzFKeyent(strCard: string ); overload; { 锁定窗口位置 } procedure YzLockWindow(ClassName,WinName: PChar ;poX,poY: Integer ); { 注册一个DLL形式或OCX形式的OLE/COM控件 参数strOleFileName为一个DLL或OCX文件名, 参数OleAction表示注册操作类型,1表示注册,0表示卸载 返回值True表示操作执行成功,False表示操作执行失败 } function YzRegisterOleFile (strOleFileName: STRING ;OleAction: Byte ): BOOLEAN ; function YzListViewColumnCount(mHandle: THandle): Integer ; function YzGetListViewText(mHandle: THandle; mStrings: TStrings): Boolean ; { 删除目录树 } function YzDeleteDirectoryTree(Path: string ): boolean ; { Jpg格式转换为bmp格式 } function JpgToBmp(Jpg: TJpegImage): TBitmap; { 设置程序自启动函数 } function YzSetAutoRun(AFilePath: string ;AFlag: Boolean ): boolean ; { 检测URL地址是否有效 } function YzCheckUrl(url: string ): Boolean ; { 获取程序可执行文件名 } function YzGetExeFName: string ; { 目录浏览对话框函数 } function YzBrowseFolder(AOwer: TWinControl;ATitle: string ): string ; { 重启计算机 } function YzShutDownSystem(AFlag: Integer ):BOOL; { 程序运行后删除自身 } procedure YzDeleteSelf; { 程序重启 } procedure YzAppRestart; { 压缩Access数据库 } function YzCompactAccessDB( const AFileName, APassWord: string ): Boolean ; { 标题:获取其他进程中TreeView的文本 } function YzTreeNodeGetNext(mHandle: THandle; mTreeItem: HTreeItem): HTreeItem; function YzTreeNodeGetLevel(mHandle: THandle; mTreeItem: HTreeItem): Integer ; function YzGetTreeViewText(mHandle: THandle; mStrings: TStrings): Boolean ; { 获取本地Application Data目录路径 } function YzLocalAppDataPath : string ; { 获取Windows当前登录的用户名 } function YzGetWindwosUserName: String ; {枚举托盘图标 } function YzEnumTrayNotifyWnd(AFindList: TStringList;ADestStr: string ): BOOL; { 获取SQL Server用户数据库列表 } procedure YzGetSQLServerDBList(ADBHostIP, ALoginPwd: string ;ADBList: TStringList); { 读取据库中所有的表 } procedure YzGetTableList(ConncetStr: string ;ATableList: TStringList); { 将域名解释成IP地址 } function YzDomainToIP(HostName: string ): string ; { 等待进程结束 } procedure YzWaitProcessExit(AProcessName: string ); { 移去系统托盘失效图标 } procedure YzRemoveDeadIcons(); { 转移程序占用内存至虚拟内存 } procedure YzClearMemory; { 检测允许试用的天数是否已到期 } function YzCheckTrialDays(AllowDays: Integer ): Boolean ; { 指定长度的随机小写字符串函数 } function YzRandomStr(aLength: Longint ): string ; var FontMapping : array of TFontMapping; implementation uses uMain; { 保存日志文件 } procedure YzWriteLogFile(Msg: String ); var FileStream: TFileStream; LogFile : String ; begin try { 每天一个日志文件 } Msg := '[' + DateTimeToStr(Now)+ '] ' + Msg; LogFile := ExtractFilePath(Application . ExeName) + '/Logs/' + DateToStr(Now) + '.log' ; if not DirectoryExists(ExtractFilePath(LogFile)) then CreateDir(ExtractFilePath(LogFile)); if FileExists(LogFile) then FileStream := TFileStream . Create(LogFile, fmOpenWrite or fmShareDenyNone) else FileStream:=TFileStream . Create(LogFile,fmCreate or fmShareDenyNone); FileStream . Position:=FileStream . Size; Msg := Msg + # 13 # 10 ; FileStream . Write ( PChar (Msg)^, Length(Msg)); FileStream . Free; except end ; end ; { 延时函数,单位为毫秒 } procedure YZDelayTime(MSecs: Longint ); var FirstTickCount, Now: Longint ; begin FirstTickCount := GetTickCount(); repeat Application . ProcessMessages; Now := GetTickCount(); until (Now - FirstTickCount>=MSecs) or (Now < FirstTickCount); end ; { 判断字符串是否为数字 } function YzStrIsNum(Str: string ): boolean ; var I: integer ; begin if Str = '' then begin Result := False ; Exit; end ; for I:= 1 to length(str) do if not (Str[I] in [ '0' .. '9' ]) then begin Result := False ; Exit; end ; Result := True ; end ; { 判断文件是否正在使用 } function YzIsFileInUse(fName: string ): boolean ; var HFileRes: HFILE; begin Result := false ; if not FileExists(fName) then exit; HFileRes := CreateFile( pchar (fName), GENERIC_READ or GENERIC_WRITE, 0 , nil , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); end ; { 删除字符串列表中的空字符串 } procedure YzDelEmptyChar(AList: TStringList); var I: Integer ; TmpList: TStringList; begin TmpList := TStringList . Create; for I := 0 to AList . Count - 1 do if AList . Strings[I] <> '' then TmpList . Add(AList . Strings[I]); AList . Clear; AList . Text := TmpList . Text; TmpList . Free; end ; { 删除文件列表中的"Thumbs.db"文件 } procedure YzDelThumbsFile(AList: TStrings); var I: Integer ; TmpList: TStringList; begin TmpList := TStringList . Create; for I := 0 to AList . Count - 1 do if ExtractFileName(AList . Strings[I]) <> 'Thumbs.db' then TmpList . Add(AList . Strings[I]); AList . Clear; AList . Text := TmpList . Text; TmpList . Free; end ; {------------------------------------------------------------- 功能: 返回一个整数指定位数的带"0"字符串 参数: Value:要转换的整数 ALength:字符串长度 返回值: string --------------------------------------------------------------} function YzIntToZeroStr(Value, ALength: Integer ): string ; var I, ACount: Integer ; begin Result := '' ; ACount := Length(IntToStr(Value)); if ACount >= ALength then Result := IntToStr(Value) else begin for I := 1 to ALength-ACount do Result := Result + '0' ; Result := Result + IntToStr(Value) end ; end ; { 取日期年份分量 } function YzGetYear(Date: TDate): Integer ; var y, m, d: WORD ; begin DecodeDate(Date, y, m, d); Result := y; end ; { 取日期月份分量 } function YzGetMonth(Date: TDate): Integer ; var y, m, d: WORD ; begin DecodeDate(Date, y, m, d); Result := m; end ; { 取日期天数分量 } function YzGetDay(Date: TDate): Integer ; var y, m, d: WORD ; begin DecodeDate(Date, y, m, d); Result := d; end ; { 取时间小时分量 } function YzGetHour(Time: TTime): Integer ; var h, m, s, ms: WORD ; begin DecodeTime(Time, h, m, s, ms); Result := h; end ; { 取时间分钟分量 } function YzGetMinute(Time: TTime): Integer ; var h, m, s, ms: WORD ; begin DecodeTime(Time, h, m, s, ms); Result := m; end ; { 取时间秒钟分量 } function YzGetSecond(Time: TTime): Integer ; var h, m, s, ms: WORD ; begin DecodeTime(Time, h, m, s, ms); Result := s; end ; { 返回时间分量字符串 } function YzGetTimeStr(ATime: TTime;AFlag: string ): string ; var wTimeStr: string ; FH, FM, FS, FMS: WORD ; const HOURTYPE = 'Hour' ; MINUTETYPE = 'Minute' ; SECONDTYPE = 'Second' ; MSECONDTYPE = 'MSecond' ; begin wTimeStr := TimeToStr(ATime); if Pos( '上午' , wTimeStr) <> 0 then wTimeStr := Copy(wTimeStr, Pos( '上午' , wTimeStr) + 4 , 10 ) else if Pos( '下午' , wTimeStr) <> 0 then wTimeStr := Copy(wTimeStr, Pos( '下午' , wTimeStr) + 4 , 10 ); DecodeTime(ATime, FH, FM, FS, FMS); if AFlag = HOURTYPE then begin { 如果是12小时制则下午的小时分量加12 } if Pos( '下午' , wTimeStr) <> 0 then Result := YzIntToZeroStr(FH + 12 , 2 ) else Result := YzIntToZeroStr(FH, 2 ); end ; if AFlag = MINUTETYPE then Result := YzIntToZeroStr(FM, 2 ); if AFlag = SECONDTYPE then Result := YzIntToZeroStr(FS, 2 ); if AFlag = MSECONDTYPE then Result := YzIntToZeroStr(FMS, 2 ); end ; { 返回日期时间字符串 } function YzGetDateTimeStr(ATime: TTime;ADate: TDate): string ; var wYear, wMonth, wDay: string ; wHour, wMinute, wSecond: string ; begin wYear := RightStr(YzIntToZeroStr(YzGetYear(ADate), 4 ), 2 ); wMonth := YzIntToZeroStr(YzGetMonth(ADate), 2 ); wDay := YzIntToZeroStr(YzGetDay(ADate), 2 ); wHour := YzGetTimeStr(ATime, 'Hour' ); wMinute := YzGetTimeStr(ATime, 'Minute' ); wSecond := YzGetTimeStr(ATime, 'Second' ); Result := wYear + wMonth + wDay + wHour + wMinute + wSecond; end ; { 通过窗体子串查找窗体 } procedure YzFindSpecWindow(ASubTitle: string ); function EnumWndProc(AWnd: THandle;AWinName: string ): Boolean ;stdcall; var WindowText: array [ 0..255 ] of Char ; WindowStr: string ; begin GetWindowText(AWnd, WindowText, 255 ); WindowStr := StrPas(WindowText); WindowStr := COPY(WindowStr, 1 , StrLen( PChar (AWinName))); if CompareText(AWinName, WindowStr) = 0 then begin SetForegroundWindow(AWnd); Result := False ; Exit; end ; Result := True ; end ; begin EnumWindows(@EnumWndProc, LongInt (@ASubTitle)); YzDelayTime( 1000 ); end ; { 获取计算机名称 } function YzGetComputerName(): string ; var pcComputer: PChar ; dwCSize: DWORD; begin dwCSize := MAX_COMPUTERNAME_LENGTH + 1 ; Result := '' ; GetMem(pcComputer, dwCSize); try if Windows . GetComputerName(pcComputer, dwCSize) then Result := pcComputer; finally FreeMem(pcComputer); end ; end ; { 判断进程CPU占用率 } procedure YzJudgeCPU(ProcessName: string ;CPUUsage: Single ); var cnt: PCPUUsageData; usage: Single ; begin cnt := wsCreateUsageCounter(FindProcess(ProcessName)); while True do begin usage := wsGetCpuUsage(cnt); if usage <= CPUUsage then begin wsDestroyUsageCounter(cnt); YzDelayTime( 2000 ); Break; end ; YzDelayTime( 10 ); Application . ProcessMessages; end ; end ; { 分割字符串 } procedure YzSeparateTerms(Source: string ;Separator: Char ;Terms: TStringList); var TmpStr: string ; PO: integer ; begin Terms . Clear; if Length(Source) = 0 then Exit; { 长度为0则退出 } PO := Pos(Separator, Source); if PO = 0 then begin Terms . Add(Source); Exit; end ; while PO <> 0 do begin TmpStr := Copy(Source, 1 , PO - 1 ); { 复制字符 } Terms . Add(TmpStr); { 添加到列表 } Delete(Source, 1 , PO); { 删除字符和分割符 } PO := Pos(Separator, Source); { 查找分割符 } end ; if Length(Source) > 0 then Terms . Add(Source); { 添加剩下的条目 } end ; { 切换页面控件的活动页面 } procedure YzGotoNewPage(AOwerPage: TPageControl;ANewPage: TTabSheet); begin if AOwerPage . ActivePage <> ANewPage then AOwerPage . ActivePage := ANewPage; end ; { 设置页面控件标签的可见性 } procedure YzSetTableVisible(PageControl: TPageControl;ShowFlag: Boolean ); var I: Integer ; begin for I := 0 to PageControl . PageCount - 1 do PageControl . Pages[I].TabVisible := ShowFlag; end ; { 根据产品名称获取产品编号 } function YZGetLevelCode(AName: string ;ProductList: TStringList): string ; var I: Integer ; TmpStr: string ; begin Result := '' ; if ProductList . Count <= 0 then Exit; for I := 0 to ProductList . Count- 1 do begin TmpStr := ProductList . Strings[I]; if AName = Copy(TmpStr, 1 , Pos( '_' , TmpStr)- 1 ) then begin Result := Copy(TmpStr, Pos( '_' , TmpStr)+ 1 , 10 ); Break; end ; end ; end ; { 取文件的主文件名 } function YzGetMainFileName(AFileName: string ): string ; var TmpStr: string ; begin if AFileName = '' then Exit; TmpStr := ExtractFileName(AFileName); Result := Copy(TmpStr, 1 , Pos( '.' , TmpStr) - 1 ); end ; { 按下一个键 } procedure YzPressOneKey(AByteCode: Byte ); begin keybd_event(AByteCode, 0 , 0 , 0 ); YzDelayTime( 100 ); keybd_event(AByteCode, 0 , KEYEVENTF_KEYUP, 0 ); YzDelayTime( 400 ); end ; { 按下一个指定次数的键 } procedure YzPressOneKey(AByteCode: Byte ;ATimes: Integer );overload; var I: Integer ; begin for I := 1 to ATimes do begin keybd_event(AByteCode, 0 , 0 , 0 ); YzDelayTime( 10 ); keybd_event(AByteCode, 0 , KEYEVENTF_KEYUP, 0 ); YzDelayTime( 150 ); end ; end ; { 按下二个键 } procedure YzPressTwoKeys(AFirstByteCode, ASecByteCode: Byte ); begin keybd_event(AFirstByteCode, 0 , 0 , 0 ); keybd_event(ASecByteCode, 0 , 0 , 0 ); YzDelayTime( 100 ); keybd_event(ASecByteCode, 0 , KEYEVENTF_KEYUP, 0 ); keybd_event(AFirstByteCode, 0 , KEYEVENTF_KEYUP, 0 ); YzDelayTime( 400 ); end ; { 按下三个键 } procedure YzPressThreeKeys(AFirstByteCode, ASecByteCode, AThirdByteCode: Byte ); begin keybd_event(AFirstByteCode, 0 , 0 , 0 ); keybd_event(ASecByteCode, 0 , 0 , 0 ); keybd_event(AThirdByteCode, 0 , 0 , 0 ); YzDelayTime( 100 ); keybd_event(AThirdByteCode, 0 , KEYEVENTF_KEYUP, 0 ); keybd_event(ASecByteCode, 0 , KEYEVENTF_KEYUP, 0 ); keybd_event(AFirstByteCode, 0 , KEYEVENTF_KEYUP, 0 ); YzDelayTime( 400 ); end ; { 创建桌面快捷方式 } procedure YzCreateShortCut( const sPath: string ; sShortCutName: WideString ); var tmpObject: IUnknown; tmpSLink: IShellLink; tmpPFile: IPersistFile; PIDL: PItemIDList; StartupDirectory: array [ 0.. MAX_PATH] of Char ; StartupFilename: String ; LinkFilename: WideString ; begin StartupFilename := sPath; tmpObject := CreateComObject(CLSID_ShellLink); { 创建建立快捷方式的外壳扩展 } tmpSLink := tmpObject as IShellLink; { 取得接口 } tmpPFile := tmpObject as IPersistFile; { 用来储存*.lnk文件的接口 } tmpSLink . SetPath( pChar (StartupFilename)); { 设定notepad.exe所在路径 } tmpSLink . SetWorkingDirectory( pChar (ExtractFilePath(StartupFilename))); {设定工作目录 } SHGetSpecialFolderLocation( 0 , CSIDL_DESKTOPDIRECTORY, PIDL); { 获得桌面的Itemidlist } SHGetPathFromIDList(PIDL, StartupDirectory); { 获得桌面路径 } sShortCutName := '/' + sShortCutName + '.lnk' ; LinkFilename := StartupDirectory + sShortCutName; tmpPFile . Save(pWChar(LinkFilename), FALSE ); { 保存*.lnk文件 } end ; { 删除桌面快捷方式 } procedure YzDeleteShortCut(sShortCutName: WideString ); var PIDL : PItemIDList; StartupDirectory: array [ 0.. MAX_PATH] of Char ; LinkFilename: WideString ; begin SHGetSpecialFolderLocation( 0 ,CSIDL_DESKTOPDIRECTORY,PIDL); SHGetPathFromIDList(PIDL,StartupDirectory); LinkFilename := StrPas(StartupDirectory) + '/' + sShortCutName + '.lnk' ; DeleteFile(LinkFilename); end ; { 通过光标位置进行鼠标左键单击 } procedure YzMouseLeftClick(X, Y: Integer ); begin SetCursorPos(X, Y); YzDelayTime( 100 ); mouse_event(MOUSEEVENTF_LEFTDOWN, 0 , 0 , 0 , 0 ); mouse_event(MOUSEEVENTF_LEFTUP, 0 , 0 , 0 , 0 ); YzDelayTime( 400 ); end ; { 鼠标左键双击 } procedure YzMouseDoubleClick(X, Y: Integer ); begin SetCursorPos(X, Y); YzDelayTime( 100 ); mouse_event(MOUSEEVENTF_LEFTDOWN, 0 , 0 , 0 , 0 ); mouse_event(MOUSEEVENTF_LEFTUP, 0 , 0 , 0 , 0 ); YzDelayTime( 100 ); mouse_event(MOUSEEVENTF_LEFTDOWN, 0 , 0 , 0 , 0 ); mouse_event(MOUSEEVENTF_LEFTUP, 0 , 0 , 0 , 0 ); YzDelayTime( 400 ); end ; { 通过窗口句柄进行鼠标左键单击 } procedure YzMouseLeftClick(lpClassName, lpWindowName: PAnsiChar );overload; var AHandel: THandle; begin AHandel := FindWindow(lpClassName, lpWindowName); SendMessage(AHandel, WM_LBUTTONDOWN, 0 , 0 ); SendMessage(AHandel, WM_LBUTTONUP, 0 , 0 ); YzDelayTime( 500 ); end ; { 等待进程结束 } procedure YzWaitProcessExit(AProcessName: string ); begin while True do begin KillByPID(FindProcess(AProcessName)); if FindProcess(AProcessName) = 0 then Break; YzDelayTime( 10 ); Application . ProcessMessages; end ; end ; {------------------------------------------------------------- 功 能: 等待窗口在指定时间后出现 参 数: lpClassName: 窗口类名 lpWindowName: 窗口标题 ASecond: 要等待的时间,"0"代表永久等待 返回值: 无 备 注: 如果指定的等待时间未到窗口已出现则立即退出 --------------------------------------------------------------} function YzWaitWindowExist(lpClassName, lpWindowName: PAnsiChar ; ASecond: Integer = 0 ): THandle;overload; var StartTickCount, PassTickCount: LongWord ; begin Result := 0 ; { 永久等待 } if ASecond = 0 then begin while True do begin Result := FindWindow(lpClassName, lpWindowName); if Result <> 0 then Break; YzDelayTime( 10 ); Application . ProcessMessages; end ; end else { 等待指定时间 } begin StartTickCount := GetTickCount; while True do begin Result := FindWindow(lpClassName, lpWindowName); { 窗口已出现则立即退出 } if Result <> 0 then Break else begin PassTickCount := GetTickCount; { 等待时间已到则退出 } if (PassTickCount - StartTickCount) div 1000 >= ASecond then Break; end ; YzDelayTime( 10 ); Application . ProcessMessages; end ; end ; YzDelayTime( 1000 ); end ; { 等待指定窗口消失 } procedure YzWaitWindowClose(lpClassName, lpWindowName: PAnsiChar ; ASecond: Integer = 0 ); var StartTickCount, PassTickCount: LongWord ; begin if ASecond = 0 then begin while True do begin if FindWindow(lpClassName, lpWindowName) = 0 then Break; YzDelayTime( 10 ); Application . ProcessMessages; end end else begin StartTickCount := GetTickCount; while True do begin { 窗口已关闭则立即退出 } if FindWindow(lpClassName, lpWindowName)= 0 then Break else begin PassTickCount := GetTickCount; { 等待时间已到则退出 } if (PassTickCount - StartTickCount) div 1000 >= ASecond then Break; end ; YzDelayTime( 10 ); Application . ProcessMessages; end ; end ; YzDelayTime( 500 ); end ; { 通过光标位置查找窗口句柄 } function YzWindowFromPoint(X, Y: Integer ): THandle; var MousePoint: TPoint; CurWindow: THandle; hRect: TRect; Canvas: TCanvas; begin MousePoint . X := X; MousePoint . Y := Y; CurWindow := WindowFromPoint(MousePoint); GetWindowRect(Curwindow, hRect); if Curwindow <> 0 then begin Canvas := TCanvas . Create; Canvas . Handle := GetWindowDC(Curwindow); Canvas . Pen . Width := 2 ; Canvas . Pen . Color := clRed; Canvas . Pen . Mode := pmNotXor; Canvas . Brush . Style := bsClear; Canvas . Rectangle( 0 , 0 , hRect . Right-hRect . Left, hRect . Bottom-hRect . Top); Canvas . Free; end ; Result := CurWindow; end ; { 通光标位置,窗口类名与标题查找窗口是否存在 } function YzWaitWindowExist(X, Y: Integer ;AClassName, AWinName: string ; ASecond: Integer ):THandle;overload; var MousePo: TPoint; CurWindow: THandle; bufClassName: array [ 0.. MAXBYTE- 1 ] of Char ; bufWinName: array [ 0.. MAXBYTE- 1 ] of Char ; StartTickCount, PassTickCount: LongWord ; begin Result := 0 ; { 永久等待 } if ASecond = 0 then begin while True do begin MousePo . X := X; MousePo . Y := Y; CurWindow := WindowFromPoint(MousePo); GetClassName(CurWindow, bufClassName, MAXBYTE); GetWindowText(CurWindow, bufWinname, MAXBYTE); if (CompareText(StrPas(bufClassName), AClassName) = 0 ) and (CompareText(StrPas(bufWinName), AWinName) = 0 ) then begin Result := CurWindow; Break; end ; YzDelayTime( 10 ); Application . ProcessMessages; end ; end else { 等待指定时间 } begin StartTickCount := GetTickCount; while True do begin { 窗口已出现则立即退出 } MousePo . X := X; MousePo . Y := Y; CurWindow := WindowFromPoint(MousePo); GetClassName(CurWindow, bufClassName, MAXBYTE); GetWindowText(CurWindow, bufWinname, MAXBYTE); if (CompareText(StrPas(bufClassName), AClassName) = 0 ) and (CompareText(StrPas(bufWinName), AWinName) = 0 ) then begin Result := CurWindow; Break; end else begin PassTickCount := GetTickCount; { 等待时间已到则退出 } if (PassTickCount - StartTickCount) div 1000 >= ASecond then Break; end ; YzDelayTime( 10 ); Application . ProcessMessages; end ; end ; YzDelayTime( 1000 ); end ; { 通过窗口句柄设置文本框控件文本 } procedure YzSetEditText(lpClassName, lpWindowName: PAnsiChar ; AText: string );overload; var CurWindow: THandle; begin CurWindow := FindWindow(lpClassName, lpWindowName); SendMessage(CurWindow ,WM_SETTEXT, 0 , Integer ( PChar (AText))); YzDelayTime( 500 ); end ; { 通过光标位置设置文本框控件文本 } procedure YzSetEditText(X, Y: Integer ;AText: string );overload; var CurWindow: THandle; begin CurWindow := YzWindowFromPoint(X, Y); SendMessage(CurWindow, WM_SETTEXT, 0 , Integer ( PChar (AText))); YzMouseLeftClick(X, Y); end ; { 获取Window操作系统语言 } function YzGetWindowsLanguageStr: String ; var WinLanguage: array [ 0..50 ] of char ; begin VerLanguageName(GetSystemDefaultLangID, WinLanguage, 50 ); Result := StrPas(WinLanguage); end ; procedure YzDynArraySetZero( var A); var P: PLongint; { 4个字节 } begin P := PLongint(A); { 指向 A 的地址 } Dec(P); { P地址偏移量是 sizeof(A),指向了数组长度 } P^ := 0 ; { 数组长度清空 } Dec(P); { 指向数组引用计数 } P^ := 0 ; { 数组计数清空 } end ; { 动态设置分辨率 } function YzDynamicResolution(x, y: WORD ): Boolean ; var lpDevMode: TDeviceMode; begin Result := EnumDisplaySettings( nil , 0 , lpDevMode); if Result then begin lpDevMode . dmFields := DM_PELSWIDTH or DM_PELSHEIGHT; lpDevMode . dmPelsWidth := x; lpDevMode . dmPelsHeight := y; Result := ChangeDisplaySettings(lpDevMode, 0 ) = DISP_CHANGE_SUCCESSFUL; end ; end ; procedure YzSetFontMapping; begin SetLength(FontMapping, 3 ); { 800 x 600 } FontMapping[ 0 ].SWidth := 800 ; FontMapping[ 0 ].SHeight := 600 ; FontMapping[ 0 ].FName := '宋体' ; FontMapping[ 0 ].FSize := 7 ; { 1024 x 768 } FontMapping[ 1 ].SWidth := 1024 ; FontMapping[ 1 ].SHeight := 768 ; FontMapping[ 1 ].FName := '宋体' ; FontMapping[ 1 ].FSize := 9 ; { 1280 x 1024 } FontMapping[ 2 ].SWidth := 1280 ; FontMapping[ 2 ].SHeight := 1024 ; FontMapping[ 2 ].FName := '宋体' ; FontMapping[ 2 ].FSize := 11 ; end ; { 程序窗体及控件自适应分辨率(有问题) } procedure YzFixForm(AForm: TForm); var I, J: integer ; T: TControl; begin with AForm do begin for I := 0 to ComponentCount - 1 do begin try T := TControl(Components[I]); T . left := Trunc(T . left * (Screen . width / 1024 )); T . top := Trunc(T . Top * (Screen . Height / 768 )); T . Width := Trunc(T . Width * (Screen . Width / 1024 )); T . Height := Trunc(T . Height * (Screen . Height / 768 )); except end ; { try } end ; { for I } for I:= 0 to Length(FontMapping) - 1 do begin if (Screen . Width = FontMapping[I].SWidth) and (Screen . Height = FontMapping[I].SHeight) then begin for J := 0 to ComponentCount - 1 do begin try TFontedControl(Components[J]).Font . Name := FontMapping[I].FName; TFontedControl(Components[J]).FONT . Size := FontMapping[I].FSize; except end ; { try } end ; { for J } end ; { if } end ; { for I } end ; { with } end ; { 检测系统屏幕分辨率 } function YzCheckDisplayInfo(X, Y: Integer ): Boolean ; begin Result := True ; if (Screen . Width <> X) and (Screen . Height <> Y) then begin if MessageBox(Application . Handle, PChar ( '系统检测到您的屏幕分辨率不是 ' + IntToStr(X) + '×' + IntToStr(Y) + ',这将影响到系统的正常运行,' + '是否要自动调整屏幕分辨率?' ), '提示' , MB_YESNO + MB_ICONQUESTION + MB_TOPMOST) = 6 then YzDynamicResolution( 1024 , 768 ) else Result := False ; end ; end ; function YzGetUninstallInfo: TUninstallInfo; const Key = '/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/' ; var S : TStrings; I : Integer ; J : Integer ; begin with TRegistry . Create do begin S := TStringlist . Create; J := 0 ; try RootKey:= HKEY_LOCAL_MACHINE; OpenKeyReadOnly(Key); GetKeyNames(S); Setlength(Result, S . Count); for I:= 0 to S . Count - 1 do begin If OpenKeyReadOnly(Key + S[I]) then If ValueExists( 'DisplayName' ) and ValueExists( 'UninstallString' ) then begin Result[J].RegProgramName:= S[I]; Result[J].ProgramName:= ReadString( 'DisplayName' ); Result[J].UninstallPath:= ReadString( 'UninstallString' ); If ValueExists( 'Publisher' ) then Result[J].Publisher:= ReadString( 'Publisher' ); If ValueExists( 'URLInfoAbout' ) then Result[J].PublisherURL:= ReadString( 'URLInfoAbout' ); If ValueExists( 'DisplayVersion' ) then Result[J].Version:= ReadString( 'DisplayVersion' ); If ValueExists( 'HelpLink' ) then Result[J].HelpLink:= ReadString( 'HelpLink' ); If ValueExists( 'URLUpdateInfo' ) then Result[J].UpdateInfoURL:= ReadString( 'URLUpdateInfo' ); If ValueExists( 'RegCompany' ) then Result[J].RegCompany:= ReadString( 'RegCompany' ); If ValueExists( 'RegOwner' ) then Result[J].RegOwner:= ReadString( 'RegOwner' ); Inc(J); end ; end ; finally Free; S . Free; SetLength(Result, J); end ; end ; end ; { 检测Java安装信息 } function YzCheckJavaInfo(AUninstallInfo: TUninstallInfo;CheckJava6 : Boolean = False ): Boolean ; var I: Integer ; Java6Exist: Boolean ; AUninstall: TUninstallInfo; AProgramList: TStringList; AJavaVersion, AFilePath: string ; begin Result := True ; Java6Exist := False ; AJavaVersion := 'J2SE Runtime Environment 5.0 Update 14' ; AUninstall := YzGetUninstallInfo; AProgramList := TStringList . Create; for I := Low(AUninstall) to High(AUninstall) do begin if Pos( 'J2SE' , AUninstall[I].ProgramName) <> 0 then AProgramList . Add(AUninstall[I].ProgramName); if Pos( 'Java(TM)' , AUninstall[I].ProgramName) <> 0 then Java6Exist := True ; end ; if Java6Exist then begin if CheckJava6 then begin MessageBox(Application . Handle, '系统检测到您机器上安装了Java6以上的版本,' + '如果影响到系统的正常运行请先将其卸载再重新启动系统!' , '提示' , MB_OK + MB_ICONINFORMATION + MB_TOPMOST); Result := False ; end ; end else if AProgramList . Count = 0 then begin MessageBox(Application . Handle, '系统检测到您机器上没有安装Java运行环境,' + '请点击 "确定" 安装Java运行环境后再重新运行程序!' , '提示' , MB_OK + MB_ICONINFORMATION + MB_TOPMOST); AFilePath := ExtractFilePath(ParamStr( 0 )) + 'java' + '/' + 'jre-1_5_0_14-windows-i586-p.exe' ; if FileExists(AFilePath) then WinExec( PChar (AFilePath), SW_SHOWNORMAL) else MessageBox(Application . Handle, '找不到Java安装文件,请您手动安装!' , '提示' , MB_OK + MB_ICONINFORMATION + MB_TOPMOST); Result := False ; end ; AProgramList . Free; end ; {------------------------------------------------------------- 功能: 窗口自适应屏幕大小 参数: Form: 需要调整的Form OrgWidth:开发时屏幕的宽度 OrgHeight:开发时屏幕的高度 --------------------------------------------------------------} procedure YzAdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer ); begin with Form do begin if (Screen . width <> OrgWidth) then begin Scaled := True ; Height := longint (Height) * longint (Screen . height) div OrgHeight; Width := longint (Width) * longint (Screen . Width) div OrgWidth; ScaleBy(Screen . Width, OrgWidth); end ; end ; end ; { 设置窗口为当前窗体 } procedure YzBringMyAppToFront(AppHandle: THandle); var Th1, Th2: Cardinal ; begin Th1 := GetCurrentThreadId; Th2 := GetWindowThreadProcessId(GetForegroundWindow, NIL ); AttachThreadInput(Th2, Th1, TRUE ); try SetForegroundWindow(AppHandle); finally AttachThreadInput(Th2, Th1, TRUE ); end ; end ; { 获取文件夹文件数量 } function YzGetDirFiles(Dir: string ;SubDir: Boolean ): LongInt ; var SearchRec: TSearchRec; Founded: integer ; begin Result := 0 ; if Dir[length(Dir)] <> '/' then Dir := Dir + '/' ; Founded := FindFirst(Dir + '*.*' , faAnyFile, SearchRec); while Founded = 0 do begin Inc(Result); if (SearchRec . Attr and faDirectory > 0 ) and (SearchRec . Name[ 1 ] <> '.' ) and (SubDir = True ) then Inc(Result, YzGetDirFiles(Dir + SearchRec . Name, True )); Founded := FindNext(SearchRec); end ; FindClose(SearchRec); end ; { 算术舍入法的四舍五入取整函数 } function YzRoundEx ( const Value: Real ): LongInt ; var x: Real ; begin x := Value - Trunc(Value); if x >= 0.5 then Result := Trunc(Value) + 1 else Result := Trunc(Value); end ; { 获取文件大小(KB) } function YzGetFileSize( const FileName: String ): LongInt ; var SearchRec: TSearchRec; begin if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then Result := SearchRec . Size else Result := - 1 ; Result := YzRoundEx(Result / 1024 ); end ; { 获取文件大小(字节) } function YzGetFileSize_Byte( const FileName: String ): LongInt ; var SearchRec: TSearchRec; begin if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then Result := SearchRec . Size else Result := - 1 ; end ; { 获取文件夹大小 } function YzGetDirSize(Dir: string ;SubDir: Boolean ): LongInt ; var SearchRec: TSearchRec; Founded: integer ; begin Result := 0 ; if Dir[length(Dir)] <> '/' then Dir := Dir + '/' ; Founded := FindFirst(Dir + '*.*' , faAnyFile, SearchRec); while Founded = 0 do begin Inc(Result, SearchRec . size); if (SearchRec . Attr and faDirectory > 0 ) and (SearchRec . Name[ 1 ] <> '.' ) and (SubDir = True ) then Inc(Result, YzGetDirSize(Dir + SearchRec . Name, True )); Founded := FindNext(SearchRec); end ; FindClose(SearchRec); Result := YzRoundEx(Result / 1024 ); end ; {------------------------------------------------------------- 功能: 弹出选择目录对话框 参数: const iMode: 选择模式 const sInfo: 对话框提示信息 返回值: 如果取消取返回为空,否则返回选中的路径 --------------------------------------------------------------} function YzSelectDir( const iMode: integer ; const sInfo: string ): string ; var Info: TBrowseInfo; IDList: pItemIDList; Buffer: PChar ; begin Result:= '' ; Buffer := StrAlloc(MAX_PATH); with Info do begin hwndOwner := application . mainform . Handle; { 目录对话框所属的窗口句柄 } pidlRoot := nil ; { 起始位置,缺省为我的电脑 } pszDisplayName := Buffer; { 用于存放选择目录的指针 } lpszTitle := PChar (sInfo); { 此处表示显示目录和文件,如果只显示目录则将后一个去掉即可 } if iMode = 1 then ulFlags := BIF_RETURNONLYFSDIRS or BIF_BROWSEINCLUDEFILES else ulFlags := BIF_RETURNONLYFSDIRS; lpfn := nil ; { 指定回调函数指针 } lParam := 0 ; { 传递给回调函数参数 } IDList := SHBrowseForFolder(Info); { 读取目录信息 } end ; if IDList <> nil then begin SHGetPathFromIDList(IDList, Buffer); { 将目录信息转化为路径字符串 } Result := strpas(Buffer); end ; StrDispose(buffer); end ; { 获取指定路径下文件夹的个数 } procedure YzListFolders( const Path: String ; const ShowPath: Boolean ; var List: TStrings); var SRec: TSearchRec; begin if not Assigned(List) then List:= TStringList . Create; FindFirst(Path + '*.*' , faDirectory, SRec); if ShowPath then List . Add(Path + SRec . Name) else List . Add(SRec . Name); while FindNext(SRec) = 0 do if ShowPath then List . Add(Path + SRec . Name) else List . Add(SRec . Name); FindClose(SRec); end ; { 禁用窗器控件的所有子控件 } procedure YzSetSubCtlState(AOwer: TWinControl;AState: Boolean ); var I: Integer ; begin for I := 0 to AOwer . ControlCount - 1 do AOwer . Controls[I].Enabled := AState; end ; { 模拟键盘按键操作(处理字节码) } procedure YzFKeyent(byteCard: byte ); var vkkey: integer ; begin vkkey := VkKeyScan(chr(byteCard)); if (chr(byteCard) in [ 'A' .. 'Z' ]) then begin keybd_event(VK_SHIFT, 0 , 0 , 0 ); keybd_event( byte (byteCard), 0 , 0 , 0 ); keybd_event(VK_SHIFT, 0 , 2 , 0 ); end else if chr(byteCard) in [ '!' , '@' , '#' , '$' , '%' , '^' , '&' , '*' , '(' , ')' , '_' , '+' , '|' , '{' , '}' , ':' , '"' , '<' , '>' , '?' , '~' ] then begin keybd_event(VK_SHIFT, 0 , 0 , 0 ); keybd_event( byte (vkkey), 0 , 0 , 0 ); keybd_event(VK_SHIFT, 0 , 2 , 0 ); end else { if byteCard in [8,13,27,32] } begin keybd_event( byte (vkkey), 0 , 0 , 0 ); end ; end ; { 模拟键盘按键(处理字符) } procedure YzFKeyent(strCard: string ); var str: string ; strLength: integer ; I: integer ; byteSend: byte ; begin str := strCard; strLength := length(str); for I := 1 to strLength do begin byteSend := byte (str[I]); YzFKeyent(byteSend); end ; end ; { 锁定窗口位置 } procedure YzLockWindow(ClassName,WinName: PChar ;poX,poY: Integer ); var CurWindow: THandle; _wndRect: TRect; begin CurWindow := 0 ; while True do begin CurWindow := FindWindow(ClassName,WinName); if CurWindow <> 0 then Break; YzDelayTime( 10 ); Application . ProcessMessages; end ; GetWindowRect(CurWindow,_wndRect); if ( _wndRect . Left <> poX) or ( _wndRect . Top <> poY) then begin MoveWindow(CurWindow, poX, poY, (_wndRect . Right-_wndRect . Left), (_wndRect . Bottom-_wndRect . Top), TRUE ); end ; YzDelayTime( 1000 ); end ; { 注册一个DLL形式或OCX形式的OLE/COM控件 参数strOleFileName为一个DLL或OCX文件名, 参数OleAction表示注册操作类型,1表示注册,0表示卸载 返回值True表示操作执行成功,False表示操作执行失败 } function YzRegisterOleFile (strOleFileName: STRING ;OleAction: Byte ): BOOLEAN ; const RegisterOle = 1 ; { 注册 } UnRegisterOle = 0 ; { 卸载 } type TOleRegisterFunction = function : HResult; { 注册或卸载函数的原型 } var hLibraryHandle: THandle; { 由LoadLibrary返回的DLL或OCX句柄 } hFunctionAddress: TFarProc; { DLL或OCX中的函数句柄,由GetProcAddress返回 } RegFunction: TOleRegisterFunction; { 注册或卸载函数指针 } begin Result := FALSE ; { 打开OLE/DCOM文件,返回的DLL或OCX句柄 } hLibraryHandle := LoadLibrary( PCHAR (strOleFileName)); if (hLibraryHandle > 0 ) then { DLL或OCX句柄正确 } try { 返回注册或卸载函数的指针 } if (OleAction = RegisterOle) then { 返回注册函数的指针 } hFunctionAddress := GetProcAddress(hLibraryHandle, pchar ( 'DllRegisterServer' )) { 返回卸载函数的指针 } else hFunctionAddress := GetProcAddress(hLibraryHandle, pchar ( 'DllUnregisterServer' )); if (hFunctionAddress <> NIL ) then { 注册或卸载函数存在 } begin { 获取操作函数的指针 } RegFunction := TOleRegisterFunction(hFunctionAddress); { 执行注册或卸载操作,返回值>=0表示执行成功 } if RegFunction >= 0 then Result := true ; end ; finally { 关闭已打开的OLE/DCOM文件 } FreeLibrary(hLibraryHandle); end ; end ; function YzListViewColumnCount(mHandle: THandle): Integer ; begin Result := Header_GetItemCount(ListView_GetHeader(mHandle)); end ; { ListViewColumnCount } function YzGetListViewText(mHandle: THandle; mStrings: TStrings): Boolean ; var vColumnCount: Integer ; vItemCount: Integer ; I, J: Integer ; vBuffer: array [ 0..255 ] of Char ; vProcessId: DWORD; vProcess: THandle; vPointer: Pointer ; vNumberOfBytesRead: Cardinal ; S: string ; vItem: TLVItem; begin Result := False ; if not Assigned(mStrings) then Exit; vColumnCount := YzListViewColumnCount(mHandle); if vColumnCount <= 0 then Exit; vItemCount := ListView_GetItemCount(mHandle); GetWindowThreadProcessId(mHandle, @vProcessId); vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False , vProcessId); vPointer := VirtualAllocEx(vProcess, nil , 4096 , MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); mStrings . BeginUpdate; try mStrings . Clear; for I := 0 to vItemCount - 1 do begin S := '' ; for J := 0 to vColumnCount - 1 do begin with vItem do begin mask := LVIF_TEXT; iItem := I; iSubItem := J; cchTextMax := SizeOf(vBuffer); pszText := Pointer ( Cardinal (vPointer) + SizeOf(TLVItem)); end ; WriteProcessMemory(vProcess, vPointer, @vItem, SizeOf(TLVItem), vNumberOfBytesRead); SendMessage(mHandle, LVM_GETITEM, I, lparam(vPointer)); ReadProcessMemory(vProcess, Pointer ( Cardinal (vPointer) + SizeOf(TLVItem)), @vBuffer[ 0 ], SizeOf(vBuffer), vNumberOfBytesRead); S := S + # 9 + vBuffer; end ; Delete(S, 1 , 1 ); mStrings . Add(S); end ; finally VirtualFreeEx(vProcess, vPointer, 0 , MEM_RELEASE); CloseHandle(vProcess); mStrings . EndUpdate; end ; Result := True ; end ; { GetListViewText } { 删除目录树 } function YzDeleteDirectoryTree(Path: string ): boolean ; var SearchRec: TSearchRec; SFI: string ; begin Result := False ; if (Path = '' ) or ( not DirectoryExists(Path)) then exit; if Path[length(Path)] <> '/' then Path := Path + '/' ; SFI := Path + '*.*' ; if FindFirst(SFI, faAnyFile, SearchRec) = 0 then begin repeat begin if (SearchRec . Name = '.' ) or (SearchRec . Name = '..' ) then Continue; if (SearchRec . Attr and faDirectory <> 0 ) then begin if not YzDeleteDirectoryTree(Path + SearchRec . name) then Result := FALSE ; end else begin FileSetAttr(Path + SearchRec . Name, 128 ); DeleteFile(Path + SearchRec . Name); end ; end until FindNext(SearchRec) <> 0 ; FindClose(SearchRec); end ; FileSetAttr(Path, 0 ); if RemoveDir(Path) then Result := TRUE else Result := FALSE ; end ; { Jpg格式转换为bmp格式 } function JpgToBmp(Jpg: TJpegImage): TBitmap; begin Result := nil ; if Assigned(Jpg) then begin Result := TBitmap . Create; Jpg . DIBNeeded; Result . Assign(Jpg); end ; end ; { 设置程序自启动函数 } function YzSetAutoRun(AFilePath: string ;AFlag: Boolean ): boolean ; var AMainFName: string ; Reg: TRegistry; begin Result := true ; AMainFName := YzGetMainFileName(AFilePath); Reg := TRegistry . Create; Reg . RootKey := HKEY_LOCAL_MACHINE; try Reg . OpenKey( 'SOFTWARE/Microsoft/Windows/CurrentVersion/Run' , True ); if AFlag = False then { 取消自启动 } Reg . DeleteValue(AMainFName) else { 设置自启动 } Reg . WriteString(AMainFName, '"' + AFilePath + '"' ) except Result := False ; end ; Reg . CloseKey; Reg . Free; end ; { 检测URL地址是否有效 } function YzCheckUrl(url: string ): Boolean ; var hSession, hfile, hRequest: HINTERNET; dwindex, dwcodelen: dword; dwcode: array [ 1..20 ] of Char ; res: PChar ; begin Result := False ; try if Pos( 'http://' ,LowerCase(url)) = 0 then url := 'http://' + url; { Open an internet session } hSession:=InternetOpen( 'InetURL:/1.0' ,INTERNET_OPEN_TYPE_PRECONFIG, nil , nil , 0 ); if Assigned(hsession) then begin hfile := InternetOpenUrl(hsession, PChar (url), nil , 0 ,INTERNET_FLAG_RELOAD, 0 ); dwIndex := 0 ; dwCodeLen := 10 ; HttpQueryInfo(hfile,HTTP_QUERY_STATUS_CODE,@dwcode,dwcodeLen,dwIndex); res := PChar (@dwcode); Result := (res = '200' ) or (res = '302' ); if Assigned(hfile) then InternetCloseHandle(hfile); InternetCloseHandle(hsession); end ; except end ; end ; { 获取程序可执行文件名 } function YzGetExeFName: string ; begin Result := ExtractFileName(Application . ExeName); end ; { 目录浏览对话框函数 } function YzBrowseFolder(AOwer: TWinControl;ATitle: string ): string ; var Info: TBrowseInfo; Dir: array [ 0..260 ] of char ; ItemId: PItemIDList; begin with Info do begin hwndOwner := AOwer . Handle; pidlRoot := nil ; pszDisplayName := nil ; lpszTitle := PChar (ATitle); ulFlags := 0 ; lpfn := nil ; lParam := 0 ; iImage := 0 ; end ; ItemId := SHBrowseForFolder(Info); SHGetPathFromIDList(ItemId,@Dir); Result := string (Dir); end ; { 重启计算机 } function YzShutDownSystem(AFlag: Integer ):BOOL; var hProcess,hAccessToken: THandle; LUID_AND_ATTRIBUTES: TLUIDAndAttributes; TOKEN_PRIVILEGES: TTokenPrivileges; BufferIsNull: DWORD; Const SE_SHUTDOWN_NAME= 'SeShutdownPrivilege' ; begin hProcess:=GetCurrentProcess(); OpenProcessToken(hprocess, TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY, hAccessToken); LookupPrivilegeValue( Nil , SE_SHUTDOWN_NAME, LUID_AND_ATTRIBUTES . Luid); LUID_AND_ATTRIBUTES . Attributes := SE_PRIVILEGE_ENABLED; TOKEN_PRIVILEGES . PrivilegeCount := 1 ; TOKEN_PRIVILEGES . Privileges[ 0 ] := LUID_AND_ATTRIBUTES; BufferIsNull := 0 ; AdjustTokenPrivileges(hAccessToken, False , TOKEN_PRIVILEGES, sizeof( TOKEN_PRIVILEGES) , Nil , BufferIsNull); Result := ExitWindowsEx(AFlag, 0 ); end ; { 程序运行后删除自身 } procedure YzDeleteSelf; var hModule: THandle; buff: array [ 0..255 ] of Char ; hKernel32: THandle; pExitProcess, pDeleteFileA, pUnmapViewOfFile: Pointer ; begin hModule := GetModuleHandle( nil ); GetModuleFileName(hModule, buff, sizeof(buff)); CloseHandle(THandle( 4 )); hKernel32 := GetModuleHandle( 'KERNEL32' ); pExitProcess := GetProcAddress(hKernel32, 'ExitProcess' ); pDeleteFileA := GetProcAddress(hKernel32, 'DeleteFileA' ); pUnmapViewOfFile := GetProcAddress(hKernel32, 'UnmapViewOfFile' ); asm LEA EAX, buff PUSH 0 PUSH 0 PUSH EAX PUSH pExitProcess PUSH hModule PUSH pDeleteFileA PUSH pUnmapViewOfFile RET end ; end ; { 程序重启 } procedure YzAppRestart; var AppName : PChar ; begin AppName := PChar (Application . ExeName) ; ShellExecute(Application . Handle, 'open' , AppName, nil , nil , SW_SHOWNORMAL); KillByPID(GetCurrentProcessId); end ; { 压缩Access数据库 } function YzCompactAccessDB( const AFileName, APassWord: string ): Boolean ; var SPath, FConStr, TmpConStr: string ; SFile: array [ 0..254 ] of Char ; STempFileName: string ; JE: OleVariant; function GetTempDir: string ; var Buffer: array [ 0.. MAX_PATH] of Char ; begin ZeroMemory(@Buffer, MAX_PATH); GetTempPath(MAX_PATH, Buffer); Result := IncludeTrailingBackslash(StrPas(Buffer)); end ; begin Result := False ; SPath := GetTempDir; { 取得Windows的Temp路径 } { 取得Temp文件名,Windows将自动建立0字节文件 } GetTempFileName( PChar (SPath), '~ACP' , 0 , SFile); STempFileName := SFile; { 删除Windows建立的0字节文件 } if not DeleteFile(STempFileName) then Exit; try JE := CreateOleObject( 'JRO.JetEngine' ); { 压缩数据库 } FConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source=' + AFileName + ';Jet OLEDB:DataBase PassWord=' + APassWord; TmpConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source=' + STempFileName + ';Jet OLEDB:DataBase PassWord=' + APassWord; JE . CompactDatabase(FConStr, TmpConStr); { 覆盖源数据库文件 } Result := CopyFile( PChar (STempFileName), PChar (AFileName), False ); { 删除临时文件 } DeleteFile(STempFileName); except Application . MessageBox( '压缩数据库失败!' , '提示' , MB_OK + MB_ICONINFORMATION); end ; end ; { 标题:获取其他进程中TreeView的文本 } function YzTreeNodeGetNext(mHandle: THandle; mTreeItem: HTreeItem): HTreeItem; var vParentID: HTreeItem; begin Result := nil ; if (mHandle <> 0 ) and (mTreeItem <> nil ) then begin Result := TreeView_GetChild(mHandle, mTreeItem); if Result = nil then Result := TreeView_GetNextSibling(mHandle, mTreeItem); vParentID := mTreeItem; while (Result = nil ) and (vParentID <> nil ) do begin vParentID := TreeView_GetParent(mHandle, vParentID); Result := TreeView_GetNextSibling(mHandle, vParentID); end ; end ; end ; { TreeNodeGetNext } function YzTreeNodeGetLevel(mHandle: THandle; mTreeItem: HTreeItem): Integer ; var vParentID: HTreeItem; begin Result := - 1 ; if (mHandle <> 0 ) and (mTreeItem <> nil ) then begin vParentID := mTreeItem; repeat Inc(Result); vParentID := TreeView_GetParent(mHandle, vParentID); until vParentID = nil ; end ; end ; { TreeNodeGetLevel } function YzGetTreeViewText(mHandle: THandle; mStrings: TStrings): Boolean ; var vItemCount: Integer ; vBuffer: array [ 0..255 ] of Char ; vProcessId: DWORD; vProcess: THandle; vPointer: Pointer ; vNumberOfBytesRead: Cardinal ; I: Integer ; vItem: TTVItem; vTreeItem: HTreeItem; begin Result := False ; if not Assigned(mStrings) then Exit; GetWindowThreadProcessId(mHandle, @vProcessId); vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False , vProcessId); vPointer := VirtualAllocEx(vProcess, nil , 4096 , MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); mStrings . BeginUpdate; try mStrings . Clear; vItemCount := TreeView_GetCount(mHandle); vTreeItem := TreeView_GetRoot(mHandle); for I := 0 to vItemCount - 1 do begin with vItem do begin mask := TVIF_TEXT; cchTextMax := SizeOf(vBuffer); pszText := Pointer ( Cardinal (vPointer) + SizeOf(vItem)); hItem := vTreeItem; end ; WriteProcessMemory(vProcess, vPointer, @vItem, SizeOf(vItem), vNumberOfBytesRead); SendMessage(mHandle, TVM_GETITEM, 0 , lparam(vPointer)); ReadProcessMemory(vProcess, Pointer ( Cardinal (vPointer) + SizeOf(TLVItem)), @vBuffer[ 0 ], SizeOf(vBuffer), vNumberOfBytesRead); mStrings . Add(StringOfChar(# 9 , YzTreeNodeGetLevel(mHandle, vTreeItem)) + vBuffer); vTreeItem := YzTreeNodeGetNext(mHandle, vTreeItem); end ; finally VirtualFreeEx(vProcess, vPointer, 0 , MEM_RELEASE); CloseHandle(vProcess); mStrings . EndUpdate; end ; Result := True ; end ; { GetTreeViewText } { 获取其他进程中ListBox和ComboBox的内容 } function YzGetListBoxText(mHandle: THandle; mStrings: TStrings): Boolean ; var vItemCount: Integer ; I: Integer ; S: string ; begin Result := False ; if not Assigned(mStrings) then Exit; mStrings . BeginUpdate; try mStrings . Clear; vItemCount := SendMessage(mHandle, LB_GETCOUNT, 0 , 0 ); for I := 0 to vItemCount - 1 do begin SetLength(S, SendMessage(mHandle, LB_GETTEXTLEN, I, 0 )); SendMessage(mHandle, LB_GETTEXT, I, Integer (@S[ 1 ])); mStrings . Add(S); end ; SetLength(S, 0 ); finally mStrings . EndUpdate; end ; Result := True ; end ; { GetListBoxText } function YzGetComboBoxText(mHandle: THandle; mStrings: TStrings): Boolean ; var vItemCount: Integer ; I: Integer ; S: string ; begin Result := False ; if not Assigned(mStrings) then Exit; mStrings . BeginUpdate; try mStrings . Clear; vItemCount := SendMessage(mHandle, CB_GETCOUNT, 0 , 0 ); for I := 0 to vItemCount - 1 do begin SetLength(S, SendMessage(mHandle, CB_GETLBTEXTLEN, I, 0 )); SendMessage(mHandle, CB_GETLBTEXT, I, Integer (@S[ 1 ])); mStrings . Add(S); end ; SetLength(S, 0 ); finally mStrings . EndUpdate; end ; Result := True ; end ; { GetComboBoxText } { 获取本地Application Data目录路径 } function YzLocalAppDataPath : string ; const SHGFP_TYPE_CURRENT = 0 ; var Path: array [ 0.. MAX_PATH] of char ; begin SHGetFolderPath( 0 , CSIDL_LOCAL_APPDATA, 0 , SHGFP_TYPE_CURRENT, @path[ 0 ]) ; Result := Path; end ; { 获取Windows当前登录的用户名 } function YzGetWindwosUserName: String ; var pcUser: PChar ; dwUSize: DWORD; begin dwUSize := 21 ; result := '' ; GetMem(pcUser, dwUSize); try if Windows . GetUserName(pcUser, dwUSize) then Result := pcUser finally FreeMem(pcUser); end ; end ; {------------------------------------------------------------- 功 能: delphi 枚举托盘图标 参 数: AFindList: 返回找到的托盘列表信息 返回值: 成功为True,反之为False 备 注: 返回的格式为: 位置_名称_窗口句柄_进程ID --------------------------------------------------------------} function YzEnumTrayNotifyWnd(AFindList: TStringList;ADestStr: string ): BOOL; var wd: HWND; wtd: HWND; wd1: HWND; pid: DWORD; hd: THandle; num, i: integer ; n: ULONG; p: TTBBUTTON; pp: ^TTBBUTTON; x: string ; name: array [ 0..255 ] of WCHAR; whd, proid: ulong; temp: string ; sp: ^TTBBUTTON; _sp: TTBButton; begin Result := False ; wd := FindWindow( 'Shell_TrayWnd' , nil ); if (wd = 0 ) then Exit; wtd := FindWindowEx(wd, 0 , 'TrayNotifyWnd' , nil ); if (wtd = 0 ) then Exit; wtd := FindWindowEx(wtd, 0 , 'SysPager' , nil ); if (wtd = 0 ) then Exit; wd1 := FindWindowEx(wtd, 0 , 'ToolbarWindow32' , nil ); if (wd1 = 0 ) then Exit; pid := 0 ; GetWindowThreadProcessId(wd1, @pid); if (pid = 0 ) then Exit; hd := OpenProcess(PROCESS_ALL_ACCESS, true , pid); if (hd = 0 ) then Exit; num := SendMessage(wd1, TB_BUTTONCOUNT, 0 , 0 ); sp := @_sp; for i := 0 to num do begin SendMessage(wd1, TB_GETBUTTON, i, integer (sp)); pp := @p; ReadProcessMemory(hd, sp, pp, sizeof(p), n); name[ 0 ] := Char ( 0 ); if ( Cardinal (p . iString) <> $FFFFFFFF ) then begin try ReadProcessMemory(hd, pointer (p . iString), @name, 255 , n); name[n] := Char ( 0 ); except end ; temp := name; try whd := 0 ; ReadProcessMemory(hd, pointer (p . dwData), @whd, 4 , n); except end ; proid := 0 ; GetWindowThreadProcessId(whd, @proid); AFindList . Add(Format( '%d_%s_%x_%x' , [i, temp, whd, proid])); if CompareStr(temp, ADestStr) = 0 then Result := True ; end ; end ; end ; { 获取SQL Server用户数据库列表 } procedure YzGetSQLServerDBList(ADBHostIP, ALoginPwd: string ;ADBList: TStringList); var PQuery: TADOQuery; ConnectStr: string ; begin ConnectStr := 'Provider=SQLOLEDB.1;Password=' + ALoginPwd + ';Persist Security Info=True;User ID=sa;Initial Catalog=master' + ';Data Source=' + ADBHostIP; ADBList . Clear; PQuery := TADOQuery . Create( nil ); try PQuery . ConnectionString := ConnectStr; PQuery . SQL . Text:= 'select name from sysdatabases where dbid > 6' ; PQuery . Open; while not PQuery . Eof do begin ADBList . add(PQuery . Fields[ 0 ].AsString); PQuery . Next; end ; finally PQuery . Free; end ; end ; { 检测数据库中是否存在给定的表 } procedure YzGetTableList(ConncetStr: string ;ATableList: TStringList); var FConnection: TADOConnection; begin FConnection := TADOConnection . Create( nil ); try FConnection . LoginPrompt := False ; FConnection . Connected := False ; FConnection . ConnectionString := ConncetStr; FConnection . Connected := True ; FConnection . GetTableNames(ATableList, False ); finally FConnection . Free; end ; end ; { 将域名解释成IP地址 } function YzDomainToIP(HostName: string ): string ; type tAddr = array [ 0..100 ] of PInAddr; pAddr = ^tAddr; var I: Integer ; WSA: TWSAData; PHE: PHostEnt; P: pAddr; begin Result := '' ; WSAStartUp( $101 , WSA); try PHE := GetHostByName( pChar (HostName)); if (PHE <> nil ) then begin P := pAddr(PHE^.h_addr_list); I := 0 ; while (P^[I] <> nil ) do begin Result := (inet_nToa(P^[I]^)); Inc(I); end ; end ; except end ; WSACleanUp; end ; { 移去系统托盘失效图标 } procedure YzRemoveDeadIcons(); var hTrayWindow: HWND; rctTrayIcon: TRECT; nIconWidth, nIconHeight: integer ; CursorPos: TPoint; nRow, nCol: Integer ; Begin //Get tray window handle and bounding rectangle hTrayWindow := FindWindowEx(FindWindow( 'Shell_TrayWnd ' , nil ), 0 , 'TrayNotifyWnd ' , nil ); if Not (GetWindowRect(hTrayWindow, rctTrayIcon)) then Exit; //Get small icon metrics nIconWidth := GetSystemMetrics(SM_CXSMICON); nIconHeight := GetSystemMetrics(SM_CYSMICON); //Save current mouse position } GetCursorPos(CursorPos); //Sweep the mouse cursor over each icon in the tray in both dimensions for nRow := 0 To ((rctTrayIcon . bottom - rctTrayIcon . top) div nIconHeight) Do Begin for nCol := 0 To ((rctTrayIcon . right - rctTrayIcon . left) div nIconWidth) Do Begin SetCursorPos(rctTrayIcon . left + nCol * nIconWidth + 5 , rctTrayIcon . top + nRow * nIconHeight + 5 ); Sleep( 0 ); end ; end ; //Restore mouse position SetCursorPos(CursorPos . x, CursorPos . x); //Redraw tray window(to fix bug in multi-line tray area) RedrawWindow(hTrayWindow, nil , 0 , RDW_INVALIDATE Or RDW_ERASE Or RDW_UPDATENOW); end ; { 转移程序占用内存至虚拟内存 } procedure YzClearMemory; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF , $FFFFFFFF ); Application . ProcessMessages; end ; end ; { 检测允许试用的天数是否已到期 } function YzCheckTrialDays(AllowDays: Integer ): Boolean ; var Reg_ID, Pre_ID: TDateTime; FRegister: TRegistry; begin { 初始化为试用没有到期 } Result := True ; FRegister := TRegistry . Create; try with FRegister do begin RootKey := HKEY_LOCAL_MACHINE; if OpenKey( 'Software/Microsoft/Windows/CurrentSoftware/' + YzGetMainFileName(Application . ExeName), True ) then begin if ValueExists( 'DateTag' ) then begin Reg_ID := ReadDate( 'DateTag' ); if Reg_ID = 0 then Exit; Pre_ID := ReadDate( 'PreDate' ); { 允许使用的时间到 } if ((Reg_ID <> 0 ) and (Now - Reg_ID > AllowDays)) or (Pre_ID <> Reg_ID) or (Reg_ID > Now) then begin { 防止向前更改日期 } WriteDateTime( 'PreDate' , Now + 20000 ); Result := False ; end ; end else begin { 首次运行时保存初始化数据 } WriteDateTime( 'PreDate' , Now); WriteDateTime( 'DateTag' , Now); end ; end ; end ; finally FRegister . Free; end ; end ; { 指定长度的随机小写字符串函数 } function YzRandomStr(aLength: Longint ): string ; var X: Longint ; begin if aLength <= 0 then exit; SetLength(Result, aLength); for X := 1 to aLength do Result[X] := Chr(Random( 26 ) + 65 ); Result := LowerCase(Result); end ; end . |
分类:
Delphi
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· DeepSeek V3 两周使用总结
· 回顾我的软件开发经历(1)
· C#使用yield关键字提升迭代性能与效率
· 低成本高可用方案!Linux系统下SQL Server数据库镜像配置全流程详解
· 4. 使用sql查询excel内容