annotate ui/processhelp_win.cpp @ 621:5d6e86cf3b87

Fix dependency handling for messages files. This causes the messages to be recompiled when they are modified
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 20 Jun 2014 09:49:26 +0200
parents 81a44b93229e
children 175370634226
rev   line source
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 *
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details. */
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 #ifdef WIN32
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "processhelp.h"
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 #include "strhelp.h"
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include <windows.h>
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include <tlhelp32.h>
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <psapi.h>
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <unistd.h>
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 #include <QDebug>
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
19 struct EnumWindowsStruct {
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
20 EnumWindowsStruct() : windowId(0) {}
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
21 DWORD pid;
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
22 HWND windowId;
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 };
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 PSID copySid(PSID from)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 {
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
27 if (!from) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 return 0;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
31 int sidLength = GetLengthSid(from);
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
32 PSID to = (PSID) xmalloc(sidLength);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 CopySid(sidLength, to, from);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 return to;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 static PSID getProcessOwner(HANDLE hProcess)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 HANDLE hToken = NULL;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 PSID sid;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 OpenProcessToken(hProcess, TOKEN_READ, &hToken);
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
43 if (hToken) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 DWORD size;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 PTOKEN_USER userStruct;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 // check how much space is needed
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
48 GetTokenInformation(hToken, TokenUser, NULL, 0, &size);
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
49 if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
50 userStruct = reinterpret_cast<PTOKEN_USER>(new BYTE[size]);
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
51 GetTokenInformation(hToken, TokenUser, userStruct, size, &size);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
53 sid = copySid(userStruct->User.Sid);
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
54 CloseHandle(hToken);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 delete [] userStruct;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 return sid;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 return 0;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 if (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 DWORD pidwin;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 GetWindowThreadProcessId(hwnd, &pidwin);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 if (pidwin == ((EnumWindowsStruct *)lParam)->pid) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 ((EnumWindowsStruct *)lParam)->windowId = hwnd;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 return FALSE;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 return TRUE;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 static HANDLE getProcessHandle(int processID)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 return OpenProcess(SYNCHRONIZE |
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 PROCESS_QUERY_INFORMATION |
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 PROCESS_VM_READ |
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 PROCESS_TERMINATE,
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 false, processID);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 HANDLE h;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 PROCESSENTRY32 pe32;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 QList <int> pids;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 if (h == INVALID_HANDLE_VALUE) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 return pids;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 pe32.dwSize = sizeof(PROCESSENTRY32); // Necessary according to MSDN
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 if (!Process32First(h, &pe32)) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 return pids;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 pids.clear();
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104
608
81a44b93229e Be more permissive with process names. Case insenstive and with suffix or not.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 606
diff changeset
105 const QString processNameLower = processName.toLower().replace(".exe", "");
81a44b93229e Be more permissive with process names. Case insenstive and with suffix or not.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 606
diff changeset
106 const QString processNameExe = processNameLower + ".exe";
81a44b93229e Be more permissive with process names. Case insenstive and with suffix or not.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 606
diff changeset
107
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 do {
608
81a44b93229e Be more permissive with process names. Case insenstive and with suffix or not.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 606
diff changeset
109 const QString exeFile = QString::fromWCharArray(pe32.szExeFile).toLower();
81a44b93229e Be more permissive with process names. Case insenstive and with suffix or not.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 606
diff changeset
110 if (exeFile == processNameLower || exeFile == processNameExe) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 PSID user_sid = getProcessOwner(GetCurrentProcess());
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
112 if (user_sid) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 // Also check that we are the owner of that process
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 HANDLE hProcess = getProcessHandle(pe32.th32ProcessID);
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
115 if (!hProcess) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 continue;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 PSID sid = getProcessOwner(hProcess);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 PSID userSid = getProcessOwner(GetCurrentProcess());
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
121 if (!sid || (userSid && !EqualSid(userSid, sid))) {
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
122 free(sid);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 continue;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 pids.append((int)pe32.th32ProcessID);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 qDebug() << "found PID: " << (int)pe32.th32ProcessID;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 } while (Process32Next(h, &pe32));
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
130 CloseHandle(h);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 return pids;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 bool ProcessHelp::otherProcessesExist(const QString &processName)
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 const QList<int> pids = getProcessesIdForName(processName);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 int myPid = getpid();
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
138 foreach(int pid, pids) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 if (myPid != pid) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 qDebug() << "Found another process with id: " << pid;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 return true;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 return false;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
147 void ProcessHelp::activateWindowForProcess(const QString &executableName)
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
148 {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 const QList<int> pids = getProcessesIdForName(executableName);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 int myPid = getpid();
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 int foundPid = 0;
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
152 foreach(int pid, pids) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 if (myPid != pid) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 qDebug() << "activateWindowForProcess(): PID to activate:" << pid;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 foundPid = pid;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 break;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 }
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
159 if (foundPid == 0) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 return;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 EnumWindowsStruct winStruct;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 winStruct.pid = foundPid;
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
164 EnumWindows(EnumWindowsProc, (LPARAM)&winStruct);
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
165 if (winStruct.windowId == 0) {
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 return;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 }
606
91dd38a71783 Style: run astyle on processhelp
Andre Heinecke <andre.heinecke@intevation.de>
parents: 603
diff changeset
168 SetForegroundWindow(winStruct.windowId);
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 #endif // WIN32
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171

http://wald.intevation.org/projects/trustbridge/