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

📄 wndfordll.cpp

📁 随着计算机信息技术的飞速发展
💻 CPP
字号:
// WndForDLL.cpp: implementation of the CWndForDLL class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WndForDLL.h"
#include "MyDoc.h"
#include "MyView.h"


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CWndForDLL, CWnd)

CWndForDLL::CWndForDLL()
{
	m_pDocument		  = NULL;
	m_bHaveMouseRight = FALSE;
	m_pDLLMenu        = NULL;
	m_pDLLMenuArray.RemoveAll();
	m_menuNameArray.RemoveAll();
}

CWndForDLL::~CWndForDLL()
{

}


BEGIN_MESSAGE_MAP(CWndForDLL, CWnd)
	ON_MESSAGE(MYWM_USER_LOST_MOUSERIGHT, OnLostMouse)
	ON_MESSAGE(MYWM_DRAW, OnMyPaint)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWndForDLL message handlers

LRESULT CWndForDLL::OnLostMouse(WPARAM wParam, LPARAM lParam) 
{
	m_bHaveMouseRight = FALSE;
	OnLostMouseRight();
	return TRUE;
}

LRESULT CWndForDLL::OnMyPaint(WPARAM wParam, LPARAM lParam) 
{
	CMyView* pView = (CMyView*)wParam;
	OnMyDraw(pView);
	return TRUE;
}

void CWndForDLL::OnLostMouseRight()
{
	return;
}
void CWndForDLL::OnMyDraw(CMyView* pView)
{
	return;
}

BOOL CWndForDLL::ConnectWithDocument(CMyDoc* pDoc)
{
	//AfxGetMainWnd()->;  CDocument
	CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
	
	CMDIChildWnd* pMDIChildWnd = pMainWnd->MDIGetActive();
	if (pMDIChildWnd == NULL)
	{
		ASSERT(FALSE);  
		return FALSE;
	}

	CView* pView = pMDIChildWnd->GetActiveView();

	/*if(pView->GetDocument() != pDoc)	
		return FALSE;
	*/

	m_pView = (CMyView*)pView;
	m_pDocument = pDoc;
	ASSERT(pDoc != NULL);
	(pDoc->m_dllList).AddTail(this);
	if(AddMenu())						
		pMainWnd->DrawMenuBar();

	return TRUE;
}

BOOL CWndForDLL::AddMenu()
{
		
	//if(m_bMenuActive)
	//	return FALSE;
	//m_bMenuActive = TRUE;
	CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
	int iPos = 3;
	
	if(m_menuID != -1 && m_pDLLMenu == NULL)
	{
		m_pDLLMenu = new CMenu;
		m_pDLLMenu->LoadMenu(m_menuID);
		CMenu* pDLLSubMenu = m_pDLLMenu->GetSubMenu(0);
	
		pTopMenu->InsertMenu( iPos, MF_POPUP|MF_STRING|MF_BYPOSITION,
			(UINT)pDLLSubMenu->m_hMenu, m_menuName);
	}

	if ( m_pDLLMenuArray.GetSize() == 0 )
	{
		m_pDLLMenuArray.SetSize(m_menuNameArray.GetSize());
		for (int i = 0 ; i <m_menuNameArray.GetSize(); i++ )
			m_pDLLMenuArray[i] = NULL;
	}
	for (int i = 0 ; i <m_menuNameArray.GetSize(); i++ )
	{
		if(m_menuIDArray[i] != -1 && m_pDLLMenuArray[i] == NULL)
		{
			m_pDLLMenuArray[i] = new CMenu;
			m_pDLLMenuArray[i]->LoadMenu(m_menuIDArray[i]);
			CMenu* pDLLSubMenu = m_pDLLMenuArray[i]->GetSubMenu(0);
	
			pTopMenu->InsertMenu( iPos, MF_POPUP|MF_STRING|MF_BYPOSITION,
				(UINT)pDLLSubMenu->m_hMenu, m_menuNameArray[i]);
		}
	}
	return TRUE;
}


BOOL CWndForDLL::DelMenu()
{
	CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
	int iPos = 0;
	CString str;
	BOOL bTrue = FALSE;
	for (iPos = pTopMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
	{
		
		pTopMenu->GetMenuString( iPos, str, MF_BYPOSITION );
		if (str == m_menuName)
		{
			pTopMenu->DeleteMenu(iPos, MF_BYPOSITION);
			bTrue = TRUE;
		}
		delete m_pDLLMenu;
		m_pDLLMenu = NULL;

	}

	for (int i = m_menuNameArray.GetSize( ) -1 ; i >= 0 ; i-- )
	{
		for (iPos = pTopMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
		{
		
			pTopMenu->GetMenuString( iPos, str, MF_BYPOSITION );
			if (str == m_menuNameArray[i])
			{
				pTopMenu->DeleteMenu(iPos, MF_BYPOSITION);
				bTrue = TRUE;
			}
			delete m_pDLLMenuArray[i];
			m_pDLLMenuArray[i] = NULL;
		}
	}

	if(iPos < 0 && !bTrue)
		return FALSE;
	//CMenu* pMenu = pTopMenu->GetSubMenu(iPos);
	//int num = pMenu->GetMenuItemCount();
	//pTopMenu->DeleteMenu(iPos, MF_BYPOSITION);
	//for (iPos = pMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
	//	pMenu->DeleteMenu(iPos, MF_BYPOSITION);
	//CDocumentT
	CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
	pMainWnd->DrawMenuBar();
	return TRUE;
}



//Cdocument
void CWndForDLL::GetMouseRight()
{
	CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
	CMDIChildWnd* pMDIChildWnd = pMainWnd->MDIGetActive();
	if (pMDIChildWnd == NULL)
		return;  

	CView* pView = pMDIChildWnd->GetActiveView();
	pView->SendMessage(MYWM_USER_LOST_MOUSERIGHT);
	m_bHaveMouseRight = TRUE;
}

LRESULT CWndForDLL::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	
	return CWnd::WindowProc(message, wParam, lParam);
}

void CWndForDLL::SetStatusText(CString& statusString)
{
	CStatusBar* pStatus=(CStatusBar*)
	AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);

	pStatus->SetPaneText(0,statusString);  

}

⌨️ 快捷键说明

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