Skip to content

Commit 43b5a7e

Browse files
committed
better messages while sending WM_CLOSE
1 parent 2f92214 commit 43b5a7e

5 files changed

Lines changed: 60 additions & 36 deletions

File tree

npackdg/src/npackdg_de.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2721,7 +2721,7 @@ p, li { white-space: pre-wrap; }
27212721
<translation type="unfinished"></translation>
27222722
</message>
27232723
<message>
2724-
<source>Sending a WM_CLOSE event to &quot;%1&quot;</source>
2724+
<source>Sending a WM_CLOSE event to the window of the class &quot;%1&quot; from the process &quot;%2&quot;</source>
27252725
<translation type="unfinished"></translation>
27262726
</message>
27272727
</context>

npackdg/src/npackdg_es.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ p, li { white-space: pre-wrap; }
35263526
<translation type="unfinished"></translation>
35273527
</message>
35283528
<message>
3529-
<source>Sending a WM_CLOSE event to &quot;%1&quot;</source>
3529+
<source>Sending a WM_CLOSE event to the window of the class &quot;%1&quot; from the process &quot;%2&quot;</source>
35303530
<translation type="unfinished"></translation>
35313531
</message>
35323532
</context>

npackdg/src/npackdg_fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,7 @@ p, li { white-space: pre-wrap; }
34123412
<translation type="unfinished"></translation>
34133413
</message>
34143414
<message>
3415-
<source>Sending a WM_CLOSE event to &quot;%1&quot;</source>
3415+
<source>Sending a WM_CLOSE event to the window of the class &quot;%1&quot; from the process &quot;%2&quot;</source>
34163416
<translation type="unfinished"></translation>
34173417
</message>
34183418
</context>

npackdg/src/npackdg_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3514,7 +3514,7 @@ p, li { white-space: pre-wrap; }
35143514
<translation type="unfinished"></translation>
35153515
</message>
35163516
<message>
3517-
<source>Sending a WM_CLOSE event to &quot;%1&quot;</source>
3517+
<source>Sending a WM_CLOSE event to the window of the class &quot;%1&quot; from the process &quot;%2&quot;</source>
35183518
<translation type="unfinished"></translation>
35193519
</message>
35203520
</context>

npackdg/src/wpmutils.cpp

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,13 +1618,20 @@ void WPMUtils::closeProcessesThatUseDirectory(const QString &dir,
16181618
bool changed = false;
16191619
for (int i = 0; i < ps.size(); i++) {
16201620
HANDLE p = ps.at(i);
1621-
if (GetProcessId(p) != me && !pathEquals(explorer, getProcessFile(p))) {
1622-
QList<HWND> ws = findProcessTopWindows(GetProcessId(p));
1623-
if (ws.size() > 0) {
1624-
closeProcessWindows(p, ws);
1625-
changed = true;
1626-
}
1627-
}
1621+
1622+
if (GetProcessId(p) == me)
1623+
continue;
1624+
1625+
QString processFile = getProcessFile(p);
1626+
if (processFile.isEmpty() || pathEquals(explorer, processFile))
1627+
continue;
1628+
1629+
QList<HWND> ws = findProcessTopWindows(GetProcessId(p));
1630+
if (ws.size() == 0)
1631+
continue;
1632+
1633+
closeProcessWindows(p, ws);
1634+
changed = true;
16281635
}
16291636

16301637
if (changed) {
@@ -1641,17 +1648,26 @@ void WPMUtils::closeProcessesThatUseDirectory(const QString &dir,
16411648
HANDLE hProc = ps.at(i);
16421649
DWORD processId = GetProcessId(hProc);
16431650

1644-
if (processId != 0 && processId != me &&
1645-
WPMUtils::isProcessRunning(hProc) &&
1646-
!pathEquals(explorer, getProcessFile(hProc))) {
1647-
// 0 = GR_GDIOBJECTS, 1 = GR_USEROBJECTS
1648-
if (GetGuiResources(hProc, 0) == 0 &&
1649-
GetGuiResources(hProc, 1) == 0) {
1650-
qCInfo(npackd).noquote() << QObject::tr("Sending Ctrl+C to \"%1\"").
1651-
arg(getProcessFile(hProc));
1652-
if (GenerateConsoleCtrlEvent(CTRL_C_EVENT, processId)) {
1653-
changed = true;
1654-
}
1651+
if (processId == 0)
1652+
continue;
1653+
1654+
if (processId == me)
1655+
continue;
1656+
1657+
if (!WPMUtils::isProcessRunning(hProc))
1658+
continue;
1659+
1660+
QString processFile = getProcessFile(hProc);
1661+
if (processFile.isEmpty() || pathEquals(explorer, processFile))
1662+
continue;
1663+
1664+
// 0 = GR_GDIOBJECTS, 1 = GR_USEROBJECTS
1665+
if (GetGuiResources(hProc, 0) == 0 &&
1666+
GetGuiResources(hProc, 1) == 0) {
1667+
qCInfo(npackd).noquote() << QObject::tr("Sending Ctrl+C to \"%1\"").
1668+
arg(getProcessFile(hProc));
1669+
if (GenerateConsoleCtrlEvent(CTRL_C_EVENT, processId)) {
1670+
changed = true;
16551671
}
16561672
}
16571673
}
@@ -1668,19 +1684,27 @@ void WPMUtils::closeProcessesThatUseDirectory(const QString &dir,
16681684
HANDLE hProc = ps.at(i);
16691685
DWORD processId = GetProcessId(hProc);
16701686

1671-
if (processId != 0 && processId != me &&
1672-
WPMUtils::isProcessRunning(hProc) &&
1673-
!pathEquals(explorer, getProcessFile(hProc))) {
1687+
if (processId == 0)
1688+
continue;
16741689

1675-
qCInfo(npackd).noquote() << QObject::tr("Killing the process \"%1\"").
1676-
arg(getProcessFile(hProc));
1690+
if (processId == me)
1691+
continue;
16771692

1678-
// TerminateProcess is asynchronous
1679-
if (TerminateProcess(hProc, 1000))
1680-
WaitForSingleObject(hProc, 30000);
1693+
if (!WPMUtils::isProcessRunning(hProc))
1694+
continue;
16811695

1682-
changed = true;
1683-
}
1696+
QString processFile = getProcessFile(hProc);
1697+
if (processFile.isEmpty() || pathEquals(explorer, processFile))
1698+
continue;
1699+
1700+
qCInfo(npackd).noquote() << QObject::tr("Killing the process \"%1\"").
1701+
arg(getProcessFile(hProc));
1702+
1703+
// TerminateProcess is asynchronous
1704+
if (TerminateProcess(hProc, 1000))
1705+
WaitForSingleObject(hProc, 30000);
1706+
1707+
changed = true;
16841708
}
16851709

16861710
if (changed) {
@@ -1813,7 +1837,9 @@ void WPMUtils::closeProcessWindows(HANDLE process,
18131837
if ((GetWindowLong(w, GWL_STYLE) & WS_DISABLED) == 0) {
18141838
//qCDebug(npackd) << "WM_CLOSE to " <<
18151839
// GetProcessId(process) << getClassName(w);
1816-
qCInfo(npackd).noquote() << QObject::tr("Sending a WM_CLOSE event to \"%1\"").
1840+
qCInfo(npackd).noquote() << QObject::tr("Sending a WM_CLOSE event to the window of "
1841+
"the class \"%1\" from the process \"%2\"").
1842+
arg(getClassName(w)).
18171843
arg(getProcessFile(process));
18181844
PostMessage(w, WM_CLOSE, 0, 0);
18191845
}
@@ -1855,9 +1881,7 @@ QString WPMUtils::getProcessFile(HANDLE hProcess)
18551881
res.resize(MAX_PATH + 1);
18561882
DWORD r = GetModuleFileNameEx(hProcess, nullptr, (LPWSTR) res.data(),
18571883
res.length());
1858-
if (r != 0) {
1859-
res.resize(r);
1860-
}
1884+
res.resize(r);
18611885

18621886
return res;
18631887
}

0 commit comments

Comments
 (0)