⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 关于进程&线程查看器 用过vc++自带的Process Viewer
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 +------------------------------------------------------------+
 |															  |
 | (c) Copyright 2002, bigwhite, Inc.						  |
 |															  |
 | ALL RIGHTS RESERVED										  |
 |															  |
 +------------------------------------------------------------+
*/

 
/*============================================================*
 * MainFrm.cpp : implementation of the CMainFrame class       |
 *  Version 1.1                                               |
 *===========================================================*/
#include "stdafx.h"
#include "processdir.h"
#include "Splash.h"
#include "MainFrm.h"

#include "resource.h"
#include "processdirDoc.h"
#include "threadlist.h"
#include "processdirView.h"
#include "ProcessWatchedDialog.h"
#include "BCMenu.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_COMMAND(ID_APP_EXIT, OnAppExit)
	ON_COMMAND(ID_WINDOW_RECOVERY, OnWindowRecovery)
	ON_COMMAND(ID_SET_PROCESS_WATCHED, OnSetProcessWatched)
	ON_WM_NCLBUTTONDOWN()
	ON_WM_NCMOUSEMOVE()
	ON_WM_ACTIVATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
    m_wndToolBar.SetButtonText(0,"refresh");//add explanation below the toolbar
	m_wndToolBar.SetButtonText(2,"kill");
	m_wndToolBar.SetButtonText(4,"about");
	m_wndToolBar.SetSizes(CSize(48,42),CSize(40,19));//fix the size of the image of the toolbar
	// CG: The following line was added by the Splash Screen component.	CSplashWnd::ShowSplashScreen(this);
	
    CenterWindow();//make the mainframe in the center of the screen 
//	AnimateWindow(GetSafeHwnd(),1000,AW_CENTER);//动画方式打开窗口
    AnimateWindowS();
	 ////初始化数据成员tnd
     tnd.cbSize=sizeof(NOTIFYICONDATA);
      tnd.hWnd=this->m_hWnd;
      tnd.uID=IDR_MAINFRAME;
      tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
      tnd.uCallbackMessage=WM_TASKNOTIFY;
      tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME)); 
      strcpy(tnd.szTip,"进程&线程查看器");
      Shell_NotifyIcon(NIM_ADD,&tnd);
	  
	  SetTimer(1,55*20*30,NULL);

	  return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	//cs.style=~WS_SYSMENU;
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);	}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_MAIN_FRAME));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}



BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{ if(!m_wndSplitter.CreateStatic(this,2,1)||!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CProcessdirView),CSize(128,395),pContext)
	  ||!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CThreadList),CSize(0,0),pContext))
	 return FALSE;
  return TRUE;
}	
	



void CMainFrame::OnClose() 
{
  AnimateWindowH();
  CFrameWnd::OnClose();
}

LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 switch(message){

	case WM_TASKNOTIFY:       
	//如果是用户定义的消息
		if(lParam==WM_LBUTTONDBLCLK)
		{  //鼠标双击时主窗口出现
			AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
	        AfxGetApp()->m_pMainWnd->UpdateWindow();	
		}
   	   else if(lParam==WM_RBUTTONDOWN){ 
		//鼠标右键单击弹出菜单
		    BCMenu menu;

		    VERIFY(menu.LoadMenu(IDR_TASKMENU));
			BCMenu::SetMenuDrawMode(BCMENU_DRAWMODE_XP);
			//载入事先定义的菜单
		    BCMenu* pMenu=(BCMenu*)(menu.GetSubMenu(0));
		    ASSERT(pMenu != NULL);
			CPoint pos;
		    GetCursorPos(&pos);
  	        ::SetForegroundWindow(tnd.hWnd); 
			pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
			pos.x,pos.y,AfxGetMainWnd());
            

		
		}
		break;
	case WM_SYSCOMMAND:     
	//如果是系统消息
		if(wParam==SC_MINIMIZE){ 
		//接收到最小化消息时主窗口隐藏
		      AfxGetApp()->m_pMainWnd->
			  ShowWindow(SW_HIDE);
		      return 0;
		}
		break;
	}
	return CFrameWnd::WindowProc
	(message, wParam, lParam);
}



void CMainFrame::OnAppExit() 
{
	// TODO: Add your command handler code here
	
    /*NOTIFYICONDATA tnid;
    tnid.cbSize=sizeof(NOTIFYICONDATA);
    tnid.hWnd=this->m_hWnd;
    tnid.uID=IDR_MAINFRAME;//保证删除的是该程序的图标*/
    Shell_NotifyIcon(NIM_DELETE,&tnd);
    AfxPostQuitMessage(0);
}

void CMainFrame::OnWindowRecovery() 
{
	// TODO: Add your command handler code here
	AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
	AfxGetApp()->m_pMainWnd->UpdateWindow();
}





void CMainFrame::OnSetProcessWatched() 
{
	// TODO: Add your command handler code here
	dlg.DoModal();
}

void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
		// TODO: Add your message handler code here and/or call default
	//检测各按钮是否按到

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -