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

📄 guiframewnd.cpp

📁 一个很好用的串口侦听源代码
💻 CPP
字号:
//-----------------------------------------------------------------------//
// This is a part of the GuiLib MFC Extention.							 //	
// Autor  :  Francisco Campos											 //
// (C) 2002 Francisco Campos <www.beyondata.com> All rights reserved     //
// This code is provided "as is", with absolutely no warranty expressed  //
// or implied. Any use is at your own risk.								 //		
// You must obtain the author's consent before you can include this code //
// in a software library.												 //
// If the source code in  this file is used in any application			 //
// then acknowledgement must be made to the author of this program		 //	
// fco_campos@tutopia.com													 //
// Version :1.1															 //
// Modified by : Francisco Campos										 //	 
//-----------------------------------------------------------------------//

#include "stdafx.h"
#include "..\header\guiframewnd.h"
#include "..\header\guiframewnd.h"
#include "..\header\GuiMiniFrame.h"

IMPLEMENT_DYNCREATE(CGuiFrameWnd, CFrameWnd)
CGuiFrameWnd::CGuiFrameWnd(void)
{
	m_MdiTabbed=FALSE;
}

CGuiFrameWnd::~CGuiFrameWnd(void)
{
}

BOOL CGuiFrameWnd::PreCreateWindow(CREATESTRUCT& cs)
{
	return CFrameWnd::PreCreateWindow(cs);
}

BOOL CGuiFrameWnd::PreTranslateMessage(MSG* pMsg) 
{
	if (m_wndMenuBar.TranslateFrameMessage(pMsg))
		return TRUE;
	
	return CFrameWnd::PreTranslateMessage(pMsg);
}

//*************************************************************************
BOOL CGuiFrameWnd::PreCreateWindow(CREATESTRUCT& cs, UINT nIconID)
{
	cs.lpszClass = AfxRegisterWndClass( 0, NULL, NULL,
		AfxGetApp()->LoadIcon(nIconID));
	ASSERT(cs.lpszClass);

	return CFrameWnd::PreCreateWindow(cs);
}

void CGuiFrameWnd::EnableDocking(DWORD dwDockStyle)
{
	ASSERT((dwDockStyle & ~ (CBRS_ALIGN_ANY | CBRS_FLOAT_MULTI)) == 0);


	m_pFloatingFrameClass = RUNTIME_CLASS(CMiniDockFrameWnd);
	CGuiDocBarExten* pDock;
	DWORD dwStyle = WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
	DWORD dwstyle;

	pDock = new CGuiDocBarExten();
	pDock->Create(this,dwStyle|CBRS_TOP, AFX_IDW_DOCKBAR_TOP);
	dwstyle = pDock->GetBarStyle();
	dwstyle &= ~CBRS_BORDER_ANY;
	pDock->SetBarStyle(dwstyle);

	pDock = new CGuiDocBarExten();
	pDock->Create(this, dwStyle|CBRS_BOTTOM, AFX_IDW_DOCKBAR_BOTTOM);
	dwstyle = pDock->GetBarStyle();
	dwstyle &= ~CBRS_BORDER_ANY;
	pDock->SetBarStyle(dwstyle);

	pDock = new CGuiDocBarExten();
	pDock->Create(this,dwStyle|CBRS_LEFT, AFX_IDW_DOCKBAR_LEFT);
	dwstyle = pDock->GetBarStyle();
	dwstyle &= ~CBRS_BORDER_ANY;
	pDock->SetBarStyle(dwstyle);

	pDock = new CGuiDocBarExten();
	pDock->Create(this,dwStyle|CBRS_RIGHT, AFX_IDW_DOCKBAR_RIGHT);
	dwstyle = pDock->GetBarStyle();
	dwstyle &= ~CBRS_BORDER_ANY;
	pDock->SetBarStyle(dwstyle);
	m_pFloatingFrameClass = RUNTIME_CLASS(CGuiMiniFrame);
//	DockSpecialBars();

}

void CGuiFrameWnd::ShowHideBar(CGuiControlBar* pBar)
{
	if (pBar->IsWindowVisible())
		ShowControlBar(pBar, FALSE, FALSE);
	else
		ShowControlBar(pBar, TRUE, FALSE);
}

void CGuiFrameWnd::ShowHideBar(CControlBar* pBar)
{
	if (pBar->IsWindowVisible())
		ShowControlBar(pBar, FALSE, FALSE);
	else
		ShowControlBar(pBar, TRUE, FALSE);
}

void CGuiFrameWnd::SavePosBar(CString szBars)
{
	POSITION pos = m_listControlBars.GetHeadPosition();
    while (pos != NULL)
    {
        CGuiControlBar* pBar = (CGuiControlBar*) m_listControlBars.GetNext(pos);
        ASSERT(pBar != NULL);
        if (pBar->IsKindOf(RUNTIME_CLASS(CGuiControlBar)))
            pBar->SaveBar(szBars);
    }
}

void CGuiFrameWnd::LoadPosBar(CString szBars)
{
	POSITION pos = m_listControlBars.GetHeadPosition();
    while (pos != NULL)
    {
        CGuiControlBar* pBar = (CGuiControlBar*) m_listControlBars.GetNext(pos);
        ASSERT(pBar != NULL);
        if (pBar->IsKindOf(RUNTIME_CLASS(CGuiControlBar)))
            pBar->LoadStateBar(szBars);
    }
}

void CGuiFrameWnd::DockSpecialBars()
{
	m_dockToolbarTop.Create(this,CBRS_ALIGN_BOTTOM);
	m_dockToolbarBottom.Create(this,CBRS_ALIGN_TOP);
	m_dockToolbarLeft.Create(this,CBRS_ALIGN_LEFT);
	m_dockToolbarRight.Create(this,CBRS_ALIGN_RIGHT);

/*	m_dockToolbarTop.EnableDocking(CBRS_ALIGN_TOP);
	m_dockToolbarBottom.EnableDocking(CBRS_ALIGN_BOTTOM);
	m_dockToolbarLeft.EnableDocking(CBRS_ALIGN_LEFT);
	m_dockToolbarRight.EnableDocking(CBRS_ALIGN_RIGHT);

	DockControlBar(&m_dockToolbarTop);
	DockControlBar(&m_dockToolbarBottom);
	DockControlBar(&m_dockToolbarLeft);
	DockControlBar(&m_dockToolbarRight);*/
}
/////////////////////////////////////////////////////////////////////////////
// CGuiMDIFrame message handlers
//***********************************************************************
BOOL CGuiFrameWnd::DestroyWindow()
{
	CWinApp* pApp = AfxGetApp();
	TCHAR szSection[256];
	wsprintf(szSection, "%s-Main", sProfile);
	CRect rc;
	GetWindowRect(rc);
	pApp->WriteProfileString(szSection, NULL, NULL);
	pApp->WriteProfileInt(szSection, "left", rc.left);
	pApp->WriteProfileInt(szSection, "right", rc.right);
	pApp->WriteProfileInt(szSection, "bottom", rc.bottom);
	pApp->WriteProfileInt(szSection, "top", rc.top);

	SaveBarState(sProfile);
	SavePosBar(sProfile);
	return CFrameWnd::DestroyWindow();
}

//***********************************************************************
BOOL CGuiFrameWnd::VerifyBarState(LPCTSTR lpszProfileName)
{
    CDockState state;
    state.LoadState(lpszProfileName);

    for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
    {
        CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
        ASSERT(pInfo != NULL);
        int nDockedCount = pInfo->m_arrBarID.GetSize();
        if (nDockedCount > 0)
        {
            // dockbar
            for (int j = 0; j < nDockedCount; j++)
            {
                UINT nID = (UINT) pInfo->m_arrBarID[j];
                if (nID == 0) continue; // row separator
                if (nID > 0xFFFF)
                    nID &= 0xFFFF; // placeholder - get the ID
                if (GetControlBar(nID) == NULL)
                    return FALSE;
            }
        }

        if (!pInfo->m_bFloating) // floating dockbars can be created later
            if (GetControlBar(pInfo->m_nBarID) == NULL)
                return FALSE; // invalid bar ID
    }

    return TRUE;
}


void CGuiFrameWnd::LoadBars()
{
	
	CWinApp* pApp = AfxGetApp();
	TCHAR szSection[256];
 	wsprintf(szSection, "%s-Main", sProfile);
	CRect rc=CRect(0,0,0,0);
	rc.left=pApp->GetProfileInt(szSection, "left",0);
	rc.top=pApp->GetProfileInt(szSection, "top",0);
	rc.bottom=pApp->GetProfileInt(szSection, "bottom",GetSystemMetrics(SM_CYSCREEN));
	rc.right=pApp->GetProfileInt(szSection, "right",GetSystemMetrics(SM_CXSCREEN));
	MoveWindow(rc);
	
	if (VerifyBarState(sProfile))
	{
		LoadBarState(sProfile);
		LoadPosBar(sProfile);
	}
}

BEGIN_MESSAGE_MAP(CGuiFrameWnd, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()

int CGuiFrameWnd::InitMenu(UINT uIDMenu)
{
	if (!m_wndMenuBar.CreateEx(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_SIZE_DYNAMIC ) ||
		!m_wndMenuBar.LoadMenuBar(uIDMenu))
	{
		TRACE0("Failed to create menubar\n");
		return -1;      // fail to create
	}	
	m_NewMenu.LoadMenu(uIDMenu);
	m_wndCool.Install(this);
	m_wndCool.LoadToolbar(uIDMenu);
	
	return 0;
}

int CGuiFrameWnd::InitStatusBar(const UINT* lpIDArray,int nSize)
{
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(lpIDArray,
		  nSize))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}
	return 0;
}

int CGuiFrameWnd::InitToolBar(UINT uID,UINT uIDMenu)
{
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,CRect(0,0,0,0),uID) ||
		!m_wndToolBar.LoadToolBar(uIDMenu))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	return 0;
}

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

	return 0;
}

⌨️ 快捷键说明

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