////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 5.0 on Windows 95
//
#include "StdAfx.h"
#include "FormSwap2.h"
#include "MainFrm.h"
#include "LeftView.h"
#include "Forms.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const ROWFORMVIEW = 0;
const COLFORMVIEW = 1;
const CXLIST = 50;
const IDLEFTVIEW = AFX_IDW_PANE_FIRST;
// Get the size of a dialog
static CSize GetDialogSize(LPCTSTR lpszTemplName, CWnd* pParent);
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_NEXT_FORM, OnViewNextForm)
ON_NOTIFY(LVN_ITEMCHANGED, IDLEFTVIEW, OnItemChanged)
END_MESSAGE_MAP()
static UINT indicators[] = {
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT);
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT))) {
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// Make frame just big enough to fit dialog
CSize sz = GetDialogSize(MAKEINTRESOURCE(IDD_DIALOG1), this);
CRect rc(CPoint(0,0), sz);
CalcWindowRect(&rc);
SetWindowPos(NULL, 0, 0, rc.Width(), rc.Height(),
SWP_NOMOVE|SWP_NOZORDER);
return 0;
}
//////////////////
// Client window created: Set up splitter window and save
// pointers to the two panes
//
BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, CCreateContext* pcc)
{
// create splitter window
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
// Create left and right pane/views.
//
CSplitterWnd& sw = m_wndSplitter;
if (!sw.CreateView(0,0,RUNTIME_CLASS(CLeftView), CSize(CXLIST,100), pcc) ||
!sw.CreateView(ROWFORMVIEW, COLFORMVIEW,
FormData.GetViewClass(FormData.GetCurrentForm()),
CSize(0,0), // will get fixed in CMainFrame::OnCreate
pcc) ) {
TRACE("***CMainFrame: failed to create splitter views\n");
sw.DestroyWindow();
return FALSE;
}
// Double-check for ON_NOTIFY in message map above
ASSERT(AFX_IDW_PANE_FIRST == sw.IdFromRowCol(0,0));
return TRUE;
}
//////////////////
// User selected a different item: change the form view.
//
void CMainFrame::OnItemChanged(NMLISTVIEW* pnmlv, LRESULT* pRes)
{
if ((pnmlv->uChanged & LVIF_STATE) &&
(pnmlv->uNewState & LVIS_SELECTED)) {
ViewForm(pnmlv->iItem); // change it
}
*pRes = 0;
}
//////////////////
// Handle View | Next Form command
//
void CMainFrame::OnViewNextForm()
{
UINT iWhich = FormData.GetCurrentForm();
UINT nForms = FormData.GetMaxNumForms();
if (++iWhich >= nForms)
iWhich = 0;
ViewForm(iWhich);
}
//////////////////
// Change the view in the right pane
//
void CMainFrame::ViewForm(UINT iWhich)
{
if (iWhich != FormData.GetCurrentForm()) {
TRACE("\nCMainFrame::ViewForm: %d\n", iWhich);
CMySplitterWnd& sw = m_wndSplitter;
sw.ChangeView(ROWFORMVIEW, COLFORMVIEW, FormData.GetViewClass(iWhich));
FormData.SetCurrentForm(iWhich);
}
}
//////////////////
// Route commands to splitter window.
//
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
// Pass to splitter
if (m_wndSplitter.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// Call default routing--very important!
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
//////////////////
// CDialog class to get the size of a dialog.
// Assumes dialog is invisible (no WS_VISIBLE).
//
class CTempDlg : public CDialog {
public:
CRect m_rcDlg;
protected:
virtual BOOL OnInitDialog();
};
////////////////
// Initialize dialog: save size, then quit.
// Ignore "dialog failed" TRACE from MFC.
//
BOOL CTempDlg::OnInitDialog()
{
GetWindowRect(&m_rcDlg);
m_rcDlg -= m_rcDlg.TopLeft();
EndDialog(0);
return TRUE;
}
//////////////////
// static fn uses CTempDlg to get the size of any dialog used in a CFormView.
//
static CSize GetDialogSize(LPCTSTR lpszTemplName, CWnd* pParent)
{
CTempDlg dlg;
dlg.Create(lpszTemplName, pParent);
return dlg.m_rcDlg.Size();
}
//////////////////
// Calculate the size of the total frame, given a desired client (form) size.
// Start with client rect and add all the extra stuff.
//
void CMainFrame::CalcWindowRect(PRECT prcClient, UINT nAdjustType)
{
CRect rect(0, 0, 32767, 32767);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery,
&rect, &rect, FALSE);
CSize szBorder = m_wndSplitter.GetBorderSize();
CSize szSplitter = m_wndSplitter.GetSplitterSize();
prcClient->bottom += rect.Height() + // total toolbar height +
GetSystemMetrics(SM_CYMENU) + // menu +
GetSystemMetrics(SM_CYCAPTION) + // title bar +
2 * GetSystemMetrics(SM_CYSIZEFRAME) + // top/bottom window frame +
2 * szBorder.cy; // splitter borders
prcClient->right += CXLIST + // left pane width
2 * GetSystemMetrics(SM_CXSIZEFRAME) + // L/R window border
4 * szBorder.cx + // 2 panes==> 4 borders
szSplitter.cx; // 1 splitter
}
FormSwap2.rar_image_多文档_多窗口 visual c++ _多视图_窗口
版权申诉
180 浏览量
2022-09-23
23:27:23
上传
评论 1
收藏 48KB RAR 举报
朱moyimi
- 粉丝: 65
- 资源: 1万+
最新资源
- Anaconda3-2024.02-1-Windows-x86-64.exe
- stm32cubemx can通信 一个板子负责传感器采集 一个板子负责wifi传递到网页 网页可控制传感器板子.zip
- k8s集群搭建1.27.1版本(来源于图灵k8s笔记)
- 树莓派连接 DS18B20 温度传感器读取温度时监控客户端,服务器端连接状况,实现断线重连机制
- 小游戏-坦克大战,你认为的小游戏
- 最好用的富文本编辑器wangeditor
- jQuery 3.7.1
- 校园失物招领小程序源码可作毕业设计
- SAP客户端GUI740安装包(JAVA版本)
- winlibs-x86-64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64msvcrt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈