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

📄 appwnd.cpp

📁 硬件的操作系统语言
💻 CPP
字号:
// AppWnd.cpp : implementation file
//

#include "stdafx.h"
#include "sameproc.h"
#include "AppWnd.h"
#include "AppThread.h"


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

/////////////////////////////////////////////////////////////////////////////
// CAppWnd

IMPLEMENT_DYNCREATE(CAppWnd, CFrameWnd)

CAppWnd::CAppWnd()
 :m_bCanClose(false)
{
}

CAppWnd::~CAppWnd()
{
}


BEGIN_MESSAGE_MAP(CAppWnd, CFrameWnd)
	//{{AFX_MSG_MAP(CAppWnd)
	ON_WM_COPYDATA()
	ON_WM_CLOSE()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//关于namespace请参见SDK文档
namespace
{
	static TCHAR szClassName[] = _T("SameProcClass");
}


/////////////////////////////////////////////////////////////////////////////
// CAppWnd message handlers

bool CAppWnd::CreateAppWnd()
{
	//注册特殊的窗口类SameProcClass
	WNDCLASS wndclass;
	
	::ZeroMemory(&wndclass, sizeof(WNDCLASS));

	wndclass.lpfnWndProc = AfxWndProc;
	wndclass.lpszClassName = szClassName;// "SameProcClass"
	wndclass.hInstance = AfxGetInstanceHandle();

	if (!AfxRegisterClass(&wndclass))
	{
		AfxMessageBox(SP_IDP_REGISTER_FAILED);
		return false;	
	}

	//创建一个窗口
	if (!CFrameWnd::Create(szClassName, _T("SameProcMainWnd"), 0))
	{
		AfxMessageBox(SP_IDP_CREATEFAILED);
		return false;	
	}

	return true;
}

CAppWnd* CAppWnd::FindAppWnd()
{
	
	//查找窗口类为SameProcClass的窗口
	if (CWnd* pWnd = CWnd::FindWindow(szClassName, NULL))
	{
		return static_cast<CAppWnd*>(pWnd);
	}

	return NULL;
}


BOOL CAppWnd::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) 
{
	//保证不能在此时关闭主程序
	m_bCanClose = false;
	
	//取出命令行信息
	//创建代表新的实例的线程
	//If you are interested in having the command line processing you have to add
	//a bit of code to pass it to CAppThread class
	DWORD nCmdShow = pCopyDataStruct->dwData ;
	LPTSTR szCmdLine = reinterpret_cast<LPTSTR>(pCopyDataStruct->lpData);
	
	AfxBeginThread(RUNTIME_CLASS(CAppThread));

	return CFrameWnd::OnCopyData(pWnd, pCopyDataStruct);
}

//关闭整个应用程序的流程
void CAppWnd::OnClose() 
{
	static bool bTimerSet = false;
	if (!m_bCanClose)
	{
		if (bTimerSet)
			KillTimer(1);

		m_bCanClose = true;
		//创建一个时钟
		SetTimer(1, 1000, NULL);

		bTimerSet = true;
	}
	else
	{
		KillTimer(1);
		CFrameWnd::OnClose();
	}
}

//时钟响应函数
void CAppWnd::OnTimer(UINT nIDEvent) 
{

	if (nIDEvent == 1)
		PostMessage(WM_CLOSE);
}


⌨️ 快捷键说明

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