Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Function Suggestion for WindowInfo

Aug
2,314
111
Hi Charles,
I have a program that I put together,
which provides me with the ProcessID of a hWnd,
using the GetWindowThreadProcessId API to obtain such.

Would you please add a function to your WindowInfo plugin that would provide the ProcessID of a hWnd?
Code:
$COMPILE EXE
$REGISTER NONE
$INCLUDE "WIN32API.INC"

FUNCTION PBMAIN AS LONG

        DIM gsTitle AS GLOBAL STRING

        EnumWindows CODEPTR(EnumWindowsProc), 0

END FUNCTION

FUNCTION EnumWindowsProc(BYVAL lHandle AS LONG, BYVAL lNotUsed AS LONG) PRIVATE AS LONG

        DIM gsTitle AS GLOBAL STRING
        DIM dwProcessId AS GLOBAL DWORD

        gsTitle = STRING$(256,0)
        GetWindowText lHandle, BYVAL STRPTR(gsTitle), 256
        gsTitle = EXTRACT$(gsTitle,CHR$(0))
        ucTitle$ = UCASE$(gsTitle)
        Arg1$ = UCASE$(COMMAND$(1))

        IF LEN(gsTitle) THEN

          IF TALLY(ucTitle$, Arg1$) > 0 THEN
            STDOUT USING$("##########",lHandle);
            STDOUT "   ";
            CALL GetWindowThreadProcessId(lHandle, dwProcessId)
            STDOUT USING$("##########",dwProcessID);
            STDOUT "   ";
            STDOUT gsTitle
          END IF
          IF TRIM$(COMMAND$) = "" THEN
            STDOUT USING$("##########",lHandle);
            STDOUT "   ";
            CALL GetWindowThreadProcessId(lHandle, dwProcessId)
            STDOUT USING$("##########",dwProcessID);
            STDOUT "   ";
            STDOUT gsTitle
          END IF
        END IF

        FUNCTION = 1

END FUNCTION

Joe
 
TCC has @WINPID, but that takes a title. You just want to pass an HWND?

I should be able to add this mañana. The docs will probably take longer than the code.
 
Thankyou, Charles, for the function.

@HWNDPID — Returns the process ID of the process which created a given window.
Syntax:
%@HWNDPID[hwnd,flags]
hwndthe window’s handle; decimal or hex with a leading 0x
flagsbitmapped:
1: return process ID in hexadecimal
This function only takes a window handle, not a title. It’s basically a wrapper around the Windows GetWindowThreadProcessId() function.
If the specified window does not exist, or on any other error, this function returns 0.

Joe
 
OK, thanks. It's not on your plugins page.

There's more you could put in if you wanted to use GetAncestor (which gives some odd results) and

Code:
const auto GetRealWindowOwner = (DWORD(WINAPI*)(HWND)) GetProcAddress(GetModuleHandleW(L"user32.dll"), MAKEINTRESOURCEA(2712));

which gives a PID.
 
Back
Top