Skip to content

Commit 6dfc9dd

Browse files
committed
Fix options window parenting
1 parent e13ce47 commit 6dfc9dd

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
lines changed

ProcessHacker/include/phplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ typedef struct _PH_OPTIONS_SECTION
370370
PVOID Parameter;
371371

372372
HWND DialogHandle;
373+
HTREEITEM TreeItemHandle;
373374
// begin_phapppub
374375
} PH_OPTIONS_SECTION, *PPH_OPTIONS_SECTION;
375376
// end_phapppub

ProcessHacker/options.c

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ VOID PhShowOptionsDialog(
175175
DialogBox(
176176
PhInstanceHandle,
177177
MAKEINTRESOURCE(IDD_OPTIONS),
178-
ParentWindowHandle,
178+
NULL,
179179
PhOptionsDialogProc
180180
);
181181

@@ -211,18 +211,18 @@ VOID PhShowOptionsDialog(
211211
}
212212
}
213213

214-
static HTREEITEM PhpOptionsTreeViewAddItem(
214+
static HTREEITEM PhpTreeViewInsertItem(
215+
_In_opt_ HTREEITEM HandleInsertAfter,
215216
_In_ PWSTR Text,
216-
_In_ PVOID Context,
217-
_In_ HTREEITEM InsertAfter
217+
_In_ PVOID Context
218218
)
219219
{
220220
TV_INSERTSTRUCT insert;
221221

222222
memset(&insert, 0, sizeof(TV_INSERTSTRUCT));
223223

224224
insert.hParent = TVI_ROOT;
225-
insert.hInsertAfter = InsertAfter;
225+
insert.hInsertAfter = HandleInsertAfter;
226226
insert.item.mask = TVIF_TEXT | TVIF_PARAM;
227227
insert.item.pszText = Text;
228228
insert.item.lParam = (LPARAM)Context;
@@ -234,52 +234,36 @@ static VOID PhpOptionsShowHideTreeViewItem(
234234
_In_ BOOLEAN Hide
235235
)
236236
{
237-
HTREEITEM tvItemGeneral = NULL;
238-
HTREEITEM tvItemAdvanced = NULL;
239-
HTREEITEM tvItemCurrent;
240-
241-
tvItemCurrent = TreeView_GetRoot(OptionsTreeControl);
237+
static PH_STRINGREF generalName = PH_STRINGREF_INIT(L"General");
238+
static PH_STRINGREF advancedName = PH_STRINGREF_INIT(L"Advanced");
242239

243-
while (tvItemCurrent)
240+
if (Hide)
244241
{
245-
TVITEM tvItem;
246-
WCHAR buffer[MAX_PATH];
247-
248-
tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
249-
tvItem.hItem = tvItemCurrent;
250-
tvItem.cchTextMax = ARRAYSIZE(buffer);
251-
tvItem.pszText = buffer;
242+
PPH_OPTIONS_SECTION advancedSection;
252243

253-
if (TreeView_GetItem(OptionsTreeControl, &tvItem))
244+
if (advancedSection = PhOptionsFindSection(&advancedName))
254245
{
255-
if (PhEqualStringZ(buffer, L"Advanced", TRUE))
246+
if (advancedSection->TreeItemHandle)
256247
{
257-
tvItemAdvanced = tvItemCurrent;
258-
}
259-
else if (PhEqualStringZ(buffer, L"General", TRUE))
260-
{
261-
tvItemGeneral = tvItemCurrent;
248+
TreeView_DeleteItem(OptionsTreeControl, advancedSection->TreeItemHandle);
249+
advancedSection->TreeItemHandle = NULL;
262250
}
263251
}
264-
265-
tvItemCurrent = TreeView_GetNextSibling(OptionsTreeControl, tvItemCurrent);
266-
}
267-
268-
if (Hide)
269-
{
270-
if (tvItemAdvanced)
271-
TreeView_DeleteItem(OptionsTreeControl, tvItemAdvanced);
272252
}
273253
else
274254
{
275-
static PH_STRINGREF sectionName = PH_STRINGREF_INIT(L"Advanced");
255+
PPH_OPTIONS_SECTION generalSection;
256+
PPH_OPTIONS_SECTION advancedSection;
257+
258+
generalSection = PhOptionsFindSection(&generalName);
259+
advancedSection = PhOptionsFindSection(&advancedName);
276260

277-
if (tvItemGeneral)
261+
if (generalSection && advancedSection)
278262
{
279-
PhpOptionsTreeViewAddItem(
280-
sectionName.Buffer,
281-
PhOptionsFindSection(&sectionName),
282-
tvItemGeneral
263+
advancedSection->TreeItemHandle = PhpTreeViewInsertItem(
264+
generalSection->TreeItemHandle,
265+
advancedName.Buffer,
266+
advancedSection
283267
);
284268
}
285269
}
@@ -547,11 +531,10 @@ PPH_OPTIONS_SECTION PhOptionsCreateSection(
547531
section->Template = Template;
548532
section->DialogProc = DialogProc;
549533
section->Parameter = Parameter;
534+
section->TreeItemHandle = PhpTreeViewInsertItem(TVI_LAST, Name, section);
550535

551536
PhAddItemList(SectionList, section);
552537

553-
PhpOptionsTreeViewAddItem(Name, section, TVI_LAST);
554-
555538
return section;
556539
}
557540

0 commit comments

Comments
 (0)