不用splitter控件  简单实现对mfc对话框的分割的方法

直接贴上源代码主要部分吧

这个是基于对话框的工程 进行对话框的分割实现

只是相应了三个消息函数,看一下就会明白的

我空间资源里边有现成的工程代码可以下载运行

.cpp 文件

  1. // spliteDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "splite.h"
  5. #include "spliteDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSpliteDlg dialog
  13. CSpliteDlg::CSpliteDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSpliteDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSpliteDlg)
  17. //}}AFX_DATA_INIT
  18. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  19. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  20. m_SplitCursor = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_CURSOR_SPLIT));
  21. }
  22. void CSpliteDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CSpliteDlg)
  26. DDX_Control(pDX, IDC_LIST, m_edit);
  27. DDX_Control(pDX, IDC_TREE, m_tree);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CSpliteDlg, CDialog)
  31. //{{AFX_MSG_MAP(CSpliteDlg)
  32. ON_WM_MOUSEMOVE()
  33. ON_WM_LBUTTONDOWN()
  34. ON_WM_LBUTTONUP()
  35. ON_WM_SIZE()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CSpliteDlg message handlers
  40. #define SIZEBAR          2// Space BTW Tree and Edit
  41. BOOL CSpliteDlg::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. // Set the icon for this dialog.  The framework does this automatically
  45. //  when the application's main window is not a dialog
  46. SetIcon(m_hIcon, TRUE);         // Set big icon
  47. SetIcon(m_hIcon, FALSE);        // Set small icon
  48. CRect rect ;
  49. GetClientRect( &rect );
  50. // TODO: Add extra initialization here
  51. CRect treepos ;
  52. m_tree.GetClientRect( treepos );
  53. m_tree.MoveWindow(0, 0, treepos.Width(), rect.Height() );
  54. m_edit.MoveWindow(treepos.Width() +SIZEBAR , 0, rect.Width()-(treepos.Width() +SIZEBAR), rect.Height() );
  55. return TRUE;  // return TRUE  unless you set the focus to a control
  56. }
  57. void CSpliteDlg::OnMouseMove(UINT nFlags, CPoint point)
  58. {
  59. // TODO: Add your message handler code here and/or call default
  60. CRect treepos ;
  61. m_tree.GetWindowRect( &treepos );
  62. ScreenToClient( &treepos );
  63. CRect editpos ;
  64. m_edit.GetWindowRect( &editpos );
  65. ScreenToClient( &editpos );
  66. CRect rc;
  67. rc.left = treepos.right;
  68. rc.right = editpos.left;
  69. rc.top = treepos.top;
  70. rc.bottom = treepos.bottom;
  71. CRect rect;
  72. GetClientRect( &rect );
  73. if ( rect.PtInRect(point) )
  74. {
  75. SetCursor(m_SplitCursor);  //设置鼠标光标形状
  76. if ( nFlags & MK_LBUTTON )
  77. {
  78. ResizeWindows(point.x, rect.right-rect.left);
  79. }
  80. }
  81. else
  82. {
  83. if(m_bButtonDown)
  84. {
  85. m_bButtonDown = FALSE;
  86. ReleaseCapture();
  87. }
  88. }
  89. CDialog::OnMouseMove(nFlags, point);
  90. }
  91. void CSpliteDlg::ResizeWindows( int CxBarAt, int len )
  92. {
  93. CRect treepos ;
  94. m_tree.GetClientRect( &treepos );
  95. CRect rect ;
  96. GetClientRect( &rect );
  97. if(CxBarAt <= 1)
  98. CxBarAt = 1;
  99. if(CxBarAt >= len - 1)
  100. CxBarAt = len - 1;
  101. // 移动tree窗口
  102. m_tree.MoveWindow( 0,0, CxBarAt-SIZEBAR, rect.Height() );
  103. // 移动edit窗口
  104. m_edit.MoveWindow(CxBarAt, 0, rect.right-CxBarAt, rect.Height());
  105. }
  106. void CSpliteDlg::OnLButtonDown(UINT nFlags, CPoint point)
  107. {
  108. // TODO: Add your message handler code here and/or call default
  109. m_bButtonDown = TRUE;
  110. CRect treepos ;
  111. m_tree.GetWindowRect( &treepos );
  112. ScreenToClient( &treepos );
  113. CRect editpos ;
  114. m_edit.GetWindowRect( &editpos );
  115. ScreenToClient( &editpos );
  116. CRect rect;
  117. rect.left = treepos.right;
  118. rect.right = editpos.left;
  119. rect.top = treepos.top;
  120. rect.bottom = treepos.bottom;
  121. //  CRect rect;
  122. //  GetClientRect( &rect );
  123. if ( rect.PtInRect(point) )
  124. {
  125. SetCursor(m_SplitCursor);
  126. }
  127. SetCapture();
  128. CDialog::OnLButtonDown(nFlags, point);
  129. }
  130. void CSpliteDlg::OnLButtonUp(UINT nFlags, CPoint point)
  131. {
  132. // TODO: Add your message handler code here and/or call default
  133. m_bButtonDown=FALSE;
  134. ReleaseCapture();
  135. CDialog::OnLButtonUp(nFlags, point);
  136. }
  137. void CSpliteDlg::OnSize(UINT nType, int cx, int cy)
  138. {
  139. CDialog::OnSize(nType, cx, cy);
  140. // TODO: Add your message handler code here
  141. if((IsWindow(m_tree.m_hWnd)) && (IsWindow(m_edit.m_hWnd)))
  142. {// get sizes; width of tree never changed
  143. CRect rcTree;
  144. m_tree.GetClientRect(&rcTree);
  145. CRect rcEdit;
  146. m_edit.GetClientRect(&rcEdit);
  147. // 移动tree控件
  148. rcTree.bottom=cy;
  149. m_tree.MoveWindow(&rcTree,TRUE);
  150. // 移动edit控件
  151. rcEdit.left=rcTree.right+SIZEBAR;
  152. rcEdit.right=cx;
  153. rcEdit.top=0;
  154. rcEdit.bottom=rcTree.bottom;
  155. m_edit.MoveWindow(&rcEdit,TRUE);
  156. }
  157. }

.h 头文件

    1. // spliteDlg.h : header file
    2. //
    3. #if !defined(AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_)
    4. #define AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_
    5. #if _MSC_VER > 1000
    6. #pragma once
    7. #endif // _MSC_VER > 1000
    8. /////////////////////////////////////////////////////////////////////////////
    9. // CSpliteDlg dialog
    10. class CSpliteDlg : public CDialog
    11. {
    12. // Construction
    13. public:
    14. CSpliteDlg(CWnd* pParent = NULL);   // standard constructor
    15. // Dialog Data
    16. //{{AFX_DATA(CSpliteDlg)
    17. enum { IDD = IDD_SPLITE_DIALOG };
    18. CListCtrl   m_edit;
    19. CTreeCtrl   m_tree;
    20. //}}AFX_DATA
    21. // ClassWizard generated virtual function overrides
    22. //{{AFX_VIRTUAL(CSpliteDlg)
    23. protected:
    24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    25. //}}AFX_VIRTUAL
    26. // Implementation
    27. protected:
    28. HICON m_hIcon;
    29. // Generated message map functions
    30. //{{AFX_MSG(CSpliteDlg)
    31. virtual BOOL OnInitDialog();
    32. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    33. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    34. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    35. afx_msg void OnSize(UINT nType, int cx, int cy);
    36. //}}AFX_MSG
    37. DECLARE_MESSAGE_MAP()
    38. private:
    39. void ResizeWindows(int CxBarAt, int len );
    40. private:
    41. HCURSOR     m_SplitCursor;
    42. BOOL        m_bButtonDown;
    43. };
    44. //{{AFX_INSERT_LOCATION}}
    45. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    46. #endif // !defined(AFX_SPLITEDLG_H__5C7DA2C0_E37E_426A_A7D3_E1DC7DFD2766__INCLUDED_)

不用splitter控件 简单实现对mfc对话框的分割的方法的更多相关文章

  1. C++ Builder中splitter控件的使用方法简介

    C++ Builder提供了一个Splitter控件来实现对用户窗口的分割,只需拖动该控件到窗体上,就可以实现窗口的任意分割.把面板控件(Panel)拖动到窗体上,设置其对齐方式,然后把Splitte ...

  2. iOS开发UI篇—Date Picker和UITool Bar控件简单介绍

    iOS开发UI篇—Date Picker和UITool Bar控件简单介绍 一.Date Picker控件 1.简单介绍: Date Picker显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...

  3. iOS开发UI篇—UITableview控件简单介绍

    iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...

  4. c# splitter控件使用简介

    摘自:http://blog.itpub.net/26221264/viewspace-735903 1.先在窗体上放置部分一的控件,这里是TreeView控件,然后把它的 Dock 属性设置为 Le ...

  5. .net分页控件简单实现

    .net分页控件简单实现 好久好久没写博客了.....最近写了一个.net的分页控件,放到园子里...你觉得好,就点个赞,不好呢,就告诉我为啥吧.... 是使用Request.QueryString的 ...

  6. Victor 串口 VCL 控件 - 简单实用, 功能强大的 C++ Builder 串口控件!

    源:Victor 串口 VCL 控件 - 简单实用, 功能强大的 C++ Builder 串口控件! 2014年02月06日发布控件的重要更新版本: Victor 串口控件 1.5.0.2 版本 (包 ...

  7. iOS开发基础-UITableView控件简单介绍

     UITableView 继承自 UIScrollView ,用于实现表格数据展示,支持垂直滚动.  UITableView 需要一个数据源来显示数据,并向数据源查询一共有多少行数据以及每一行显示什么 ...

  8. ASP.NET AJAX入门系列(6):UpdateProgress控件简单介绍

    在ASP.NET AJAX Beta2中,UpdateProgress控件已经从“增值”CTP中移到了ASP.NET AJAX核心中.以下两篇关于UpdateProgress的文章基本翻译自ASP.N ...

  9. 列表控件ListBox关联的MFC中的类:CListBox

    列表控件ListBox关联的MFC中的类:CListBox ######################################################## 1.在列表的结尾添加一项: ...

随机推荐

  1. zabbix 添加主机成功失败判断

    zabbix 成功添加后: $VAR1 = bless( { 'version' => 0, 'content' => { 'jsonrpc' => '2.0', 'id' => ...

  2. 设计模式 ( 二十 ) 访问者模式Visitor(对象行为型)

    设计模式 ( 二十 ) 访问者模式Visitor(对象行为型) 1.概述 在软件开发过程中,对于系统中的某些对象,它们存储在同一个集合collection中,且具有不同的类型,而且对于该集合中的对象, ...

  3. 基于端口的VLAN典型配置指导

    本文为转发,简单明了,我喜欢 VLAN典型配置全过程如下: 组网图 图1-1 基于端口的VLAN组网示意图 应用要求 如图1-1所示,Switch A和Switch B分别连接了不同部门使用的Host ...

  4. WinForm - 两个窗体之间的方法调用

    方法1:   所有权法//Form1://需要有一个公共的刷新方法public   void   Refresh_Method(){ //...} //在调用Form2时,要把Form2的所有者设为F ...

  5. arm汇编:ldr,str,ldm,stm,伪指令ldr

    ldr,str,ldm,stm的命名规律: 这几个指令命名看起来不易记住,现在找找规律. 指令 样本 效果 归纳名称解释 ldr Rd,addressing ldr r1,[r0] addressin ...

  6. the Meta-Object Compiler (moc)

    the Meta-Object Compiler (moc) 元对象编译器是处理Qt的C++扩展的程序. moc工具读取C++头文件,如果它找到一个或者多个类声明包含Q_OBJECT宏.它生为那些类成 ...

  7. Android dialog 问题

    1.dialog.dismiss和dialog.cancel的区别 Cancel the dialog. This is essentially the same as calling dismiss ...

  8. 清华集训2014 day1 task1 玛里苟斯

    题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...

  9. 查询SystemFeature的方法

    查询SystemFeature的方法可以在adb shell下敲如下的命令: dumpsys package 然后搜feature关键字. 例如,我的平台的SystemFeature,如下所示: Fe ...

  10. 3890: [Usaco2015 Jan]Meeting Time( dp )

    简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) --------------------------- ...