// PluckBoxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PluckBox.h"
#include "PluckBoxDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPluckBoxDlg dialog
CPluckBoxDlg::CPluckBoxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPluckBoxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPluckBoxDlg)
m_Edit = _T("单击边框上的按钮调整文本框大小\r\n\r\n 作者:风林");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPluckBoxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPluckBoxDlg)
DDX_Control(pDX, IDC_BUTTONUP, m_ButtonUp);
DDX_Control(pDX, IDC_BUTTONRIGHT, m_ButtonRight);
DDX_Control(pDX, IDC_BUTTONLEFT, m_ButtonLeft);
DDX_Control(pDX, IDC_BUTTONDOWN, m_ButtonDown);
DDX_Text(pDX, IDC_EDIT1, m_Edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPluckBoxDlg, CDialog)
//{{AFX_MSG_MAP(CPluckBoxDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONDOWN, OnButtondown)
ON_BN_CLICKED(IDC_BUTTONLEFT, OnButtonleft)
ON_BN_CLICKED(IDC_BUTTONRIGHT, OnButtonright)
ON_BN_CLICKED(IDC_BUTTONUP, OnButtonup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPluckBoxDlg message handlers
BOOL CPluckBoxDlg::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
// TODO: Add extra initialization here
//设置推拉窗口按钮初始状态
m_ButtonLeft.SetPluckButStyle( KEY_STYLE_LEFT ); //左边按钮
m_ButtonUp.SetPluckButStyle( KEY_STYLE_UP ); //上边按钮
m_ButtonRight.SetPluckButStyle( KEY_STYLE_RIGHT ); //右边按钮
m_ButtonDown.SetPluckButStyle( KEY_STYLE_DOWN ); //下边按钮
m_start = WS_NORMAL; //窗口初始状态(正常)
CWnd *pWnd = GetDlgItem( IDC_EDIT1 ); //求编辑框尺寸和正常时的位置
pWnd->GetWindowRect( &m_Rect[WS_NORMAL] );
ScreenToClient( &m_Rect[WS_NORMAL] );
CRect m_ClientRect;
this->GetClientRect( &m_ClientRect ); //获取客户区尺寸
//求各状态下工作区坐标:
//工作区向左伸展
m_Rect[WS_LEFT].SetRect( 8, m_Rect[WS_NORMAL].top, m_Rect[WS_NORMAL].right, m_Rect[WS_NORMAL].bottom );
//工作区向左、向上伸展
m_Rect[WS_LEFT_UP].SetRect( 8, 8, m_Rect[WS_NORMAL].right, m_Rect[WS_NORMAL].bottom );
//工作区向左、向上、向右伸展
m_Rect[WS_LEFT_UP_RIGHT].SetRect( 8, 8, m_ClientRect.right-8, m_Rect[WS_NORMAL].bottom );
//工作区向四周伸展
m_Rect[WS_LEFT_UP_RIGHT_DOWN].SetRect( 8, 8, m_ClientRect.right-8, m_ClientRect.bottom-8 );
//工作区向下伸展
m_Rect[WS_LEFT_DOWN].SetRect( 8, m_Rect[WS_NORMAL].top, m_Rect[WS_NORMAL].right, m_ClientRect.bottom-8 );
//工作区向下、向右伸展
m_Rect[WS_LEFT_RIGHT_DOWN].SetRect( 8, m_Rect[WS_NORMAL].top, m_ClientRect.right-8, m_ClientRect.bottom-8 );
//工作区向下、向左、向右伸展
m_Rect[WS_LEFT_UP_DOWN].SetRect( 8, 8, m_Rect[WS_NORMAL].right, m_ClientRect.bottom-8 );
//工作区向左、向右伸展
m_Rect[WS_LEFT_RIGHT].SetRect( 8, m_Rect[WS_NORMAL].top, m_ClientRect.right-8, m_Rect[WS_NORMAL].bottom );
//工作区向上伸展
m_Rect[WS_UP].SetRect( m_Rect[WS_NORMAL].left, 8, m_Rect[WS_NORMAL].right, m_Rect[WS_NORMAL].bottom );
//工作区向上、向右伸展
m_Rect[WS_UP_RIGHT].SetRect( m_Rect[WS_NORMAL].left, 8, m_ClientRect.right-8, m_Rect[WS_NORMAL].bottom );
//工作区向上、向右、向下伸展
m_Rect[WS_UP_RIGHT_DOWN].SetRect( m_Rect[WS_NORMAL].left, 8, m_ClientRect.right-8, m_ClientRect.bottom-8 );
//工作区向上、向下伸展
m_Rect[WS_UP_DOWN].SetRect( m_Rect[WS_NORMAL].left, 8, m_Rect[WS_NORMAL].right, m_ClientRect.bottom-8 );
//工作区向右伸展
m_Rect[WS_RIGHT].SetRect( m_Rect[WS_NORMAL].left, m_Rect[WS_NORMAL].top, m_ClientRect.right-8, m_Rect[WS_NORMAL].bottom );
//工作区向右、向下伸展
m_Rect[WS_RIGHT_DOWN].SetRect( m_Rect[WS_NORMAL].left, m_Rect[WS_NORMAL].top, m_ClientRect.right-8, m_ClientRect.bottom-8 );
//工作区向下伸展
m_Rect[WS_DOWN].SetRect( m_Rect[WS_NORMAL].left, m_Rect[WS_NORMAL].top, m_Rect[WS_NORMAL].right, m_ClientRect.bottom-8 );
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
// 重绘窗口函数
void CPluckBoxDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
DrawWorkings(&dc); //绘制工作区
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPluckBoxDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
////////////////////////////////////////////////////////////////////////////////
//绘制工作区,位置取决于m_Rect[m_start]
void CPluckBoxDlg::DrawWorkings(CPaintDC *pdc)
{
CWnd *pWnd = GetDlgItem( IDC_EDIT1 ); //调整编辑框位置
pWnd->SetWindowPos( NULL, m_Rect[m_start].left, m_Rect[m_start].top, m_Rect[m_start].Width(), m_Rect[m_start].Height(), SWP_NOZORDER );
CBrush Brush; //画边框
Brush.CreateSolidBrush( RGB(97,120,140) );
pdc->SelectObject( &Brush );
pdc->RoundRect(m_Rect[m_start].left-9, m_Rect[m_start].top-9, m_Rect[m_start].right+9, m_Rect[m_start].bottom+9, 10, 10 );
//以下根据编辑框坐标调整各按钮位置
pWnd = GetDlgItem( IDC_BUTTONLEFT ); //调整左边按钮位置
pWnd->SetWindowPos( NULL, m_Rect[m_start].left-9, m_Rect[m_start].CenterPoint().y-30, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
pWnd = GetDlgItem( IDC_BUTTONUP ); //调整上边按钮位置
pWnd->SetWindowPos( NULL, m_Rect[m_start].CenterPoint().x-30, m_Rect[m_start].top-9, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
pWnd = GetDlgItem( IDC_BUTTONRIGHT ); //调整右边按钮位置
pWnd->SetWindowPos( NULL, m_Rect[m_start].right, m_Rect[m_start].CenterPoint().y-30, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
pWnd = GetDlgItem( IDC_BUTTONDOWN ); //调整下边按钮位置
pWnd->SetWindowPos( NULL, m_Rect[m_start].CenterPoint().x-30, m_Rect[m_start].bottom, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
}
//单击下边按钮
void CPluckBoxDlg::OnButtondown()
{
switch(m_start) //更改位置
{
case WS_NORMAL: m_start = WS_DOWN; break;
case WS_LEFT: m_start = WS_LEFT_DOWN; break;
case WS_LEFT_UP: m_start = WS_LEFT_UP_DOWN; break;
case WS_LEFT_UP_RIGHT: m_start = WS_LEFT_UP_RIGHT_DOWN; break;
case WS_LEFT_UP_RIGHT_DOWN: m_start = WS_LEFT_UP_RIGHT; break;
case WS_LEFT_DOWN: m_start = WS_LEFT; break;
case WS_LEFT_RIGHT_DOWN: m_start = WS_LEFT_RIGHT; break;
case WS_LEFT_UP_DOWN: m_start = WS_LEFT_UP; break;
case WS_LEFT_RIGHT: m_start = WS_LEFT_RIGHT_DOWN; break;
case WS_UP: m_start = WS_UP_DOWN; break;
case WS_UP_RIGHT: m_start = WS_UP_RIGHT_DOWN; break;
case WS_UP_RIGHT_DOWN: m_start = WS_UP_RIGHT; break;
case WS_UP_DOWN: m_start = WS_UP; break;
case WS_RIGHT: m_start = WS_RIGHT_DOWN; break;
case WS_RIGHT_DOWN: m_start = WS_RIGHT; break;
case WS_DOWN: m_start = WS_NORMAL; break;
}
Invalidate(); //重绘对话框
}
//单击左边按钮
void CPluckBoxDlg::OnButtonleft()
{
switch(m_start)
{
case WS_NORMAL: m_start = WS_LEFT; break;
case WS_LEFT: m_start = WS_NORMAL; break;
case WS_LE
评论0