From ae84363b1feaefbd434bb5a744d101e4516bf191 Mon Sep 17 00:00:00 2001 From: wj32 Date: Tue, 30 Mar 2010 11:15:53 +0000 Subject: [PATCH] * use TPM_RETURNCMD instead of IDDYNAMIC * fixed memory leak git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3001 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/ProcessHacker/runas.c | 43 +++++++++++++++++++-------------- 2.x/trunk/phlib/guisup.c | 20 +++++++++++++++ 2.x/trunk/phlib/include/phgui.h | 7 ++++++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/2.x/trunk/ProcessHacker/runas.c b/2.x/trunk/ProcessHacker/runas.c index ce98ed77c..bad443127 100644 --- a/2.x/trunk/ProcessHacker/runas.c +++ b/2.x/trunk/ProcessHacker/runas.c @@ -216,6 +216,12 @@ INT_PTR CALLBACK PhpRunAsDlgProc( SendMessage(GetDlgItem(hwndDlg, IDOK), BCM_SETSHIELD, 0, TRUE); } break; + case WM_DESTROY: + { + if (context->SessionIdList) + PhDereferenceObject(context->SessionIdList); + } + break; case WM_COMMAND: { switch (LOWORD(wParam)) @@ -352,6 +358,7 @@ INT_PTR CALLBACK PhpRunAsDlgProc( ULONG i; RECT buttonRect; POINT point; + UINT selectedItem; sessionsMenu = CreatePopupMenu(); @@ -415,7 +422,7 @@ INT_PTR CALLBACK PhpRunAsDlgProc( menuString = PhFormatString(L"%u", sessions[i].SessionId); } - AppendMenu(sessionsMenu, MF_STRING, IDDYNAMIC + i, menuString->Buffer); + AppendMenu(sessionsMenu, MF_STRING, 1 + i, menuString->Buffer); PhDereferenceObject(menuString); PhAddListItem(context->SessionIdList, (PVOID)sessions[i].SessionId); @@ -426,28 +433,28 @@ INT_PTR CALLBACK PhpRunAsDlgProc( GetClientRect(GetDlgItem(hwndDlg, IDC_SESSIONS), &buttonRect); point.x = buttonRect.right; point.y = 0; - PhShowContextMenu(hwndDlg, GetDlgItem(hwndDlg, IDC_SESSIONS), sessionsMenu, point); + + selectedItem = PhShowContextMenu2( + hwndDlg, + GetDlgItem(hwndDlg, IDC_SESSIONS), + sessionsMenu, + point + ); + + if (selectedItem != 0) + { + SetDlgItemInt( + hwndDlg, + IDC_SESSIONID, + (ULONG)context->SessionIdList->Items[selectedItem - 1], + FALSE + ); + } DestroyMenu(sessionsMenu); } } break; - default: - { - if (LOWORD(wParam) >= IDDYNAMIC) - { - ULONG index = LOWORD(wParam) - IDDYNAMIC; - - if (context->SessionIdList && index < context->SessionIdList->Count) - { - ULONG sessionId; - - sessionId = (ULONG)context->SessionIdList->Items[index]; - SetDlgItemInt(hwndDlg, IDC_SESSIONID, sessionId, FALSE); - } - } - } - break; } } break; diff --git a/2.x/trunk/phlib/guisup.c b/2.x/trunk/phlib/guisup.c index 01ab48b57..81b1ff3cb 100644 --- a/2.x/trunk/phlib/guisup.c +++ b/2.x/trunk/phlib/guisup.c @@ -349,6 +349,26 @@ VOID PhShowContextMenu( ); } +UINT PhShowContextMenu2( + __in HWND hwnd, + __in HWND subHwnd, + __in HMENU menu, + __in POINT point + ) +{ + ClientToScreen(subHwnd, &point); + + return (UINT)TrackPopupMenu( + menu, + TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, + point.x, + point.y, + 0, + hwnd, + NULL + ); +} + VOID PhSetRadioCheckMenuItem( __in HMENU Menu, __in ULONG Id, diff --git a/2.x/trunk/phlib/include/phgui.h b/2.x/trunk/phlib/include/phgui.h index 070095e5c..2d43f980a 100644 --- a/2.x/trunk/phlib/include/phgui.h +++ b/2.x/trunk/phlib/include/phgui.h @@ -273,6 +273,13 @@ VOID PhShowContextMenu( __in POINT point ); +UINT PhShowContextMenu2( + __in HWND hwnd, + __in HWND subHwnd, + __in HMENU menu, + __in POINT point + ); + VOID PhSetRadioCheckMenuItem( __in HMENU Menu, __in ULONG Id,