mfc编程,界面设计

#include "stdafx.h"
#include "WndChildPage.h"
#include "ExtensionWnd.h"
 
// ��׼���캯��
CWndChildPage::CWndChildPage()
{
}
 
// ��׼�����
CWndChildPage::~CWndChildPage()
{
}
 
BEGIN_MESSAGE_MAP(CWndChildPage, CDialog)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
 
 
// CWndChildPage ��Ϣ��������
 
// WM_ERASEBKGND��Ϣ������
BOOL CWndChildPage::OnEraseBkgnd(CDC* pDC)
{
	// ʹ��UNICODE�ַ�ת��
	USES_CONVERSION;
 
	CRect rtClient;
	GetClientRect(rtClient);
 
	// �������ڻ���˫����
	CDC dcMem;
	dcMem.CreateCompatibleDC(pDC);
	CBitmap btBitmap, *pOldBitmap;
	btBitmap.CreateCompatibleBitmap(pDC, rtClient.Width(), rtClient.Height());
	pOldBitmap = dcMem.SelectObject(&btBitmap);
 
	// ���ƴ��ڱ���
	CFunctions::DrawTransBack(m_hWnd, dcMem);
 
	Gdiplus::Graphics graphics(dcMem.m_hDC);
 
	// ���ƴ�������
	StringFormat stringFormat;
	stringFormat.SetFormatFlags( StringFormatFlagsNoWrap);
 
	LOGFONT lfFont ;
	memset(&lfFont, 0, sizeof(lfFont));
	lfFont.lfHeight = -15;
	lstrcpy(lfFont.lfFaceName, _T("����"));
	Font font(dcMem.GetSafeHdc(), &lfFont);
 
	CString sName = _T("�������ɶ�̬���е�����");
	CStringW wName = T2W(sName.GetBuffer());
	SolidBrush brush((ARGB)Color::Black);
	graphics.DrawString(wName, wName.GetLength(), &font, RectF(75, 200, 600, 20),&stringFormat, &brush);
 
	// ��˫����DC���ݻ��Ƶ���ǰ����DC
	pDC->BitBlt(0, 0, rtClient.Width(), rtClient.Height(), &dcMem, 0, 0, SRCCOPY);
	dcMem.SelectObject(pOldBitmap);
	return TRUE;
}
============================
 

#include "stdafx.h"
#include "QChildPage.h"
#include "DlgChildPage.h"
#include "WndChildPage.h"
#include "ExtensionWnd.h"


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


class CQChildPageApp : public CWinApp
{
public:
	CQChildPageApp(){};
	virtual ~CQChildPageApp(){};
};


CQChildPageApp theApp;


// ��ȡ���ڹ���ģ���ӿڰ汾
DLL_DECLSPEC int GetInterfaceVersion() 
{ 
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return IUIEXTENSION_VERSION; 
}


// �������ڹ���ģ��ʵ��
DLL_DECLSPEC IUIExtension* CreateUIExtensionInterface()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return new CQChildPage();
}


// �ͷŴ��ڹ���ģ��ʵ��
void CQChildPage::Release()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	delete this;
}


// ֪ͨ���ڹ���ģ���û�������Ƥ��
void CQChildPage::ChangeSkin( LPCWSTR szSkinName )
{


}


// ��ȡ���ڹ���ģ���������Ĵ������
int  CQChildPage::GetNumUIExtensions()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return 3;
}


// ֪ͨ�������Ŵ���ָ�������Ĵ���ʵ��
IUIExtensionWindow* CQChildPage::CreateExtensionWindow(int iIndex)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	IUIExtensionWindow* pWindow = NULL;
	if(iIndex == 0)
		return new CExtensionWnd(
			// param1 ��ҳ�水ť����
			// param2 �����水ťͼ��·����ΪƤ���ļ���·��
			// param3 ��������ָ��
			// param4 ������ʹ�õĶԻ�����Դ
			_T("ģ������1"), _T("ͼ��\\ico_AdvTools.png"), new CDlgChildPage(), CDlgChildPage::IDD);
	else if(iIndex == 1)
	{
		return new CExtensionWnd(
			// param1 ��ҳ�水ť����
			// param2 �����水ťͼ��·����ΪƤ���ļ���·��
			// param3 ��������ָ��
			_T("ģ������2"), _T("ͼ��\\ico_diannaomenzhen.png"), new CWndChildPage());
	}
	else if(iIndex == 2)
	{
		return new CExtensionWnd(
			// param1 ��ҳ�水ť����
			// param2 �����水ťͼ��·����ΪƤ���ļ���·��
			// param3 ָʾҪ���еij�����������
			_T("ģ������3"), _T("ͼ��\\ico_dsmain.png"), _T("QPreview.exe"));
	}


	return pWindow;
}
=============================
 
#define	WMU_ACTIVE		(WM_APP+501)
// ��ȡָ����ҳ������
#define	WMU_GETPAGE		(WM_APP+502)
// ��ȡָ����ҳ������
#define	WMU_NOTIFMSG	(WM_APP+503)
class CMainMessage
{
public:
	static BOOL PageExsit( LPCTSTR szName )
	{
		USES_CONVERSION;
		HWND hMainWnd = GetMainWnd();
		if(hMainWnd != NULL)
		{
			HWND	hChildWnd = NULL;
			LRESULT lResult = S_FALSE;
			lResult = ::SendMessage(hMainWnd, WMU_GETPAGE, (WPARAM)T2W((LPTSTR)szName), (LPARAM)&hChildWnd);
			if(lResult == S_OK && IsWindow(hChildWnd))
			{
				return TRUE;
			}
		}
		return FALSE;
	}
	static void ActivePage( LPCTSTR szName )
	{
		USES_CONVERSION;
		HWND hMainWnd = GetMainWnd();
		if(hMainWnd != NULL)
		{
			::SendMessage(hMainWnd, WMU_ACTIVE, (WPARAM)T2W((LPTSTR)szName), NULL);
		}
	}
	static void ActivePage( LPCTSTR szName, LPCTSTR szChild )
	{
		USES_CONVERSION;
		HWND hMainWnd = GetMainWnd();
		if(hMainWnd != NULL)
		{
			::SendMessage(hMainWnd, WMU_ACTIVE, (WPARAM)T2W((LPTSTR)szName), (LPARAM)T2W((LPTSTR)szChild));
		}
	}
	static BOOL PostCommand( LPCTSTR szName, UINT uCommand, WPARAM wParam = 0, LPARAM lParam = 0 )
	{
		USES_CONVERSION;
		HWND hMainWnd = GetMainWnd();
		if(hMainWnd != NULL)
		{
			if(lstrcmp(szName, _T("MainWnd")) == 0)
			{
				return ::PostMessage(hMainWnd, uCommand, wParam, lParam);
			}
			HWND	hChildWnd = NULL;
			LRESULT lResult = S_FALSE;
			lResult = ::SendMessage(hMainWnd, WMU_GETPAGE, (WPARAM)T2W((LPTSTR)szName), (LPARAM)&hChildWnd);
			if(lResult == S_OK && IsWindow(hChildWnd))
			{
				return ::PostMessage(hChildWnd, uCommand, wParam, lParam);
			}
		}
		return FALSE;
	}
	static LRESULT SendCommand( LPCTSTR szName, UINT uCommand, WPARAM wParam = 0, LPARAM lParam = 0 )
	{
		USES_CONVERSION;
		HWND hMainWnd = GetMainWnd();
		if(hMainWnd != NULL)
		{
			if(lstrcmp(szName, _T("MainWnd")) == 0)
			{
				return ::SendMessage(hMainWnd, uCommand, wParam, lParam);
			}
			HWND	hChildWnd = NULL;
			LRESULT lResult = S_FALSE;
			lResult = ::SendMessage(hMainWnd, WMU_GETPAGE, (WPARAM)T2W((LPTSTR)szName), (LPARAM)&hChildWnd);
			if(lResult == S_OK && IsWindow(hChildWnd))
			{
				return ::SendMessage(hChildWnd, uCommand, wParam, lParam);
			}
		}
		return S_FALSE;
	}
private:
	static HWND GetMainWnd()
	{
		static 	HWND hMainWnd = NULL;
		if(hMainWnd == NULL)
		{
			const TCHAR szGuid[]		= _T("{5D11FAB5-B7D7-4b05-8B9C-E3EFBC942431}");
			const TCHAR szGuidMapFile[] = _T("{5D11FAB5-B7D7-4b05-8B9C-E3EFBC942431}_MapFile");
			HANDLE hInstMutex = CreateMutex(NULL, TRUE, szGuid);
			if (::GetLastError() != ERROR_ALREADY_EXISTS 
				&& ::GetLastError() != ERROR_ACCESS_DENIED)
				return NULL;
			DWORD dwResult;
			dwResult = WaitForSingleObject(hInstMutex, 1000);
			if (WAIT_OBJECT_0 != dwResult && WAIT_ABANDONED != dwResult)
				return NULL;
			ReleaseMutex(hInstMutex);
			HANDLE	hMapFile;
			LPVOID	pBuf;
			hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, szGuidMapFile);
			if (NULL == hMapFile || INVALID_HANDLE_VALUE == hMapFile)
				return NULL;
			pBuf = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, sizeof(HWND));
			CopyMemory((LPVOID)&hMainWnd, pBuf, sizeof(HWND));
			UnmapViewOfFile(pBuf);
			CloseHandle(hMapFile);
		}
		return hMainWnd;
	}
};
=========================================
#include "StdAfx.h"
#include "Functions.h"
BOOL CFunctions::GetTransBack( HWND hWnd, HDC& hBackDC, CRect& rtBack)
{
	hBackDC = NULL;
	HWND hParentWnd = hWnd;
	do 
	{
		hBackDC = (HDC)::GetProp(hParentWnd, _T("BackDC"));
		if( hBackDC != NULL ) break;
		hParentWnd = ::GetParent(hParentWnd);
	} while (hParentWnd != NULL);
	if(hBackDC != NULL)
	{
		CRect rtWindow;
		CWnd::FromHandle(hWnd)->GetWindowRect(rtBack);
		CWnd::FromHandle(hParentWnd)->GetWindowRect(rtWindow);
		rtBack.OffsetRect( -rtWindow.left,-rtWindow.top );
		return TRUE;
	}
	return FALSE;
}
BOOL CFunctions::DrawTransBack(HWND hWnd, HDC hDC)
{
	HDC hBackDC = NULL;
	CRect rtBack = NULL;
	if(GetTransBack(hWnd, hBackDC, rtBack))
	{
		CRect rtPaint;
		GetClipBox(hDC, &rtPaint);
		BitBlt(hDC, rtPaint.left, rtPaint.top, rtPaint.Width(), rtPaint.Height(), hBackDC, rtBack.left+rtPaint.left, rtBack.top+rtPaint.top, SRCCOPY);
		return TRUE;
	}
	return FALSE;
}
BOOL CFunctions::SetTransBack( HWND hWnd, HDC hDC )
{
	return SetProp(hWnd, _T("BackDC"), HANDLE(hDC));
}
================================================
#include "stdafx.h"
#include "ExtensionWnd.h"
CExtensionWnd::CExtensionWnd( LPCTSTR szName, LPCTSTR szIcon, LPCTSTR szCommandLine )
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	USES_CONVERSION;
	m_sName = T2W(LPTSTR(szName));
	m_sIcon = T2W(LPTSTR(szIcon));
	m_sCommandLine = szCommandLine;
	m_pPage = NULL;
	m_nIDTemplate = 0;
}
CExtensionWnd::CExtensionWnd(LPCTSTR szName, LPCTSTR szIcon, CWnd* pPage)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	USES_CONVERSION;
	m_pPage = pPage;
	m_sName = T2W(LPTSTR(szName));
	m_sIcon = T2W(LPTSTR(szIcon));
	m_nIDTemplate = 0;
}
CExtensionWnd::CExtensionWnd(LPCTSTR szName, LPCTSTR szIcon, CDialog* pDialog, UINT nIDTemplate)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	USES_CONVERSION;
	m_pPage = pDialog;
	m_sName = T2W(LPTSTR(szName));
	m_sIcon = T2W(LPTSTR(szIcon));
	m_nIDTemplate = nIDTemplate;
}
CExtensionWnd::~CExtensionWnd()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(m_pPage!= NULL)
	{
		m_pPage->DestroyWindow();
		delete m_pPage;
		m_pPage = NULL;
	}
}
BOOL CExtensionWnd::Create(HWND hParent,LPSIZE lpSize)
{ 
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	CRect rtClient(0,0, lpSize->cx, lpSize->cy);
	if(m_nIDTemplate != 0)
	{
		((CDialog*)m_pPage)->Create(m_nIDTemplate, CWnd::FromHandle(hParent));
		m_pPage->ShowWindow(SW_HIDE);
		m_pPage->MoveWindow(&rtClient, FALSE);
	}
	else
	{
		static int i = 5001;
		m_pPage->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, rtClient, CWnd::FromHandle(hParent), i++);
		m_pPage->ShowWindow(SW_HIDE);
	}
	m_pPage->UpdateWindow();
	return TRUE;
}
void CExtensionWnd::ReleaseWindow()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(m_pPage!= NULL)
	{
		m_pPage->DestroyWindow();
	}
}
HWND CExtensionWnd::GetSafeHwnd()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	return m_pPage->GetSafeHwnd();
}
BOOL CExtensionWnd::PreActive(BOOL bActive)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(m_pPage != NULL)
	{
		return TRUE;
	}
	else
	{
		USES_CONVERSION;
		WinExec(T2A(m_sCommandLine.GetBuffer()), SW_SHOW);
		return FALSE;
	}
}
BOOL CExtensionWnd::ShowWindow(BOOL bShow)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(IsWindow(m_pPage->GetSafeHwnd()))
		m_pPage->ShowWindow(bShow?SW_SHOW:SW_HIDE);
	if(bShow)
	{
		m_pPage->SetFocus();
	}
	return TRUE;
}
void CExtensionWnd::Release()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(m_pPage!= NULL)
	{
		m_pPage->DestroyWindow();
		delete m_pPage;
		m_pPage = NULL;
	}
	delete this;
}
void CExtensionWnd::Resize(LPSIZE lpSize)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	CRect rtClient(0,0, lpSize->cx, lpSize->cy);
	if(IsWindow(m_pPage->GetSafeHwnd()))
	{
		m_pPage->MoveWindow(&rtClient, FALSE);
	}
}
void CExtensionWnd::OnActive(BOOL bActive)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(IsWindow(m_pPage->GetSafeHwnd()))
		m_pPage->SendMessage(WMU_WND_ACTIVE, (WPARAM)bActive, NULL);
}
BOOL CExtensionWnd::QueryClose(PBOOL bContinue)
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	if(!IsWindow(m_pPage->GetSafeHwnd()))
		return TRUE;
	BOOL bCanClose = TRUE;
	m_pPage->SendMessage(WMU_WND_QUERY_CLOSE, (LPARAM)&bCanClose, (WPARAM)bContinue);
	return bCanClose;
}
LPCWSTR CExtensionWnd::GetWindowName()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	return m_sName.GetBuffer();
}
LPCWSTR CExtensionWnd::GetWindowIcon()
{
#ifdef _EXPORTING
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
	return m_sIcon.GetBuffer();
}
=========================================
#include "stdafx.h"
#include "DlgChildPage.h"
#include "ExtensionWnd.h"
// ��׼���캯��
CDlgChildPage::CDlgChildPage(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgChildPage::IDD, pParent)
{
}
// ��׼�����
CDlgChildPage::~CDlgChildPage()
{
}
void CDlgChildPage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlgChildPage, CDialog)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
// CDlgChildPage ��Ϣ��������
// WM_ERASEBKGND��Ϣ������
BOOL CDlgChildPage::OnEraseBkgnd(CDC* pDC)
{
	USES_CONVERSION;
	CRect rtClient;
	GetClientRect(rtClient);
	CDC dcMem;
	dcMem.CreateCompatibleDC(pDC);
	CBitmap btBitmap, *pOldBitmap;
	btBitmap.CreateCompatibleBitmap(pDC, rtClient.Width(), rtClient.Height());
	pOldBitmap = dcMem.SelectObject(&btBitmap);
	CFunctions::DrawTransBack(m_hWnd, dcMem);
	Gdiplus::Graphics graphics(dcMem.m_hDC);
	// ���ƴ�������
	StringFormat stringFormat;
	stringFormat.SetFormatFlags( StringFormatFlagsNoWrap);
	LOGFONT lfFont ;
	memset(&lfFont, 0, sizeof(lfFont));
	lfFont.lfHeight = -15;
	lstrcpy(lfFont.lfFaceName, _T("����"));
	Font font(dcMem.GetSafeHdc(), &lfFont);
	CString sName = _T("���Ի����ɶ�̬���е�����");
	CStringW wName = T2W(sName.GetBuffer());
	SolidBrush brush((ARGB)Color::Black);
	graphics.DrawString(wName, wName.GetLength(), &font, RectF(75, 200, 600, 20),&stringFormat, &brush);
	pDC->BitBlt(0, 0, rtClient.Width(), rtClient.Height(), &dcMem, 0, 0, SRCCOPY);
	dcMem.SelectObject(pOldBitmap);
	return TRUE;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值