Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5381680
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: C/C++

2009-01-13 17:35:51

Class to Auto-Position Controls on Window Resize
Rating: none

Paul Wendt ()
November 3, 2000


Introduction

Have you ever wanted to resize a window but NOT have to deal with all of that annoying control-repositioning? What a hassle! Here is an easy-to-use class that should provide a good foundation for anyone wishing to easily reposition controls when a user resizes the parent window.

Usage

In order to use this class, simply follow these steps:
  1. Create a CControlPos member variable in your CDialog (used in example) or CView derived class.
    class CYourDialog : public CDialog
    {
    ...
     CControlPos m_cControlPos;
    
  2. In the OnInitDialog (or InitialUpdate) function, set the object's parent window
    BOOL CYourDialog::OnInitDialog()
    ...
     m_cControlPos.SetParent(this);
    ...
    
  3. After the call to CControlPos::SetParent, Add the controls you want to resize.
    m_cControlPos.AddControl(IDOK, CP_MOVE_HORIZONTAL);
    m_cControlPos.AddControl(IDCANCEL, CP_MOVE_HORIZONTAL);
    
  4. Finally, on your WM_SIZE handler, call the object's MoveControls to specify runtime behaviour. move all of the controls. Controls can be moved horizontally and vertically and resized horizontally and vertically.
    void CYourDialog::OnSize(UINT nType, int cx, int cy)
    {
     CDialog::OnSize(nType, cx, cy);
    
     m_cControlPos.MoveControls();
    }
    

Downloads


阅读(1003) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~