Process Hacker
misc.c
Go to the documentation of this file.
1 /*
2  * Process Hacker -
3  * PE viewer
4  *
5  * Copyright (C) 2011 wj32
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #define CINTERFACE
24 #define COBJMACROS
25 #include <peview.h>
26 #include <shobjidl.h>
27 #undef CINTERFACE
28 #undef COBJMACROS
29 #include <cpysave.h>
30 
31 static GUID CLSID_ShellLink_I = { 0x00021401, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
32 static GUID IID_IShellLinkW_I = { 0x000214f9, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
33 static GUID IID_IPersistFile_I = { 0x0000010b, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
34 
36  _In_ PPH_STRING ShortcutFileName
37  )
38 {
39  PPH_STRING targetFileName;
40  IShellLinkW *shellLink;
41  IPersistFile *persistFile;
42  WCHAR path[MAX_PATH];
43 
44  targetFileName = NULL;
45 
46  if (SUCCEEDED(CoCreateInstance(&CLSID_ShellLink_I, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW_I, &shellLink)))
47  {
48  if (SUCCEEDED(IShellLinkW_QueryInterface(shellLink, &IID_IPersistFile_I, &persistFile)))
49  {
50  if (SUCCEEDED(IPersistFile_Load(persistFile, ShortcutFileName->Buffer, STGM_READ)) &&
51  SUCCEEDED(IShellLinkW_Resolve(shellLink, NULL, SLR_NO_UI)))
52  {
53  if (SUCCEEDED(IShellLinkW_GetPath(shellLink, path, MAX_PATH, NULL, 0)))
54  {
55  targetFileName = PhCreateString(path);
56  }
57  }
58 
59  IPersistFile_Release(persistFile);
60  }
61 
62  IShellLinkW_Release(shellLink);
63  }
64 
65  return targetFileName;
66 }
67 
68 // Copied from appsup.c
69 
71  _In_ HWND ListViewHandle
72  )
73 {
74  PPH_STRING text;
75 
76  text = PhGetListViewText(ListViewHandle);
77  PhSetClipboardString(ListViewHandle, &text->sr);
78  PhDereferenceObject(text);
79 }
80 
82  _In_ LPARAM lParam,
83  _In_ HWND ListViewHandle
84  )
85 {
86  if (((LPNMHDR)lParam)->hwndFrom == ListViewHandle && ((LPNMHDR)lParam)->code == LVN_KEYDOWN)
87  {
88  LPNMLVKEYDOWN keyDown = (LPNMLVKEYDOWN)lParam;
89 
90  switch (keyDown->wVKey)
91  {
92  case 'C':
93  if (GetKeyState(VK_CONTROL) < 0)
94  PvCopyListView(ListViewHandle);
95  break;
96  case 'A':
97  if (GetKeyState(VK_CONTROL) < 0)
98  PhSetStateAllListViewItems(ListViewHandle, LVIS_SELECTED, LVIS_SELECTED);
99  break;
100  }
101  }
102 }