diff options
author | ashok <ashok@noemail.net> | 2014-09-20 12:30:12 (GMT) |
---|---|---|
committer | ashok <ashok@noemail.net> | 2014-09-20 12:30:12 (GMT) |
commit | 0443ba3f45fc08fed3370f8a211ce1c631252c14 (patch) | |
tree | 6a124a29fb182ff1256f3879877a905b7fd718f5 /win | |
parent | 985114eeed0e47d8992dd698a5a75acca8892ebb (diff) | |
download | tk-0443ba3f45fc08fed3370f8a211ce1c631252c14.zip tk-0443ba3f45fc08fed3370f8a211ce1c631252c14.tar.gz tk-0443ba3f45fc08fed3370f8a211ce1c631252c14.tar.bz2 |
Make findwindow more robust by ensuring it is a window belonging
to the same process.
FossilOrigin-Name: 3f1e045f8f6940f65c31b04588f29d9ebe52ac86
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinTest.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/win/tkWinTest.c b/win/tkWinTest.c index 2c38d71..8a92f5a 100644 --- a/win/tkWinTest.c +++ b/win/tkWinTest.c @@ -439,6 +439,7 @@ TestfindwindowObjCmd( Tcl_DString titleString, classString; HWND hwnd = NULL; int r = TCL_OK; + DWORD myPid; Tcl_DStringInit(&classString); Tcl_DStringInit(&titleString); @@ -454,7 +455,28 @@ TestfindwindowObjCmd( } if (title[0] == 0) title = NULL; +#if 0 hwnd = FindWindow(class, title); +#else + /* We want find a window the belongs to us and not some other process */ + hwnd = NULL; + myPid = GetCurrentProcessId(); + while (1) { + DWORD pid, tid; + hwnd = FindWindowEx(NULL, hwnd, class, title); + if (hwnd == NULL) + break; + tid = GetWindowThreadProcessId(hwnd, &pid); + if (tid == 0) { + /* Window has gone */ + hwnd = NULL; + break; + } + if (pid == myPid) + break; /* Found it */ + } + +#endif if (hwnd == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to find window: ", -1)); |