不用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.在列表的结尾添加一项: ...
随机推荐
- 基于visual Studio2013解决算法导论之047赫夫曼编码
题目 赫夫曼编码 解决代码及点评 // 赫夫曼编码.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stdio.h ...
- 基于visual Studio2013解决C语言竞赛题之0418位数操作
题目 解决代码及点评 /************************************************************************/ /* 18. 给 ...
- Debian上安装TightVNC Server
from:www.penlug.org/twiki/bin/view/Main/TightVNC Using VNC The tool vncserver allows you to run ad ...
- Derby的下载安装和使用,(和JAVA中使用Derby)
首先是Java环境变量要配置: 1.打开我的电脑--属性--高级--环境变量 2.新建系统变量JAVA_HOME 和CLASSPATH 变量名:JAVA_HOME 变量值:C:\Program Fil ...
- CSS基础3——使用CSS格式化元素内容的字体
1.CSS属性单位: (1)长度单位:包含绝对长度单位和相对长度单位 绝对长度单位包含:cm.mm.in.pt.pc等. 绝对长度单位最好用于打印输出设备.在仅作为频幕显示时.绝对长度值并没有什么意义 ...
- LVS:DR模式(Direct Routing)部署实验
本文介绍怎样在kvm的虚拟环境下,部署实验LVS的DR模式.包含网络结构图,怎样配置.以及使用tcpdump分析ip包. 网络结构图 kvm ...
- Log4Net五步走
本文不是教你全面了解log4net,本文只是希望教会你按步就班,照糊芦画瓢般就会用log4net1,引入log4net.dll组件2,建立一个配置文件两种方法,一种是在Web.Config或App.C ...
- Bootstrap技术: 模式对话框的使用
一.概述 说到模式对话框,大家肯定都会想到windows下GUI程序,在gui程序中,有大量的对话框. 在web程序中,随着页面交互式功能的增多,有很多场景下也会用到对话框.在html原生的支持下,有 ...
- PowerMock mock私有方法
import java.util.Random; public class CodeWithPrivateMethod { public void meaningfulPublicApi() { if ...
- Windows Azure 网站的 IP 和域限制
编辑人员注释:本文章由 Windows Azure 网站团队的首席项目经理 Stefan Schackow 撰写. 配置 Azure 网站 (WAWS) 的 IP 和域限制一直是用户最迫切希望我们提供 ...