Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
15 KiB

  1. // ProgView.h : Declaration of the CProgView
  2. #ifndef __PROGVIEW_H_
  3. #define __PROGVIEW_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. #include <shlobj.h>
  7. /////////////////// SHIMDB
  8. extern "C" {
  9. #include "shimdb.h"
  10. }
  11. /////////////////// STL
  12. class CProgramList;
  13. class CProgView;
  14. //
  15. // Program list stuff
  16. //
  17. BOOL
  18. GetProgramListSelection(
  19. CProgramList* pProgramList
  20. );
  21. BOOL
  22. InitializeProgramList(
  23. CProgramList** ppProgramList,
  24. HWND hwndListView
  25. );
  26. BOOL
  27. CleanupProgramList(
  28. CProgramList* pProgramList
  29. );
  30. BOOL
  31. PopulateProgramList(
  32. CProgramList* pProgramList,
  33. CProgView* pProgView,
  34. HANDLE hEventCancel
  35. );
  36. BOOL
  37. GetProgramListSelectionDetails(
  38. CProgramList* pProgramList,
  39. INT iInformationClass,
  40. LPWSTR pBuffer,
  41. ULONG Size
  42. );
  43. LRESULT
  44. NotifyProgramList(
  45. CProgramList* pProgramList,
  46. LPNMHDR pnmhdr,
  47. BOOL& bHandled
  48. );
  49. BOOL
  50. GetProgramListEnabled(
  51. CProgramList* pProgramList
  52. );
  53. VOID
  54. EnableProgramList(
  55. CProgramList* pProgramList,
  56. BOOL bEnable
  57. );
  58. BOOL
  59. UpdateProgramListItem(
  60. CProgramList* pProgramList,
  61. LPCWSTR pwszPath,
  62. LPCWSTR pwszKeys
  63. );
  64. INT_PTR CALLBACK
  65. Dialog_GetProgFromList(
  66. HWND hwnd,
  67. UINT Message,
  68. WPARAM wparam,
  69. LPARAM lparam
  70. );
  71. #define WM_VIEW_CHANGED (WM_USER+500)
  72. #define WM_LIST_POPULATED (WM_USER+501)
  73. //
  74. // wait for the thread to cleanup
  75. //
  76. #define POPULATE_THREAD_TIMEOUT 1000
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CProgView
  79. class CProgView
  80. {
  81. public:
  82. typedef enum {
  83. CMD_EXIT,
  84. CMD_CLEANUP,
  85. CMD_SCAN,
  86. CMD_NONE
  87. } PopulateCmdType;
  88. CProgView() : m_Safe(TRUE)
  89. {
  90. m_pProgramList = NULL;
  91. m_bPendingPopulate = FALSE;
  92. // m_bRecomposeOnResize = TRUE;
  93. m_PopulateInProgress = FALSE;
  94. m_nCmdPopulate = CMD_NONE;
  95. m_hEventCancel = CreateEvent(NULL, TRUE, FALSE, NULL);
  96. //
  97. // handle error -- we are big time in trouble if this fails
  98. //
  99. m_hEventCmd = CreateEvent(NULL, FALSE, FALSE, NULL);
  100. //
  101. // same
  102. //
  103. m_hThreadPopulate = NULL;
  104. m_pMallocUI = NULL;
  105. //
  106. // create accelerator
  107. //
  108. ACCEL rgAccel[] = { { FVIRTKEY, VK_F5, IDC_REFRESH } };
  109. m_hAccel = CreateAcceleratorTable(rgAccel, ARRAYSIZE(rgAccel));
  110. }
  111. ~CProgView() {
  112. if (m_hAccel) {
  113. DestroyAcceleratorTable(m_hAccel);
  114. }
  115. if (m_hEventCancel) {
  116. SetEvent(m_hEventCancel);
  117. CloseHandle(m_hEventCancel);
  118. }
  119. if (m_hEventCmd) {
  120. m_nCmdPopulate = CMD_EXIT;
  121. SetEvent(m_hEventCmd);
  122. CloseHandle(m_hEventCmd);
  123. }
  124. if (m_hThreadPopulate) {
  125. WaitForSingleObject(m_hThreadPopulate, POPULATE_THREAD_TIMEOUT);
  126. CloseHandle(m_hThreadPopulate);
  127. }
  128. if (m_pMallocUI) {
  129. m_pMallocUI->Release();
  130. }
  131. }
  132. #if 0
  133. BEGIN_MSG_MAP(CProgView)
  134. NOTIFY_ID_HANDLER(IDC_FILE_LIST, OnNotifyListView)
  135. NOTIFY_HANDLER(IDC_FILE_LIST, NM_DBLCLK, OnDblclkListprograms)
  136. MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate)
  137. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  138. MESSAGE_HANDLER(WM_VIEW_CHANGED, OnViewChanged)
  139. MESSAGE_HANDLER(WM_LIST_POPULATED, OnListPopulated)
  140. MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode)
  141. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  142. // COMMAND_ID_HANDLER(IDC_REFRESH, OnRefreshListCmd)
  143. CHAIN_MSG_MAP(CComCompositeControl<CProgView>)
  144. END_MSG_MAP()
  145. // Handler prototypes:
  146. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  147. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  148. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  149. BEGIN_SINK_MAP(CProgView)
  150. //Make sure the Event Handlers have __stdcall calling convention
  151. END_SINK_MAP()
  152. BEGIN_CONNECTION_POINT_MAP(CProgView)
  153. CONNECTION_POINT_ENTRY(DIID__IProgViewEvents)
  154. CONNECTION_POINT_ENTRY(DIID__ISelectFileEvents)
  155. END_CONNECTION_POINT_MAP()
  156. STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
  157. {
  158. if (dispid == DISPID_AMBIENT_BACKCOLOR)
  159. {
  160. SetBackgroundColorFromAmbient();
  161. FireViewChange();
  162. }
  163. return IOleControlImpl<CProgView>::OnAmbientPropertyChange(dispid);
  164. }
  165. HRESULT FireOnChanged(DISPID dispID) {
  166. if (dispID == DISPID_ENABLED) {
  167. HWND hwndList = GetDlgItem(IDC_FILE_LIST);
  168. if (::IsWindow(hwndList)) {
  169. ::EnableWindow(hwndList, m_bEnabled);
  170. }
  171. }
  172. return S_OK;
  173. }
  174. STDMETHOD(GetControlInfo)(CONTROLINFO* pCI) {
  175. if (NULL == pCI) {
  176. return E_POINTER;
  177. }
  178. pCI->cb = sizeof(*pCI);
  179. pCI->hAccel = m_hAccel;
  180. pCI->cAccel = 1;
  181. pCI->dwFlags = 0;
  182. return S_OK;
  183. }
  184. STDMETHOD(OnMnemonic)(LPMSG pMsg) {
  185. if (pMsg->message == WM_COMMAND || pMsg->message == WM_SYSCOMMAND) {
  186. if (LOWORD(pMsg->wParam) == IDC_REFRESH) {
  187. PopulateList();
  188. }
  189. }
  190. return S_OK;
  191. }
  192. HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect = NULL);
  193. #endif // 0
  194. LRESULT OnNotifyListView(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  195. LRESULT OnDblclkListprograms(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  196. LRESULT OnMouseActivate(UINT, WPARAM, LPARAM, BOOL&) {
  197. // Manually activate the control
  198. // InPlaceActivate(OLEIVERB_UIACTIVATE);
  199. return 0;
  200. }
  201. #if 0
  202. STDMETHOD(InPlaceDeactivate)(VOID) {
  203. HRESULT hr = IOleInPlaceObjectWindowlessImpl<CProgView>::InPlaceDeactivate();
  204. //
  205. // make sure we cancel first if we are scanning
  206. //
  207. return hr;
  208. }
  209. STDMETHOD(SetExtent)(DWORD dwDrawAspect, SIZEL* psizel) {
  210. if (IsWindow()) {
  211. HWND hlvPrograms = GetDlgItem(IDC_FILE_LIST);
  212. SIZEL sizePix;
  213. AtlHiMetricToPixel(psizel, &sizePix);
  214. ::SetWindowPos(hlvPrograms, NULL, 0, 0,
  215. sizePix.cx, sizePix.cy,
  216. SWP_NOZORDER|SWP_NOACTIVATE);
  217. /*
  218. ::SetWindowPos(hlvPrograms, NULL, 0, 0,
  219. m_rcPos.right - m_rcPos.left,
  220. m_rcPos.bottom - m_rcPos.top,
  221. SWP_NOZORDER|SWP_NOACTIVATE);
  222. */
  223. }
  224. HRESULT hr = IOleObjectImpl<CProgView>::SetExtent(dwDrawAspect, psizel);
  225. return hr;
  226. }
  227. #endif
  228. LRESULT OnGetDlgCode(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  229. {
  230. // TODO : Add Code for message handler. Call DefWindowProc if necessary.
  231. if (lParam) {
  232. LPMSG pMsg = (LPMSG)lParam;
  233. if (pMsg->message == WM_SYSKEYDOWN || pMsg->message == WM_SYSCHAR) { // eat accel ?
  234. bHandled = TRUE;
  235. return DLGC_WANTMESSAGE;
  236. }
  237. }
  238. bHandled = TRUE;
  239. return DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_WANTALLKEYS;
  240. }
  241. #if 0
  242. STDMETHOD(SetObjectRects)(LPCRECT prcPos, LPCRECT prcClip) {
  243. HWND hlvPrograms = GetDlgItem(m_hwnd, IDC_FILE_LIST);
  244. IOleInPlaceObjectWindowlessImpl<CProgView>::SetObjectRects(prcPos, prcClip);
  245. ::SetWindowPos(hlvPrograms, NULL, 0, 0,
  246. prcPos->right - prcPos->left,
  247. prcPos->bottom - prcPos->top,
  248. SWP_NOZORDER|SWP_NOACTIVATE);
  249. HWND hwnd;
  250. RECT rc;
  251. hwnd = GetDlgItem(IDC_SEARCH_STATUS);
  252. ::GetWindowRect(hwnd, &rc);
  253. //
  254. // we are happy with location, just set the width
  255. //
  256. ScreenToClient(m_hwnd, (LPPOINT)&rc);
  257. ScreenToClient(m_hwnd, ((LPPOINT)&rc) + 1);
  258. ::SetWindowPos(hwnd, NULL,
  259. rc.left, rc.top,
  260. prcPos->right - prcPos->left - rc.left,
  261. rc.bottom - rc.top,
  262. SWP_NOZORDER|SWP_NOACTIVATE);
  263. hwnd = GetDlgItem(m_hwnd, IDC_SEARCH_STATUS2);
  264. ::GetWindowRect(hwnd, &rc);
  265. //
  266. // we are happy with location, just set the width
  267. //
  268. ScreenToClient(m_hwnd, (LPPOINT)&rc);
  269. ScreenToClient(m_hwnd, ((LPPOINT)&rc) + 1);
  270. ::SetWindowPos(hwnd, NULL,
  271. rc.left, rc.top,
  272. prcPos->right - prcPos->left - rc.left,
  273. rc.bottom - rc.top,
  274. SWP_NOZORDER|SWP_NOACTIVATE);
  275. return S_OK;
  276. }
  277. #endif //0
  278. BOOL PreTranslateAccelerator(LPMSG pMsg, HRESULT& hrRet);
  279. #if 0
  280. static CWndClassInfo& GetWndClassInfo() {
  281. DebugBreak();
  282. static CWndClassInfo wc = CWindowImpl<CProgView>::GetWndClassInfo();
  283. wc.m_wc.style &= ~(CS_HREDRAW|CS_VREDRAW);
  284. return wc;
  285. }
  286. BOOL PreTranslateAccelerator(LPMSG pMsg, HRESULT& hrRet) {
  287. HWND hwndList = GetDlgItem(IDC_FILE_LIST);
  288. HWND hwndFocus = GetFocus();
  289. if (hwndList != hwndFocus || !::IsWindowEnabled(hwndList)) {
  290. goto PropagateAccel;
  291. }
  292. if (pMsg->message == WM_KEYDOWN) {
  293. if (pMsg->wParam == VK_LEFT ||
  294. pMsg->wParam == VK_RIGHT ||
  295. pMsg->wParam == VK_UP ||
  296. pMsg->wParam == VK_DOWN) {
  297. SendDlgItemMessage(IDC_FILE_LIST, pMsg->message, pMsg->wParam, pMsg->lParam);
  298. hrRet = S_OK;
  299. return TRUE;
  300. }
  301. if (LOWORD(pMsg->wParam) == VK_RETURN || LOWORD(pMsg->wParam) == VK_EXECUTE) {
  302. if (ListView_GetNextItem(hwndList, -1, LVNI_SELECTED) >= 0) {
  303. Fire_DblClk(0);
  304. hrRet = S_OK;
  305. return TRUE;
  306. }
  307. }
  308. if (LOWORD(pMsg->wParam) == VK_TAB) {
  309. goto PropagateAccel;
  310. }
  311. }
  312. if (IsDialogMessage(pMsg)) {
  313. hrRet = S_OK;
  314. return TRUE;
  315. }
  316. if (::TranslateAccelerator(m_hwnd, NULL, pMsg)) {
  317. hrRet = S_OK;
  318. return TRUE;
  319. }
  320. PropagateAccel:
  321. return FALSE;
  322. }
  323. #endif
  324. // IProgView
  325. public:
  326. #if 0
  327. STDMETHOD(get_ExcludeFiles)(/*[out, retval]*/ BSTR* pVal);
  328. STDMETHOD(put_ExcludeFiles)(/*[in]*/ BSTR newVal);
  329. STDMETHOD(get_ExternAccel)(/*[out, retval]*/ BSTR *pVal);
  330. STDMETHOD(put_ExternAccel)(/*[in]*/ BSTR newVal);
  331. STDMETHOD(get_Accel)(/*[out, retval]*/ BSTR *pVal);
  332. STDMETHOD(put_Accel)(/*[in]*/ BSTR newVal);
  333. #endif
  334. STDMETHOD(CancelPopulateList)();
  335. STDMETHOD(UpdateListItem)(/*[in]*/BSTR pTarget, /*[in]*/VARIANT* pKeys, /*[out, retval]*/ BOOL* pResult);
  336. STDMETHOD(PopulateList)();
  337. STDMETHOD(GetSelectionInformation)(LONG, LPWSTR pBuffer, ULONG Size);
  338. STDMETHOD(get_SelectionName)(LPWSTR pBuffer, ULONG Size);
  339. STDMETHOD(GetSelectedItem)();
  340. #if 0
  341. STDMETHOD(ClearAccel)();
  342. STDMETHOD(ClearExternAccel)();
  343. STDMETHOD(get_AccelCmd)(/*[in]*/ LONG lCmd, /*[out, retval]*/ BSTR *pVal);
  344. STDMETHOD(put_AccelCmd)(/*[in]*/ LONG lCmd, /*[in]*/ BSTR newVal);
  345. #endif
  346. STDMETHOD(get_ItemCount)(/*[out, retval]*/VARIANT* pItemCount);
  347. BOOL m_bEnabled;
  348. // Security - To be implemented
  349. BOOL m_Safe; // set to true if we were able to verify the host
  350. BOOL m_bPendingPopulate;
  351. CProgramList* m_pProgramList;
  352. enum { IDD = IDD_PROGRAM_LIST_DIALOG };
  353. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled) {
  354. /*
  355. DWORD dwStyle = (DWORD)GetClassLong(m_hWnd, GCL_STYLE);
  356. dwStyle &= ~(CS_HREDRAW | CS_VREDRAW);
  357. SetClassLong(m_hWnd, GCL_STYLE, dwStyle);
  358. */
  359. //
  360. // before we start messing around with this... obtain malloc for the UI thread
  361. //
  362. HRESULT hr = SHGetMalloc(&m_pMallocUI);
  363. if (!SUCCEEDED(hr)) {
  364. //
  365. // aww -- ui malloc will not be available -- we're pretty much hosed
  366. //
  367. m_pMallocUI = NULL;
  368. }
  369. m_wszRetFileName = (LPWSTR) lParam;
  370. PopulateList();
  371. return 0;
  372. }
  373. static DWORD WINAPI _PopulateThreadProc(LPVOID lpvParam);
  374. VOID UpdatePopulateStatus(LPCTSTR lpszName, LPCTSTR lpszPath) {
  375. SetDlgItemText(m_hwnd, IDC_SEARCH_STATUS2, lpszName);
  376. ::PathSetDlgItemPath(m_hwnd, IDC_SEARCH_STATUS3, lpszPath);
  377. }
  378. VOID ShowProgressWindows(BOOL bProgress = FALSE);
  379. LRESULT OnViewChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
  380. // FireViewChange();
  381. bHandled = TRUE;
  382. return 0;
  383. }
  384. LRESULT OnListPopulated(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
  385. // Fire_ProgramListReady();
  386. bHandled = TRUE;
  387. return 0;
  388. }
  389. BOOL PopulateListInternal();
  390. HANDLE m_hEventCancel;
  391. LONG m_PopulateInProgress;
  392. HANDLE m_hEventCmd;
  393. PopulateCmdType m_nCmdPopulate;
  394. HANDLE m_hThreadPopulate;
  395. IMalloc* m_pMallocUI;
  396. HACCEL m_hAccel;
  397. HWND m_hwnd;
  398. LPWSTR m_wszRetFileName;
  399. BOOL IsScanInProgress(VOID) {
  400. return InterlockedCompareExchange(&m_PopulateInProgress, TRUE, TRUE) == TRUE;
  401. }
  402. /*
  403. LRESULT OnRefreshListCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
  404. PopulateList();
  405. bHandled = TRUE;
  406. return 0;
  407. }
  408. */
  409. //
  410. // accelerators
  411. //
  412. // CAccelContainer m_Accel; // my own accelerator
  413. // CAccelContainer m_ExternAccel; // external accels
  414. LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  415. {
  416. // InPlaceActivate(OLEIVERB_UIACTIVATE);
  417. //
  418. // if we are scanning then we don't need to do anything, else - set the focus to listview
  419. //
  420. if (!IsScanInProgress()) {
  421. ::SetFocus(GetDlgItem(m_hwnd, IDC_FILE_LIST));
  422. }
  423. return 0;
  424. // return CComCompositeControl<CProgView>::OnSetFocus(uMsg, wParam, lParam, bHandled);
  425. }
  426. LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
  427. LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
  428. //
  429. // blacklisted files
  430. //
  431. #if 0
  432. typedef set<wstring> STRSET;
  433. STRSET m_ExcludedFiles;
  434. //
  435. // check whether a file is excluded
  436. //
  437. BOOL IsFileExcluded(LPCTSTR pszFile);
  438. #endif
  439. };
  440. typedef enum tagPROGRAMINFOCLASS {
  441. PROGLIST_DISPLAYNAME,
  442. PROGLIST_LOCATION, //
  443. PROGLIST_EXENAME, // cracked exe name
  444. PROGLIST_CMDLINE, // complete exe name + parameters
  445. PROGLIST_EXECUTABLE, // what we should execute (link or exe, not cracked)
  446. PROGLIST_ARGUMENTS // just the args
  447. };
  448. #endif //__PROGVIEW_H_