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)
commitc274f24adf15e98a9fbf65571984e7b0c30c40da (patch)
tree6a124a29fb182ff1256f3879877a905b7fd718f5 /win
parenta0426df76aa736ba2d618441232d72e4ba38a380 (diff)
downloadtk-c274f24adf15e98a9fbf65571984e7b0c30c40da.zip
tk-c274f24adf15e98a9fbf65571984e7b0c30c40da.tar.gz
tk-c274f24adf15e98a9fbf65571984e7b0c30c40da.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));