不用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.在列表的结尾添加一项: ...
随机推荐
- 设计模式 ( 十三 ) 命令模式Command(对象行为型)
设计模式 ( 十三 ) 命令模式Command(对象行为型) 1.概述 在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需 ...
- 一步一步重写 CodeIgniter 框架 (8) —— 视图的嵌套输出与返回
视图函数在控制器中通过 $this->load-view() 来调用,从而输出 html,有时候为了调试或附加处理的需要,我们需要打印出这些输出,而不是直接通过浏览器输出,这在 php 中是通过 ...
- 如何将UISearchBar上"Cancel"按钮改为”取消“?
别说话,直接上代码 for (id obj in [searchBar subviews]) { if ([obj isKindOfClass:[UIView class]]) { ...
- C++逗号运算符与逗号表达式
C++将赋值表达式作为表达式的一种,使赋值操作不仅可以出现在赋值语句中,而且可以以表达式形式出现在其他语句(如输出语句.循环语句等)中.这是C++语言灵活性的一种表现. 请注意,用cout语句输出一个 ...
- WinDbg分析DUMP文件
1. 如何生成dump文件? 原理:通过SetUnhandledExceptionFilter设置捕获dump的入口,然后通过MiniDumpWriteDump生成dump文件: ...
- 利用xshell密钥管理服务器远程登录+VIM dd命令操作之伤之再伤
1.打开Xshell界面,中文界面方便操作,菜单栏:工具——新建用户密钥生成向导 2.密钥类型选择RSA,密钥长度选择2048位,单击下一步继续: 3.很快生成公钥对,单击下一步继续: 4.密钥名称可 ...
- 在uboot里面加入环境变量使用run来运行
Author:杨正 Date:2014.11.11 Email:yz2012ww@gmail.com QQ:1209758756 在移植uboot的时候,能够在uboot里面加入定义一些自己的环 ...
- codeforces #267 C George and Job(DP)
职务地址:http://codeforces.com/contest/467/problem/C 太弱了..这题当时都没做出来..思路是有的,可是自己出的几组数组总是过不去..今天又又一次写了一遍.才 ...
- #AOS应用基础平台# 添加了用户自己定义快捷菜单在平铺布局下的用户自己定义排序管理
#AOS开发平台# 添加了用户自己定义快捷菜单在平铺布局下的用户自己定义排序管理.
- asp.net 中将汉字转换成拼音
/// <summary> /// 获取汉字的全拼音 /// </summary> /// <param name="x">传汉字的字符串< ...