读书人

左键一直响应信息的有关问题

发布时间: 2012-02-15 12:09:44 作者: rapoo

左键一直响应信息的问题
感谢dazedase等人的帮助,我想实现一个基于对话框的程序,上面有一个按钮,一个CEdit,我想要在按钮左键一直按下时,CEdit的值递增,按钮抬起时,停止递增,下面是CMyButton.cpp的代码,请大家帮忙,没太多分了,原谅
// MyButton.cpp : implementation file
//

#include "stdafx.h "
#include "test26.h "
#include "test26dlg.h "
#include "MyButton.h "

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyButton

CMyButton::CMyButton()
{


}

CMyButton::~CMyButton()
{
}


BEGIN_MESSAGE_MAP(CMyButton, CButton)
//{{AFX_MSG_MAP(CMyButton)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyButton message handlers

void CMyButton::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT nID = GetDlgCtrlID();
switch(nID)
{
case IDC_BUTTON1:
MessageBox( "Hello ");
break;
case IDC_BUTTON2:
MessageBox( "Hello ");
break;
}


CButton::OnRButtonDown(nFlags, point);
}

void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT nID = GetDlgCtrlID();
CTest26Dlg * pDlg=(CTest26Dlg *)GetParent();
switch(nID)
{
case IDC_BUTTON1:

//pDlg = new CTest26Dlg;

pDlg-> m_Edit1+=1;
UpdateData(FALSE);

break;


case IDC_BUTTON2:
MessageBox( "Hello ");
break;
}
//CButton::OnLButtonDown(nFlags, point);
}


[解决办法]
//Spin 使用
使用实例:
1建立一个基于对话框的应用程序,添加一个Edit控件、一个Spin控件
ID分别为:IDC_EDIT IDC_SPIN
Spin控件的TabOrder必须紧跟Edit控件

设置Spin的属性:
AUTOBUDDY、 SET BUDDY INTERGER 、 WRAP
对齐方式为Right

2.用ClassWizard给Spin添加成员变量:
CSpinButtonCtrl m_spin;

3.初始化
在对话框类的OnInitDialog中写入代码:
m_spin.SetRange(0,10);
m_spin.SetPos(5);

读书人网 >VC/MFC

热点推荐