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

📄 mainfrm.cpp

📁 一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "MainFrm.h"
#include "MyMonitor.h"
#include "Splash.h"

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

#define LOG(x) { if((m_LogFile.m_uLogLevel) > 0) m_LogFile.WriteLog(m_csModuleName+x); }
#define INFO(x) { if((m_LogFile.m_uLogLevel) > 1) m_LogFile.WriteLog(m_csModuleName+x); }

/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	// When register to USHA successful
	ON_MESSAGE(WM_MYUDP_CALLBACK, TreatSocketThreadMessage)

	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_WM_TIMER()
	ON_WM_CLOSE()
	ON_WM_ENDSESSION()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_csModuleName = LOG_STR_MAIN_NAME;

	// Set Log File Path
	m_LogFile.CreateLogPath(_T(DEFAULT_LOG_PATH));
	m_LogFile.m_uLogLevel = LOG_LEVEL;// record both LOG and INFO

	LOG("I Start Here");

	// Show message boxes
	m_bNotify = TRUE;
}

CMainFrame::~CMainFrame()
{
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

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

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

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

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame functions
void CMainFrame::MyInfoBoxEx(CString strInfo, BOOL* pbMsgShowing)
{
	// ignore suspend mode

	MessageInfo MsgInfo;
	MsgInfo.hwndShowMsg = NULL;
	//MsgInfo.hwndShowMsg = m_hWnd;
	MsgInfo.pbMsgShowing = pbMsgShowing;
	MsgInfo.strMsgText = strInfo;
	MsgInfo.strMsgTitle = "UDP test MessageBox";
	MsgInfo.uMsgStyle = MB_ICONINFORMATION | MB_TOPMOST | MB_SETFOREGROUND;
	// Initialize event to avoid race between message threads
	// auto reset, initially reset
	MsgInfo.hEvent_GetParametersOK = CreateEvent(NULL, FALSE, FALSE, NULL);

	AfxBeginThread(ThreadMessageBox, &MsgInfo);

	// Give this thread time to transfer parameters to local MsgInfo
	// wait for GetParametersOK signal of this thread
	WaitForSingleObject(MsgInfo.hEvent_GetParametersOK, INFINITE);
}

void CMainFrame::MyInfoBox(CString strInfo, BOOL* pbMsgShowing)
{
	// if in suspend mode, don't show message
	if(!m_bNotify) return;

	MessageInfo MsgInfo;
	MsgInfo.hwndShowMsg = NULL;
	//MsgInfo.hwndShowMsg = m_hWnd;
	MsgInfo.pbMsgShowing = pbMsgShowing;
	MsgInfo.strMsgText = strInfo;
	MsgInfo.strMsgTitle = "UDP test MessageBox";
	MsgInfo.uMsgStyle = MB_ICONINFORMATION | MB_TOPMOST | MB_SETFOREGROUND;
	// Initialize event to avoid race between message threads
	// auto reset, initially reset
	MsgInfo.hEvent_GetParametersOK = CreateEvent(NULL, FALSE, FALSE, NULL);

	AfxBeginThread(ThreadMessageBox, &MsgInfo);

	// Give this thread time to transfer parameters to local MsgInfo
	// wait for GetParametersOK signal of this thread
	WaitForSingleObject(MsgInfo.hEvent_GetParametersOK, INFINITE);
}

CString CMainFrame::FormatString(DWORD dwState, CString strAddress)
{
	CString		_szDesc;

	_szDesc = "Some info to display...";

	return _szDesc;
}

/***********************************************************
 *
 * Event handlers for SocketThread.
 *
 ***********************************************************/
void CMainFrame::OnEvtConnected(WPARAM wParam, LPARAM lParam)
{
	if(((CMyUdpInfo*)lParam)->m_dwMyUdpState & MY_UDP_STATUS_CONNECTED) return;
	LOG("UDP Connected - " + ((CMyUdpInfo*)lParam)->m_csAddress);

	((CMyUdpInfo*)lParam)->m_dwMyUdpState |= MY_UDP_STATUS_CONNECTED;
	MyInfoBox(FormatString(MY_UDP_STATUS_CONNECTED,((CMyUdpInfo*)lParam)->m_csAddress), 
		&(((CMyUdpInfo*)lParam)->m_baMessageShowing[2]));
}

LRESULT CMainFrame::TreatSocketThreadMessage(WPARAM wParam, LPARAM lParam)
{
	//INFO("SocketThread Message in.");

	switch (LOWORD(wParam))
	{
		case EVENT_UDP_CONNECTED :
			OnEvtConnected(wParam,lParam); 
			break;

		default :
			LOG("Unknown SocketThread Message.");
			break;
	}

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
	// let the view have first crack at the command
	if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
		return TRUE;

	// otherwise, do default handling
	return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here

	// For SystemTray Icon
    HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));  // Icon to use
	if (!m_TrayIcon.Create(
                        NULL,                            // Let icon deal with its own messages
                        WM_ICON_NOTIFY,                  // Icon notify message to use
                        _T("This is a Tray Icon - Right click on me!"),  // tooltip
                        hIcon,
                        IDR_POPUP_MENU,                  // ID of tray icon popup menu
                        FALSE,
                        _T("Here's a cool new Win2K balloon!"), // balloon tip
                        _T("Look at me!"),               // balloon title
                        NIIF_WARNING,                    // balloon icon
                        20 ))                            // balloon timeout
    {
		return -1;
    }

	// CG: The following line was added by the Splash Screen component.	CSplashWnd::ShowSplashScreen(this);

	return 0;
}


int CMainFrame::BeginMyUdpThread(CMyUdpInfo* pMyUdpInfo)
{
	// Set the info of a MyUdp thread and start it
	pMyUdpInfo->m_hwndNotify = m_hWnd;
	pMyUdpInfo->m_pLogFile = &m_LogFile;
	pMyUdpInfo->m_csClientName = DEFAULT_CLIENTNAME;
	pMyUdpInfo->m_dwMyUdpState = 0;
	pMyUdpInfo->m_csAddress = DEFAULT_IP;
	ResetEvent(pMyUdpInfo->m_hEvent_GetParametersDone);
	ResetEvent(pMyUdpInfo->m_hEvent_Kill);
	SetEvent(pMyUdpInfo->m_hEvent_Killed);

	AfxBeginThread(MyUdpThreadProc, pMyUdpInfo);

	// Give this thread time to transfer parameters to local variable
	// wait for GetParametersOK signal of this thread
	WaitForSingleObject(pMyUdpInfo->m_hEvent_GetParametersDone, INFINITE);

	return 0;
}

void CMainFrame::OnTimer(UINT nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	switch (nIDEvent)
	{
		case TIMER_ID_MAINFRAME :
			KillTimer(TIMER_ID_MAINFRAME);
			break;

		default :
			break;
	}

	// Splash screen has ended
	// start communication now
}

// App command to run the About dialog
void CMainFrame::OnAppAbout()
{
	// TODO: Add your command handler code here

	static BOOL bShowing;
	if(bShowing) return;

	bShowing = TRUE;
	MyInfoBoxEx(ABOUT_VERSION, &bShowing);
	bShowing = FALSE;

}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	//Kill all the threads
	for(int i=0;i<UDP_THREAD_NUMBER;i++)
	{
		SetEvent(m_MyUdpArray[i].m_hEvent_Kill);
	}
	for(i=0;i<UDP_THREAD_NUMBER;i++)
	{
		WaitForSingleObject(m_MyUdpArray[i].m_hEvent_Killed, INFINITE);
	}
	
	CFrameWnd::OnClose();
}

void CMainFrame::OnEndSession(BOOL bEnding) 
{
	CFrameWnd::OnEndSession(bEnding);
	
	// TODO: Add your message handler code here
	if(bEnding)
	{
		PostMessage(WM_CLOSE, 0, 0);
	}
	
}

⌨️ 快捷键说明

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