Skip to content

Commit ac636d3

Browse files
committed
fixed dangeling pointer in repaintPanelContents()
1 parent 1c37c00 commit ac636d3

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/MultiReplacePanel.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,8 @@ void MultiReplace::updateListViewFrame()
578578
MoveWindow(lv, ci.x, ci.y, ci.cx, ci.cy, TRUE);
579579
}
580580

581-
void MultiReplace::repaintPanelContents(HWND hGrp, const wchar_t* title)
581+
void MultiReplace::repaintPanelContents(HWND hGrp, const std::wstring& title)
582582
{
583-
// The control IDs within the panel.
584583
static const std::vector<int> repInFilesIds = {
585584
IDC_REPLACE_IN_FILES_GROUP,
586585
IDC_FILTER_STATIC, IDC_FILTER_EDIT, IDC_FILTER_HELP,
@@ -589,26 +588,25 @@ void MultiReplace::repaintPanelContents(HWND hGrp, const wchar_t* title)
589588
IDC_CANCEL_REPLACE_BUTTON
590589
};
591590

592-
// Update the title
593-
SetDlgItemText(_hSelf, IDC_REPLACE_IN_FILES_GROUP, title);
591+
// WICHTIG: Jetzt immer eine stabile Kopie verwenden
592+
SetDlgItemText(_hSelf, IDC_REPLACE_IN_FILES_GROUP, title.c_str());
594593

595-
// Get the panel's rectangle in the parent dialog's coordinates
596594
RECT rcGrp;
597595
GetWindowRect(hGrp, &rcGrp);
598596
MapWindowPoints(HWND_DESKTOP, _hSelf, reinterpret_cast<LPPOINT>(&rcGrp), 2);
599597

600-
// 1. Erase the parent's background behind the panel to prevent artifacts
601-
RedrawWindow(_hSelf, &rcGrp, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN);
598+
RedrawWindow(_hSelf, &rcGrp, NULL,
599+
RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN);
602600

603-
// 2. Redraw the group box's frame and title without erasing its background (no flicker)
604-
RedrawWindow(hGrp, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOERASE | RDW_NOCHILDREN | RDW_FRAME);
601+
RedrawWindow(hGrp, NULL, NULL,
602+
RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOERASE | RDW_NOCHILDREN | RDW_FRAME);
605603

606-
// 3. Redraw all visible child controls inside the panel
607604
for (int id : repInFilesIds) {
608605
if (id == IDC_REPLACE_IN_FILES_GROUP) continue;
609606
HWND hChild = GetDlgItem(_hSelf, id);
610607
if (IsWindow(hChild) && IsWindowVisible(hChild)) {
611-
RedrawWindow(hChild, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOERASE);
608+
RedrawWindow(hChild, NULL, NULL,
609+
RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOERASE);
612610
}
613611
}
614612
}
@@ -632,18 +630,18 @@ void MultiReplace::updateReplaceInFilesVisibility()
632630
const bool show = (isReplaceInFiles || isFindAllInFiles) && !twoButtonsMode;
633631

634632
// Determine title for the group box
635-
const wchar_t* titlePtr = nullptr;
636633
std::wstring titleKey;
634+
std::wstring titleText;
637635
if (isReplaceInFiles && isFindAllInFiles) {
638-
titlePtr = LM.getLPW(L"panel_find_replace_in_files");
636+
titleText = LM.get(L"panel_find_replace_in_files");
639637
titleKey = L"panel_find_replace_in_files";
640638
}
641639
else if (isFindAllInFiles) {
642-
titlePtr = LM.getLPW(L"panel_find_in_files");
640+
titleText = LM.get(L"panel_find_in_files");
643641
titleKey = L"panel_find_in_files";
644642
}
645643
else {
646-
titlePtr = LM.getLPW(L"panel_replace_in_files");
644+
titleText = LM.get(L"panel_replace_in_files");
647645
titleKey = L"panel_replace_in_files";
648646
}
649647

@@ -681,7 +679,7 @@ void MultiReplace::updateReplaceInFilesVisibility()
681679

682680
if (show) {
683681
// handles the complete repaint logic for showing the panel.
684-
repaintPanelContents(hGrp, titlePtr);
682+
repaintPanelContents(hGrp, titleText);
685683
}
686684
else {
687685
// HIDE: This logic is specific to cleaning up and must remain.
@@ -729,7 +727,7 @@ void MultiReplace::updateReplaceInFilesVisibility()
729727
{
730728
// *** ERSETZT ***
731729
// The helper function also handles the repaint logic for a simple title change.
732-
repaintPanelContents(hGrp, titlePtr);
730+
repaintPanelContents(hGrp, titleText);
733731
lastTitleKey = titleKey;
734732
}
735733
}

src/MultiReplacePanel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ class MultiReplace : public StaticDialog
664664
void moveAndResizeControls();
665665
void updateTwoButtonsVisibility();
666666
void updateListViewFrame();
667-
void repaintPanelContents(HWND hGrp, const wchar_t* title);
667+
void MultiReplace::repaintPanelContents(HWND hGrp, const std::wstring& title);
668668
void updateReplaceInFilesVisibility();
669669
void setUIElementVisibility();
670670
void drawGripper();

0 commit comments

Comments
 (0)