2,726
社区成员
发帖
与我相关
我的任务
分享
Declare Long WinExec In kernel32 String,Long &&运行指定的程序
Declare Long GetClassName In WIN32API Long HWnd,String @lpClassName,Long nMaxCount &&获得指定窗口所属的类的类名
Declare Long GetWindowText In WIN32API Integer HWnd,String @lpText,Long nMaxCount &&函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存区内。如果指定的窗口是一个控制,则拷贝控制的文本。
Declare Long FindWindow In WIN32API String lpClassName,String lpWindowName &&函数返回与指定字符创相匹配的窗口类名或窗口名的最顶层窗口的窗口句柄。这个函数不会查找子窗口。
Declare Long FindWindowEx In WIN32API Long hwndParent,Long hwndChildAfter,String @lpszClass,String @lpszWindow &&函数获得一个窗口的句柄,该窗口的类名和窗口名与给定的字符串相匹配。这个函数查找子窗口,从排在给定的子窗口后面的下一个子窗口开始。在查找时不区分大小写。
Declare Long SendMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。
Declare Long PostMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&函数将一个消息放入(寄送)到与指定窗口创建的线程相联系消息队列里,不等待线程处理消息就返回,是异步消息模式。
Declare Long GetWindowRect In WIN32API Integer HWnd,String @lpRect &&函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。
Declare Long SetCursorPos In WIN32API Integer X,Integer Y &&函数把光标移到屏幕的指定位置。
Declare mouse_event In Win32API Integer dwFlags,Integer dx,Integer dy,Integer cButtons,Integer dwExtraInfo &&函数综合鼠标击键和鼠标动作。
#Define EM_REPLACESEL 0x00C2
#Define MOUSEEVENTF_LEFTDOWN 0x0002
#Define MOUSEEVENTF_LEFTUP 0x0004
#Define BM_CLICK 0x00F5
=WinExec("c:\自动对时器.exe",1) &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\
Create Cursor T1 (ObjectID I,ParentID I,ClassName C(50),ObjectText C(50))
lcCaption="请输入密码" &&要查找窗口的标题
lnHandle=FindWindow(Null,lcCaption)
If lnHandle>0
lnChildHandle=0
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
If lnChildHandle<>0
lnHandle=lnChildHandle
lnChildHandle=0
Do While .T.
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
If lnChildHandle<>0
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),""))
Loop
Else
Exit
Endif
Enddo
Endif
Select * Into Cursor T2 From T1 Where ClassName="TPanel"
Select T2
Scan
lnHandle=ObjectID
lnChildHandle=0
Do While .T.
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
If lnChildHandle<>0
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),""))
Loop
Else
Exit
Endif
Enddo
Endscan
Select T1
Locate For Alltrim(ObjectText)=="使用文件做密码"
If Found()
lcRect=Replicate(Chr(0),16)
If GetWindowRect(ObjectID,@lcRect)#0
lnLeftUpX=CToBin(Substr(lcRect,1,4),'4rs') &&左上角 X 坐标
lnLeftUpY=CToBin(Substr(lcRect,5,4),'4rs') &&左上角 Y 坐标
lnRightDownX=CToBin(Substr(lcRect,9,4),'4rs') &&右下角 X 坐标
lnRightDownY=CToBin(Substr(lcRect,13,4),'4rs') &&右下角 Y 坐标
SetCursorPos(lnLeftUpX+(lnRightDownX-lnLeftUpX)/2,lnLeftUpY+(lnRightDownY-lnLeftUpY)/2) &&鼠标移到 CHECKBOX
=mouse_event(MOUSEEVENTF_LEFTDOWN+MOUSEEVENTF_LEFTUP,0,0,0,0) &&单击左键(按下再松开的组合)
Wait '' Window At 10,10 Timeout 0.1
Endif
lnParentID=ParentID
Locate For ClassName="TEdit" And ParentID=lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"C:\文件密码.dat") &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\
Endif
Locate For ClassName="TEdit" And ParentID<>lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"123") &&密码 123
Endif
Locate For Alltrim(ObjectText)=="确 定"
If Found()
PostMessage(ObjectID,BM_CLICK,0,'')
Endif
Endif
Else
Messagebox("没有找到 ["+lcCaption+"] 窗体!"+Space(5),48,"信息提示")
Endif
Clear Dlls
*-- 转自红雨大侠
GetAllWinHander("TMP1") &&TMP1临时表名
Locate
Browse
* -------------------------------------
* 枚举所有当前进程窗口句柄、标题、类名、进程ID
* -------------------------------------
Function GetAllWinHander ( tcWindTable )
tcWindTable = IIF(para()=1 AND TYPE([tcWindTable])=[C], tcWindTable, [AllWindlists] )
#Define GW_HWNDNEXT 2
Declare integer FindWindow in "user32" string lpclassName, string lpWindowName
Declare integer GetWindow in "user32" integer hwnd, integer wFlag
Crea curs (tcWindTable) ( PnWinHand N(12), PcWinTitle C(254), PcWinClass C(254), PnWinProcID N(18))
Local lnHCurrent, lnWinCount, lcWinTitle
lnHCurrent = FindWindow( [Shell_TrayWnd], 0)
lnWinCount = 1 && 计数
Do WHILE lnHCurrent > 0
lcWinTitle = GetWinText( lnHCurrent )
lcWinClass = GetWinClass( lnHCurrent )
lnWinProcID = GetProcessIdFromHand( lnHCurrent )
Insert INTO (tcWindTable) (PnWinHand, PcWinTitle, PcWinClass, PnWinProcID ) ;
VALUES (lnHCurrent, lcWinTitle, lcWinClass, lnWinProcID )
lnWinCount = lnWinCount + 1
lnHCurrent = GetWindow( lnHCurrent, GW_HWNDNEXT ) && 得到下一个窗口句柄
Enddo
Endfunc
* -------------------------------------
* 由窗口句柄返回其类名
* -------------------------------------
Function GetWinClass ( lpnWinHand )
Local lcWinClass
lcWinClass = []
If TYPE([lpnWinHand])=[N]
Declare Integer GetClassName In user32 Integer, String @, Integer
lcWinClass = Repl( CHR( 0), 256)
lnClassLen = GetClassName( lpnWinHand, @lcWinClass, 255)
lcWinClass = Left( lcWinClass, lnClassLen)
Endif
Return lcWinClass
Endfunc
* -------------------------------------
* 由窗口句柄返回其标题
* -------------------------------------
Function GetWinText ( lpnWinHand )
Local lcWinText
lcWinText = []
If TYPE([lpnWinHand])=[N]
Declare Integer GetWindowText In user32 Integer, String @, Integer
lcWinText = Repl( CHR( 0), 256)
lnTextLen = GetWindowText( lpnWinHand, @lcWinText, 255)
lcWinText = Left( lcWinText, lnTextLen)
Endif
Return lcWinText
Endfunc
* -------------------------------------
* 由窗口句柄返回其进程Id
* -------------------------------------
Function GetProcessIdFromHand ( lpnWinHand )
Local lnProcessId
lnProcessId = 0
If TYPE([lpnWinHand])=[N]
Declare integer GetWindowThreadProcessId in "user32" integer hwnd, integer @lpdwProcessId
= GetWindowThreadProcessId( lpnWinHand, @lnProcessId )
Endif
Return lnProcessId
Endfunc
* -------------------------------------
* 枚举当前所有进程
* -------------------------------------
Function GetAllProcessID ( lpProcTable )
lpProcTable = IIF(para()=1 AND TYPE([lpProcTable])=[C], lpProcTable, [AllProclists] )
Declare integer CreateToolhelp32Snapshot in kernel32 integer lFlags, integer lProcessID
Declare integer Process32First in kernel32 integer hSnapShot, string @PROCESSENTRY32_uProcess
Declare integer Process32Next in kernel32 integer hSnapShot, string @PROCESSENTRY32_uProcess
Declare integer CloseHandle in kernel32 integer hObject
Declare integer GetLastError in kernel32
Crea curs (lpProcTable) (PdwSize N(3), PcntUsage N(12), ;
Pth32ProcessID N(12), Pth32DefaultHeapID N(12), ;
Pth32ModuleID N(12), PcntThreads N(12), ;
Pth32ParentProcessID N(12), PpcPriClassBase N(3), ;
PdwFlags N(3), PszExeFile C(254) )
lnHand = 0
lnHand = CreateToolhelp32Snapshot(3,0)
If lnHand>0
dwSize = Num2Dword(296)
cntUsage = Num2Dword(0)
th32ProcessID = Num2Dword(0)
th32DefaultHeapID = Num2Dword(0)
th32ModuleID = Num2Dword(0)
cntThreads = Num2Dword(0)
th32ParentProcessID = Num2Dword(0)
pcPriClassBase = Num2Dword(0)
dwFlags = Num2Dword(0)
szExeFile = Repli(CHR(0), 260)
lcTitle = dwSize + cntUsage + th32ProcessID + th32DefaultHeapID ;
+ th32ModuleID + cntThreads + th32ParentProcessID ;
+ pcPriClassBase + dwFlags + szExeFile
If Process32First(lnHand,@lcTitle) > 0 && 第一个进程是 kernel32.dll,没必要列出
Do while Process32Next(lnHand,@lcTitle)> 0
Insert INTO (lpProcTable) (PdwSize, PcntUsage, Pth32ProcessID, Pth32DefaultHeapID, ;
Pth32ModuleID, PcntThreads, Pth32ParentProcessID, ;
PpcPriClassBase, PdwFlags, PszExeFile) ;
VALUES ( ;
Dword2Num(Subs(lcTitle, 1,4)), ;
Dword2Num(Subs(lcTitle, 5,4)), ;
Dword2Num(Subs(lcTitle, 9,4)), ;
Dword2Num(Subs(lcTitle,13,4)), ;
Dword2Num(Subs(lcTitle,17,4)), ;
Dword2Num(Subs(lcTitle,21,4)), ;
Dword2Num(Subs(lcTitle,25,4)), ;
Dword2Num(Subs(lcTitle,29,4)), ;
Dword2Num(Subs(lcTitle,33,4)), ;
SUBSTR(SUBSTR(lcTitle, 37), 1, AT(CHR(0),SUBSTR(lcTitle, 37))-1) )
Enddo
Endif
= CloseHandle(lnHand)
Return .T.
Else
Return .F.
Endif
Endfunc
Function Num2Dword ( lpnNum )
Declare integer RtlMoveMemory in kernel32 as RtlCopyDword string @pDeststring, integer @pVoidSource, integer nLength
lcDword = SPACE(4)
= RtlCopyDword(@lcDword, bitor(lpnNum,0), 4)
Return lcDword
Endfunc
Function Dword2Num ( tcDword )
Declare integer RtlMoveMemory in kernel32 as RtlCopyNum integer @DestNumeric, string @pVoidSource, integer nLength
lnNum = 0
=RtlCopyNum(@lnNum, tcDword, 8)
Return lnNum
Endfunc
* -------------------------------------
* 从 ProcessId 关闭进程
* -------------------------------------
Function ExitProcessId ( lpnProcessId )
Declare integer TerminateProcess in kernel32 integer hProcess , integer uExitCode
Declare integer OpenProcess in kernel32 integer dwDesiredAccess, integer binheritHandle, integer dwProcessId
Declare integer GetCurrentProcessId in kernel32
If lpnProcessId = GetCurrentProcessId()
Return .F.
Else
hproc = OpenProcess(2035711, 0, lpnProcessId) && 从进程 ID 获得进程句柄
If hproc = 0
Return .F.
Else
= TerminateProcess(hproc, 0) && 关闭进程
Return .T.
Endif
Endif
Endfunc
* -------------------------------------
* 从 窗口句柄 关闭程序
* -------------------------------------
Function ExitWinHander ( lpnWinHand )
If TYPE([lpnWinHand])=[N]
If lpnWinHand # 0
Declare integer ShowWindowAsync in "user32" integer hwnd, integer nCmdShow
Declare integer SetForegroundWindow in "user32" integer hwnd
Declare integer SendMessage in win32api integer hwnd, integer wMsg, integer wParam, integer lParam
= ShowWindowAsync( lpnWinHand, 1 ) && 将窗口设为可见
= SetForegroundWindow( lpnWinHand ) && 将窗口设为系统的前台窗口
= SendMessage( lpnWinHand, 16, 0, 0 ) && 将退出消息发给那个窗口
Endif
Endif
Endfunc
* -------------------------------------
Declare Long WinExec In kernel32 String,Long
Declare Long GetClassName In WIN32API Long HWnd,String @lpClassName,Long nMaxCount
Declare Long GetWindowText In WIN32API Integer HWnd,String @lpText,Long nMaxCount
Declare Long FindWindow In WIN32API String lpClassName,String lpWindowName &&函数返回与指定字符创相匹配的窗口类名或窗口名的最顶层窗口的窗口句柄。这个函数不会查找子窗口。
Declare Long FindWindowEx In WIN32API Long hwndParent,Long hwndChildAfter,String @lpszClass,String @lpszWindow &&该函数获得一个窗口的句柄,该窗口的类名和窗口名与给定的字符串相匹配。这个函数查找子窗口,从排在给定的子窗口后面的下一个子窗口开始。在查找时不区分大小写。
Declare Long SendMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。
Declare Long PostMessage In WIN32API Long HWnd,Long Msg,Long wParam,String lParam
Declare Long EnableWindow In WIN32API Long HWnd,Long fEnable
#Define EM_REPLACESEL 0xC
#Define BM_SETCHECK 0x00F1
#Define BM_CLICK 0xF5
#Define WM_COMMAND 0x0111
=WinExec("c:\自动对时器.exe",1) &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\
Create Cursor T1 (ObjectID I,ParentID I,ClassName C(50),ObjectText C(50))
lcCaption="请输入密码" &&要查找窗口的标题
lnHandle=FindWindow(Null,lcCaption)
If lnHandle>0
lnChildHandle=0
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
If lnChildHandle<>0
lnHandle=lnChildHandle
lnChildHandle=0
Do While .T.
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
If lnChildHandle<>0
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),""))
Loop
Else
Exit
Endif
Enddo
Endif
Select * Into Cursor T2 From T1 Where ClassName="TPanel"
Select T2
Scan
lnHandle=ObjectID
lnChildHandle=0
Do While .T.
lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null)
If lnChildHandle<>0
Store Space(256) To lpClassName,lpText
GetClassName(lnChildHandle,@lpClassName,256)
GetWindowText(lnChildHandle,@lpText,256)
Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),""))
Loop
Else
Exit
Endif
Enddo
Endscan
Select T1
Locate For Alltrim(ObjectText)=="使用文件做密码"
If Found()
lnParentID=ParentID
Locate For ClassName="TEdit" And ParentID<>lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"123") &&密码 123
Endif
Locate For ClassName="TEdit" And ParentID=lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"C:\文件密码.dat") &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\
Endif
Locate For Alltrim(ObjectText)=="确 定"
If Found()
EnableWindow(ObjectID,1)
*SendMessage(ObjectID,BM_CLICK,0,'')
Endif
Endif
Else
Messagebox("没有找到 ["+lcCaption+"] 窗体!"+Space(5),48,"信息提示")
Endif