MainFrm.cpp
上传用户:jstlsd
上传日期:2007-01-13
资源大小:186k
文件大小:4k
源码类别:

钩子与API截获

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. //
  3. // MainFrm.cpp
  4. //
  5. // SUBSYSTEM:   Hook system
  6. //
  7. // MODULE:      Hook server
  8. //
  9. // DESCRIPTION: Implementation of the CMainFrame class
  10. //             
  11. // AUTHOR: Ivo Ivanov (ivopi@hotmail.com)
  12. // DATE: 2001 December v1.00
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "HookSrv.h"
  17. #include "MainFrm.h"
  18. #include "..CommonCustomMessages.h"
  19. //---------------------------------------------------------------------------
  20. //
  21. // Constants
  22. // 
  23. //---------------------------------------------------------------------------
  24. // Message ID used for tray notifications
  25. #define WM_MY_TRAY_NOTIFICATION WM_USER + 0x500
  26. //---------------------------------------------------------------------------
  27. //
  28. // class CMainFrame
  29. // 
  30. //---------------------------------------------------------------------------
  31. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. ON_WM_CLOSE()
  36. ON_COMMAND(ID_APP_EXIT, OnAppExit)
  37. ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
  38. //}}AFX_MSG_MAP
  39. ON_REGISTERED_MESSAGE(UWM_HOOKTOOL_DLL_LOADED, OnDllLoaded)
  40. ON_REGISTERED_MESSAGE(UWM_HOOKTOOL_DLL_UNLOADED, OnDllUnLoaded)
  41. END_MESSAGE_MAP()
  42. //---------------------------------------------------------------------------
  43. //
  44. // CMainFrame construction
  45. //
  46. //---------------------------------------------------------------------------
  47. CMainFrame::CMainFrame():
  48. m_TrayIcon(IDR_TRAYICON),
  49. m_bShutdown(FALSE),
  50. m_ApplicationScope( CApplicationScope::GetInstance() )
  51. {
  52. }
  53. //---------------------------------------------------------------------------
  54. //
  55. // CMainFrame destruction
  56. //
  57. //---------------------------------------------------------------------------
  58. CMainFrame::~CMainFrame()
  59. {
  60. m_ApplicationScope.InstallHook( FALSE, 0 );
  61. }
  62. //---------------------------------------------------------------------------
  63. //
  64. // OnCreate
  65. //
  66. //---------------------------------------------------------------------------
  67. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  68. {
  69. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  70. return -1;
  71. // Set up tray icon
  72. m_TrayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
  73. m_TrayIcon.SetIcon(IDI_TRAYICON);
  74. //
  75. // Install the hook here
  76. //
  77. m_ApplicationScope.InstallHook( TRUE, m_hWnd );
  78. return 0;
  79. }
  80. //---------------------------------------------------------------------------
  81. //
  82. // OnClose
  83. //
  84. //---------------------------------------------------------------------------
  85. void CMainFrame::OnClose() 
  86. {
  87. if (m_bShutdown)
  88. {
  89. CFrameWnd::OnClose();
  90. }
  91. else
  92. {
  93. ShowWindow(SW_HIDE);
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. // OnAppExit
  98. //
  99. // Shut down the process
  100. //---------------------------------------------------------------------------
  101. void CMainFrame::OnAppExit() 
  102. {
  103. m_bShutdown = TRUE;
  104. SendMessage(WM_CLOSE);
  105. }
  106. //---------------------------------------------------------------------------
  107. // OnTrayNotification
  108. //
  109. // Handle notification from tray icon: display a message.
  110. //---------------------------------------------------------------------------
  111. LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
  112. {
  113. // let tray icon do default stuff
  114. return m_TrayIcon.OnTrayNotification(uID, lEvent);
  115. }
  116. //---------------------------------------------------------------------------
  117. // OnDllLoaded
  118. //
  119. // Fired when a process loads hook tool dll
  120. //---------------------------------------------------------------------------
  121. LRESULT CMainFrame::OnDllLoaded(WPARAM wParam, LPARAM lParam)
  122. {
  123. m_ApplicationScope.OnDllLoaded( lParam );
  124. return 0;
  125. }
  126. //---------------------------------------------------------------------------
  127. // OnDllUnLoaded
  128. //
  129. // Fired when a process unloads hook tool dll
  130. //---------------------------------------------------------------------------
  131. LRESULT CMainFrame::OnDllUnLoaded(WPARAM wParam, LPARAM lParam)
  132. {
  133. m_ApplicationScope.OnDllUnLoaded( lParam );
  134. return 0;
  135. }
  136. //----------------------------End of the file -------------------------------