I would to show the last active window (i know this can give me problems because some text editors change the name of the title when the file is modified and not saved).
Code:
'Compilable Example: #COMPILER PBWIN 10 #COMPILE EXE #DIM ALL %Unicode=1 : %IDC_Button = 500 #INCLUDE "win32api.inc" %ID_Timer1 = 500 GLOBAL hDlg,hFound AS DWORD, szText AS WSTRINGZ * %MAX_PATH, temp AS WSTRINGZ * %MAX_PATH GLOBAL hForeground AS DWORD FUNCTION PBMAIN() AS LONG hForeground = GetForegroundWindow() DIALOG NEW PIXELS, 0, "Get Last Active Window",300,300,420,100,%WS_OVERLAPPEDWINDOW TO hDlg CONTROL ADD LABEL, hDlg, 205, "Start", 5, 50, 400, 15, %SS_LEFT CONTROL ADD BUTTON, hDlg, %IDC_Button, "Check now!", 10,10,120,20 DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION CALLBACK FUNCTION DlgProc() AS LONG SELECT CASE CB.MSG CASE %WM_INITDIALOG SetTimer(CB.HNDL, %ID_Timer1, 500, BYVAL %NULL) 'uses callback messages CASE %WM_TIMER IF CB.WPARAM = %ID_Timer1 THEN hForeground = GetForegroundWindow() GetWindowText(hForeground, temp, SIZEOF(szText)) IF temp <> "Get Last Active Window" THEN szText = temp END IF CONTROL SET TEXT hDlg, 205, szText END IF CASE %WM_COMMAND IF CB.CTL = %IDC_Button AND CB.CTLMSG = %BN_CLICKED THEN GetWindowText(hForeground, szText, SIZEOF(szText)) 'msgbox szText CONTROL SET TEXT hDlg, 205, szText END IF END SELECT END FUNCTION
But, whats the best choice to know about some window was focused? i have to set a timer and check at some fast intervals or there is some api?
feel free to atack my code... this is my first PB project.
Leave a comment: