Delphi公用函数单元 -YzDelphiFunc
2021-01-03 03:28
标签:winsock self lag note lock mic 成功 compare lvm {*******************************************************}
{ }
{ Delphi公用函数单元 }
{ }
{ 版权所有 (C) 2008 }
{ }
{*******************************************************}
unit YzDelphiFunc;
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 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 := GetTickCo
文章标题:Delphi公用函数单元 -YzDelphiFunc
文章链接:http://soscw.com/index.php/essay/39731.html