soui4中拓展spinButton控件使其支持double类型或者其他类型

#pragma once
class CSpinButtonCtrlEx : public SSpinButtonCtrl
{
	DEF_SOBJECT(CSpinButtonCtrlEx, L"spinButtonEx")
public:
	CSpinButtonCtrlEx();
	~CSpinButtonCtrlEx();

public:
	int GetActionButton();
};
#include "stdafx.h"
#include "CSpinButtonCtrlEx.h"
CSpinButtonCtrlEx::CSpinButtonCtrlEx()
{
}

CSpinButtonCtrlEx::~CSpinButtonCtrlEx()
{
}

int CSpinButtonCtrlEx::GetActionButton()
{
	//获取点击的up或者down按钮
	return m_iActionBtn;
}

主要的地方就是先获取按下的状态根据自身的业务做加减操作或者递增递减操作
使用:
1、控件注册

m_theApp->RegisterWindowClass<CSpinButtonCtrlEx>();

2、在布局中使用控件

<edit name="edit_name" inset="5,0,0,25" pos="[0,{0,@100,@30" font="face:微软雅黑,size:12"/>
<spinButtonEx name="spin_edit_name" pos="[-20,{5"></spinButtonEx>

在这里插入图片描述
将spin控件点击事件跟edit关联起来

void OnBnClickNameSpin()
{
	CSpinButtonCtrlEx* pSpin = FindChildByName2<CSpinButtonCtrlEx>(L"spin_edit_name");
	SEdit* pEdit = FindChildByName2<SEdit>(L"edit_name");
	SASSERT(pSpin);
	SASSERT(pEdit);

	//1、获取edit内容
	SStringW sstrValue = pEdit->GetWindowTextW();
	//假设内容为double类型
	double dValue = std::stod(sstrValue.GetBuffer());
	//2、获取spin的状态,以及根据状态处理内容
	int nActionButton = pSpin->GetActionButton();
	switch (nActionButton)
	{
	case 0:		//up 
		dValue += 0.1;
		break;
	case 1:		//down
		dValue -= 0.1;
		break;
	default:
		break;
	}
	
	//3、重新设置edit内容
	SStringW sstrContent;
	sstrContent.Format(L"%0.2f", dValue);
	pEdit->SetWindowTextW(sstrContent);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值