学习日志:圆盘型按钮(上下左右)重绘

在CameraController程序中,一、按钮消息响应机制:云台控制和镜头控制的所有消息响应,都经过PreTranslateMessage(MSG* pMsg)进行消息截获:以前见过这个函数的使用:BOOL CYTCONTROLDlg::PreTranslateMessage
摘要由CSDN通过智能技术生成

在CameraController程序中,

一、按钮消息响应机制:

云台控制和镜头控制的所有消息响应,都经过PreTranslateMessage(MSG* pMsg)进行消息截获:

以前见过这个函数的使用:

BOOL CYTCONTROLDlg::PreTranslateMessage(MSG* pMsg)   //可以实现鼠标按下执行上下左右命令,释放鼠标执行停的效果
 {
   // TODO: Add your specialized code here and/or call the base class

   if (pMsg->message==WM_LBUTTONDOWN)
  {
        if ( pMsg->hwnd == GetDlgItem(IDC_BUTTON_LEFT)->m_hWnd )
             OnButtonLeft();    
         if ( pMsg->hwnd == GetDlgItem(IDC_BUTTON_RIGHT)->m_hWnd )
             OnButtonRight();
         if ( pMsg->hwnd == GetDlgItem(IDC_BUTTON_UP)->m_hWnd )
             OnButtonUp();
         if ( pMsg->hwnd == GetDlgItem(IDC_BUTTON_DOWN)->m_hWnd )
             OnButtonDown();
     }
    
     return CDialog::PreTranslateMessage(pMsg);
 }

在CameraController程序中:

BOOL CCameraControllerDlg::PreTranslateMessage(MSG* pMsg)
{
    this->m_tt.RelayEvent(pMsg);

    if(this->m_bOpend) {                                                         //串口被打开后
        CWnd * pWnd = CWnd::FromHandle(pMsg->hwnd);        
        UINT msgId = pMsg->message;

        INT nId = 0;
        BYTE b[8];
        b[0] = 0;

        if(m

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现圆形上下圆盘可以通过自定义View来实现。 首先需要继承View,并且在onDraw()方法中圆盘和箭头,具体实现步骤如下: 1. 定义圆盘的半径和圆心坐标 ``` private float mRadius; // 圆盘半径 private float mCenterX; // 圆盘圆心X坐标 private float mCenterY; // 圆盘圆心Y坐标 ``` 2. 在onMeasure()方法中获取View的宽高,并且计算圆盘半径和圆心坐标 ``` @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); // 获取宽度 int height = MeasureSpec.getSize(heightMeasureSpec); // 获取高度 int size = Math.min(width, height); // 取宽高的最小值作为View的大小 mRadius = size / 2f; // 计算圆盘半径 mCenterX = width / 2f; // 计算圆盘圆心X坐标 mCenterY = height / 2f; // 计算圆盘圆心Y坐标 setMeasuredDimension(size, size); // 设置View的大小 } ``` 3. 在onDraw()方法中圆盘和箭头 ``` @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 圆盘 canvas.drawCircle(mCenterX, mCenterY, mRadius, mPaint); // 制箭头 canvas.drawLine(mCenterX, mCenterY - mRadius, mCenterX, mCenterY - mRadius / 2f, mPaint); // 上箭头 canvas.drawLine(mCenterX, mCenterY + mRadius, mCenterX, mCenterY + mRadius / 2f, mPaint); // 下箭头 canvas.drawLine(mCenterX - mRadius, mCenterY, mCenterX - mRadius / 2f, mCenterY, mPaint); // 箭头 canvas.drawLine(mCenterX + mRadius, mCenterY, mCenterX + mRadius / 2f, mCenterY, mPaint); // 箭头 } ``` 4. 在构造方法中初始化画笔 ``` public RoundButtonView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { mPaint = new Paint(); mPaint.setAntiAlias(true); // 抗锯齿 mPaint.setStyle(Paint.Style.STROKE); // 空心 mPaint.setStrokeWidth(5); // 线宽 mPaint.setColor(Color.BLACK); // 颜色 } ``` 最后,在布局文件中添加自定义View即可。 ``` <com.example.customview.RoundButtonView android:layout_width="match_parent" android:layout_height="match_parent"/> ``` 当然,这只是一个简单的实现,如果需要响应用户的手势操作,还需要写onTouchEvent()方法,并且处理用户手势的事件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值