不用splitter控件 简单实现对mfc对话框的分割的方法
不用splitter控件 简单实现对mfc对话框的分割的方法
直接贴上源代码主要部分吧
这个是基于对话框的工程 进行对话框的分割实现
只是相应了三个消息函数,看一下就会明白的
我空间资源里边有现成的工程代码可以下载运行
.cpp 文件
- // spliteDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "splite.h"
- #include "spliteDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSpliteDlg dialog
- CSpliteDlg::CSpliteDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSpliteDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSpliteDlg)
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_SplitCursor = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_CURSOR_SPLIT));
- }
- void CSpliteDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSpliteDlg)
- DDX_Control(pDX, IDC_LIST, m_edit);
- DDX_Control(pDX, IDC_TREE, m_tree);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSpliteDlg, CDialog)
- //{{AFX_MSG_MAP(CSpliteDlg)
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSpliteDlg message handlers
- #define SIZEBAR 2// Space BTW Tree and Edit
- BOOL CSpliteDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- CRect rect ;
- GetClientRect( &rect );
- // TODO: Add extra initialization here
- CRect treepos ;
- m_tree.GetClientRect( treepos );
- m_tree.MoveWindow(0, 0, treepos.Width(), rect.Height() );
- m_edit.MoveWindow(treepos.Width() +SIZEBAR , 0, rect.Width()-(treepos.Width() +SIZEBAR), rect.Height() );
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CSpliteDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CRect treepos ;
- m_tree.GetWindowRect( &treepos );
- ScreenToClient( &treepos );
- CRect editpos ;
- m_edit.GetWindowRect( &editpos );
- ScreenToClient( &editpos );
- CRect rc;
- rc.left = treepos.right;
- rc.right = editpos.left;
- rc.top = treepos.top;
- rc.bottom = treepos.bottom;
- CRect rect;
- GetClientRect( &rect );
- if ( rect.PtInRect(point) )
- {
- SetCursor(m_SplitCursor); //设置鼠标光标形状
- if ( nFlags & MK_LBUTTON )
- {
- ResizeWindows(point.x, rect.right-rect.left);
- }
- }
- else
- {
- if(m_bButtonDown)
- {
- m_bButtonDown = FALSE;
- ReleaseCapture();
- }
- }
- CDialog::OnMouseMove(nFlags, point);
- }
- void CSpliteDlg::ResizeWindows( int CxBarAt, int len )
- {
- CRect treepos ;
- m_tree.GetClientRect( &treepos );
- CRect rect ;
- GetClientRect( &rect );
- if(CxBarAt <= 1)
- CxBarAt = 1;
- if(CxBarAt >= len - 1)
- CxBarAt = len - 1;
- // 移动tree窗口
- m_tree.MoveWindow( 0,0, CxBarAt-SIZEBAR, rect.Height() );
- // 移动edit窗口
- m_edit.MoveWindow(CxBarAt, 0, rect.right-CxBarAt, rect.Height());
- }
- void CSpliteDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_bButtonDown = TRUE;
- CRect treepos ;
- m_tree.GetWindowRect( &treepos );
- ScreenToClient( &treepos );
- CRect editpos ;
- m_edit.GetWindowRect( &editpos );
- ScreenToClient( &editpos );
- CRect rect;
- rect.left = treepos.right;
- rect.right = editpos.left;
- rect.top = treepos.top;
- rect.bottom = treepos.bottom;
- // CRect rect;
- // GetClientRect( &rect );
- if ( rect.PtInRect(point) )
- {
- SetCursor(m_SplitCursor);
- }
- SetCapture();
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CSpliteDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_bButtonDown=FALSE;
- ReleaseCapture();
- CDialog::OnLButtonUp(nFlags, point);
- }
- void CSpliteDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- if((IsWindow(m_tree.m_hWnd)) && (IsWindow(m_edit.m_hWnd)))
- {// get sizes; width of tree never changed
- CRect rcTree;
- m_tree.GetClientRect(&rcTree);
- CRect rcEdit;
- m_edit.GetClientRect(&rcEdit);
- // 移动tree控件
- rcTree.bottom=cy;
- m_tree.MoveWindow(&rcTree,TRUE);
- // 移动edit控件
- rcEdit.left=rcTree.right+SIZEBAR;
- rcEdit.right=cx;
- rcEdit.top=0;
- rcEdit.bottom=rcTree.bottom;
- m_edit.MoveWindow(&rcEdit,TRUE);
- }
- }
.h 头文件
- // spliteDlg.h : header file
- //
- #if !defined(AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_)
- #define AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- /////////////////////////////////////////////////////////////////////////////
- // CSpliteDlg dialog
- class CSpliteDlg : public CDialog
- {
- // Construction
- public:
- CSpliteDlg(CWnd* pParent = NULL); // standard constructor
- // Dialog Data
- //{{AFX_DATA(CSpliteDlg)
- enum { IDD = IDD_SPLITE_DIALOG };
- CListCtrl m_edit;
- CTreeCtrl m_tree;
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CSpliteDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- HICON m_hIcon;
- // Generated message map functions
- //{{AFX_MSG(CSpliteDlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
- afx_msg void OnSize(UINT nType, int cx, int cy);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- private:
- void ResizeWindows(int CxBarAt, int len );
- private:
- HCURSOR m_SplitCursor;
- BOOL m_bButtonDown;
- };
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_)
不用splitter控件 简单实现对mfc对话框的分割的方法的更多相关文章
- C++ Builder中splitter控件的使用方法简介
C++ Builder提供了一个Splitter控件来实现对用户窗口的分割,只需拖动该控件到窗体上,就可以实现窗口的任意分割.把面板控件(Panel)拖动到窗体上,设置其对齐方式,然后把Splitte ...
- iOS开发UI篇—Date Picker和UITool Bar控件简单介绍
iOS开发UI篇—Date Picker和UITool Bar控件简单介绍 一.Date Picker控件 1.简单介绍: Date Picker显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...
- iOS开发UI篇—UITableview控件简单介绍
iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...
- c# splitter控件使用简介
摘自:http://blog.itpub.net/26221264/viewspace-735903 1.先在窗体上放置部分一的控件,这里是TreeView控件,然后把它的 Dock 属性设置为 Le ...
- .net分页控件简单实现
.net分页控件简单实现 好久好久没写博客了.....最近写了一个.net的分页控件,放到园子里...你觉得好,就点个赞,不好呢,就告诉我为啥吧.... 是使用Request.QueryString的 ...
- Victor 串口 VCL 控件 - 简单实用, 功能强大的 C++ Builder 串口控件!
源:Victor 串口 VCL 控件 - 简单实用, 功能强大的 C++ Builder 串口控件! 2014年02月06日发布控件的重要更新版本: Victor 串口控件 1.5.0.2 版本 (包 ...
- iOS开发基础-UITableView控件简单介绍
UITableView 继承自 UIScrollView ,用于实现表格数据展示,支持垂直滚动. UITableView 需要一个数据源来显示数据,并向数据源查询一共有多少行数据以及每一行显示什么 ...
- ASP.NET AJAX入门系列(6):UpdateProgress控件简单介绍
在ASP.NET AJAX Beta2中,UpdateProgress控件已经从“增值”CTP中移到了ASP.NET AJAX核心中.以下两篇关于UpdateProgress的文章基本翻译自ASP.N ...
- 列表控件ListBox关联的MFC中的类:CListBox
列表控件ListBox关联的MFC中的类:CListBox ######################################################## 1.在列表的结尾添加一项: ...
随机推荐
- zabbix 添加主机成功失败判断
zabbix 成功添加后: $VAR1 = bless( { 'version' => 0, 'content' => { 'jsonrpc' => '2.0', 'id' => ...
- 设计模式 ( 二十 ) 访问者模式Visitor(对象行为型)
设计模式 ( 二十 ) 访问者模式Visitor(对象行为型) 1.概述 在软件开发过程中,对于系统中的某些对象,它们存储在同一个集合collection中,且具有不同的类型,而且对于该集合中的对象, ...
- 基于端口的VLAN典型配置指导
本文为转发,简单明了,我喜欢 VLAN典型配置全过程如下: 组网图 图1-1 基于端口的VLAN组网示意图 应用要求 如图1-1所示,Switch A和Switch B分别连接了不同部门使用的Host ...
- WinForm - 两个窗体之间的方法调用
方法1: 所有权法//Form1://需要有一个公共的刷新方法public void Refresh_Method(){ //...} //在调用Form2时,要把Form2的所有者设为F ...
- arm汇编:ldr,str,ldm,stm,伪指令ldr
ldr,str,ldm,stm的命名规律: 这几个指令命名看起来不易记住,现在找找规律. 指令 样本 效果 归纳名称解释 ldr Rd,addressing ldr r1,[r0] addressin ...
- the Meta-Object Compiler (moc)
the Meta-Object Compiler (moc) 元对象编译器是处理Qt的C++扩展的程序. moc工具读取C++头文件,如果它找到一个或者多个类声明包含Q_OBJECT宏.它生为那些类成 ...
- Android dialog 问题
1.dialog.dismiss和dialog.cancel的区别 Cancel the dialog. This is essentially the same as calling dismiss ...
- 清华集训2014 day1 task1 玛里苟斯
题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...
- 查询SystemFeature的方法
查询SystemFeature的方法可以在adb shell下敲如下的命令: dumpsys package 然后搜feature关键字. 例如,我的平台的SystemFeature,如下所示: Fe ...
- 3890: [Usaco2015 Jan]Meeting Time( dp )
简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) --------------------------- ...