Is it possible to find the Foreground Window, even if not created by your program and then find the yes button and click it.
Bob Mechler
Bob Mechler
#Dim All #Compile Exe #Include "WIN32API.INC" '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== ' Enum all Child Windows callback '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== Function EnumChildWin(ByVal hWnd AS Dword, ByVal dFlags AS Dword) AS Long Local iCount As Long Local iRet As Long Local sText As String Local sLabel As String Local hData As Long Local hGlob As Long Local zText As Asciiz * %MAX_PATH Local iStyle As Long GetClassName hWnd, zText, SizeOf(zText) 'get the class name to see if this is a button iStyle = GetWindowLong(hWnd, %GWL_STYLE) If zText = "Button" And ((iStyle And %BS_GROUPBOX) <> %BS_GROUPBOX) And IsWindowVisible(hWnd) Then If GetWindowText(hWnd, zText, ByVal %MAX_PATH) Then 'get the text for this item sText = Remove$(Trim$(zText), "&") 'remove the accel symbols IF UCASE$(sText) = "YES" THEN 'YES button found 'GetWindowText(GetParent(hWnd), zText, ByVal %MAX_PATH) 'get the parent windows text to store in log 'LogThis "Clicking Button [" + sText + "] on " + zText 'send a message to our log PostMessage hWnd, %BM_CLICK, 0, 0 'send the button a click message End If End If End If Function = %TRUE 'return TRUE to continue listing child windows End Function '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== Function PBMain() LOCAL hTopWin AS DWORD hTopWin = GetForegroundWindow() if hTopWin Then Call EnumChildWindows(hTopWin, CodePtr(EnumChildWin), 0) 'go through each item under the main window End If End Function '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==
Local x& x = MsgBox ("Testing William", %MB_YESNO, "Click Yes")
#Dim All #Compile Exe #Include "WIN32API.INC" '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== ' Enum all Child Windows callback '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== Global x&, s$, Last_s$, Class_ctr&, Everything$ '<<< Global just easier here for this example Macro Into_CLipboard s$ = Left$(zText, Len(zText) -1) & $CrLf 'strip null ' s$ = s$ & " " & sLabel & $CrLf ' s$ = s$ & " " & sText & $CrLf Incr Class_ctr If s$ <> Last_s$ Then Everything$ = Everything$ & Using$("# Instances of ", Class_ctr) & s$ & $CrLf Reset Class_ctr End If Last_s$ = s$ End Macro Function EnumChildWin(ByVal hWnd As Dword, ByVal dFlags As Dword) As Long Local iCount As Long Local iRet As Long Local sText As String Local sLabel As String Local hData As Long Local hGlob As Long Local zText As Asciiz * %MAX_PATH Local iStyle As Long GetClassName hWnd, zText, SizeOf(zText) 'get the class name to see if this is a button iStyle = GetWindowLong(hWnd, %GWL_STYLE) Into_Clipboard If zText = "Button" And ((iStyle And %BS_GROUPBOX) <> %BS_GROUPBOX) And IsWindowVisible(hWnd) Then ' Into_Clipboard If GetWindowText(hWnd, zText, ByVal %MAX_PATH) Then 'get the text for this item sText = Remove$(Trim$(zText), "&") 'remove the accel symbols If UCase$(sText) = "YES" Then 'YES button found 'GetWindowText(GetParent(hWnd), zText, ByVal %MAX_PATH) 'get the parent windows text to store in log 'LogThis "Clicking Button [" + sText + "] on " + zText 'send a message to our log PostMessage hWnd, %BM_CLICK, 0, 0 'send the button a click message End If End If End If Function = %TRUE 'return TRUE to continue listing child windows End Function '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~== Function PBMain() Local hTopWin As Dword hTopWin = GetForegroundWindow() If hTopWin Then Call EnumChildWindows(hTopWin, CodePtr(EnumChildWin), 0) 'go through each item under the main window End If ClipBoard Set Text Everything$ To x ? Everything$,, "Also in Clipboard" End Function '==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==
SetWindowsHookEx(%WH_JOURNALPLAYBACK, CODEPTR(PlayHookProc), GetModuleHandle(BYVAL 0), 0)
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" %IDD_DIALOG1 = 101 %IDC_BUTRECORD = 1005 %IDC_BUTPLAY = 1010 %IDC_BUTSTOP = 1015 %IDC_FRAME1 = 1020 %IDC_TXTFILE = 1025 %IDC_BUTBROWSE = 1030 %IDC_LABMSG = 1035 DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() global ghDlg as dword global ghFile As DWORD global ghHook as dword GLOBAL giStop as long '-------------------------------------------------------------------------------- FUNCTION RecHookProc(BYVAL iCode AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG Local EM AS EventMsg PTR if ghFile =0 or giStop then 'insure we have a valid file and we have not pressed stop If ghHook then UnhookWindowsHookEx ghHook if ghFile then CLOSE ghFile ghFile = 0 ghHook = 0 Control Set Text ghDlg, %IDC_LABMSG, "Record stopped" EXIT FUNCTION end if SELECT CASE iCode CASE %HC_ACTION EM = lParam PRINT #ghFile, STR$(@EM.message) & $TAB & STR$(@EM.paramL) & $TAB & STR$(@EM.paramH) & $TAB & STR$(@EM.time) & $TAB & STR$(@EM.hWnd) END SELECT IF iCode < 0 THEN FUNCTION = CallNextHookEx (CODEPTR(RecHookProc), icode, wParam, lParam) END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION PlayHookProc(BYVAL iCode AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG Local EM AS EventMsg PTR local sText as string if ghFile =0 or EOF(ghFile) or giStop then 'check to see if we have more to read from file or we pressed stop If ghHook then UnhookWindowsHookEx ghHook if ghFile then CLOSE ghFile ghFile = 0 ghHook = 0 Control Set Text ghDlg, %IDC_LABMSG, "Playback stopped" EXIT FUNCTION end if SELECT CASE iCode CASE %HC_GETNEXT Line INPUT #ghFile, sText SLEEP 25 'playback a little slower EM = lParam @EM.message = VAL(parse$(sText, $TAB, 1)) @EM.paramL = VAL(parse$(sText, $TAB, 2)) @EM.paramH = VAL(parse$(sText, $TAB, 3)) @EM.time = VAL(parse$(sText, $TAB, 4)) @EM.hWnd = VAL(parse$(sText, $TAB, 5)) END SELECT IF iCode < 0 THEN FUNCTION = CallNextHookEx(CODEPTR(PlayHookProc), icode, wParam, lParam) END FUNCTION '-------------------------------------------------------------------------------- '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowDIALOG1Proc() local sFile as string SELECT CASE AS LONG CBMSG CASE %WM_CLOSE If ghHook then UnhookWindowsHookEx ghHook if ghFile then CLOSE ghFile CASE %WM_COMMAND SELECT CASE AS LONG CBCTL CASE %IDC_BUTRECORD IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 and ghHook = 0 THEN control get text ghDlg, %IDC_TXTFILE to sFile try sleep 500 giStop = 0 ghFile = FreeFile Open sFile for OutPut as #ghFile ghHook = SetWindowsHookEx(%WH_JOURNALRECORD, CODEPTR(RecHookProc), GetModuleHandle(BYVAL 0), 0) Control Set Text ghDlg, %IDC_LABMSG, "Recording." catch msgbox Error$(Err),,"Error opening file" end try END IF CASE %IDC_BUTPLAY IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 and ghHook = 0 THEN control get text ghDlg, %IDC_TXTFILE to sFile try sleep 500 giStop = 0 ghFile = FreeFile Open sFile for InPut as #ghFile ghHook = SetWindowsHookEx(%WH_JOURNALPLAYBACK, CODEPTR(PlayHookProc), GetModuleHandle(BYVAL 0), 0) Control Set Text ghDlg, %IDC_LABMSG, "Playing." catch msgbox Error$(Err),,"Error opening file" end try END IF CASE %IDC_BUTBROWSE IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 AND ghHook = 0 THEN 'NOTE: if you dont have PB9 you can remark out the following 2 lines which only let you browse for a file DISPLAY SAVEFILE ghDlg,,, "Choose keylog file", "", CHR$("Log File", 0, "*.LOG", 0), CURDIR$, "LOG", %OFN_NOCHANGEDIR TO sFile if mid$(sFile,2,1) = ":" then control set text ghDlg, %IDC_TXTFILE, sFile END IF CASE %IDC_BUTSTOP IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 AND ghHook <> 0 and giStop = %FALSE THEN giStop = %TRUE Control Set Text ghDlg, %IDC_LABMSG, "Aborting." END IF CASE %IDC_LABMSG END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ FUNCTION PBMain() as LONG LOCAL hDlg AS DWORD DIALOG NEW 0, "Journal Playback", 115, 103, 213, 48, %WS_POPUP OR _ %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _ %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME _ OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _ %WS_EX_CONTROLPARENT OR %WS_EX_TOPMOST OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD BUTTON, hDlg, %IDC_BUTRECORD, "&Record", 5, 5, 35, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTPLAY, "&Playback", 40, 5, 35, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTSTOP, "&Stop", 80, 5, 35, 15 CONTROL ADD FRAME, hDlg, %IDC_FRAME1, "Record/Playback file:", 5, 20, 205, 25 CONTROL ADD TEXTBOX, hDlg, %IDC_TXTFILE, "KeyStrokes.txt", 10, 30, 175, 10 CONTROL ADD BUTTON, hDlg, %IDC_BUTBROWSE, "...", 190, 30, 15, 10 CONTROL ADD LABEL, hDlg, %IDC_LABMSG, "", 125, 5, 80, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_CENTER OR %SS_NOTIFY OR %SS_SUNKEN, %WS_EX_LEFT OR %WS_EX_LTRREADING ghDlg = hDlg DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc END FUNCTION '------------------------------------------------------------------------------
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment