summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorashok <ashok>2014-09-20 12:30:12 (GMT)
committerashok <ashok>2014-09-20 12:30:12 (GMT)
commitb236f1898b07665e8a3d61b135d2f54b19741bfd (patch)
tree6a124a29fb182ff1256f3879877a905b7fd718f5 /win
parent9f74692b1f95fcdd80c669bbb3c54e851736a87d (diff)
downloadtk-b236f1898b07665e8a3d61b135d2f54b19741bfd.zip
tk-b236f1898b07665e8a3d61b135d2f54b19741bfd.tar.gz
tk-b236f1898b07665e8a3d61b135d2f54b19741bfd.tar.bz2
Make findwindow more robust by ensuring it is a window belonging
to the same process.
Diffstat (limited to 'win')
-rw-r--r--win/tkWinTest.c22
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));