duilib Ip控件
2015-06-25 00:00
561 查看
摘要: 自定义duilib Ip控件
直接上来贴码
头文件
源文件
直接上来贴码
头文件
#ifndef __UIIpAddress_H__ #define __UIIpAddress_H__ #pragma once namespace DuiLib { class CIpAddressUI : public CHorizontalLayoutUI { public: CIpAddressUI(); virtual void Init(); virtual void DoInit(); virtual void SetPos(RECT rc); virtual CDuiString GetText() const; virtual void DoEvent(TEventUI& event); virtual void SetText(LPCTSTR pstrText); protected: CEditUI *p; CEditUI *p2; CEditUI *p3; CEditUI *p4; }; } #endif // __UIEDIT_H__
源文件
#include "StdAfx.h" #include "..\stdafx.h" #include "UIIpAddress.h" #include <string> namespace DuiLib { CIpAddressUI::CIpAddressUI() { p=NULL; p2=NULL; p3=NULL; p4=NULL; } void CIpAddressUI::Init() { this->SetAttribute(_T("inset"),"1,1,1,1"); CHorizontalLayoutUI::Init(); //p- } void CIpAddressUI::DoInit() { CHorizontalLayoutUI::DoInit(); p=new CEditUI(); int width=this->GetWidth()/3-4; p->SetName("p"); p->SetAttribute("width","20"); p->SetAttribute("bkcolor","#00000000"); p->SetAttribute("texttype","integer");//扩展属性 见http://git.oschina.net/Qyerp/DuiLib p->SetAttribute("minvalue","0");//扩展属性 p->SetAttribute("maxvalue","255");//扩展属性 //p->SetPos(rcPos); this->Add(p); CLabelUI *dot1=new CLabelUI(); dot1->SetText("."); dot1->SetAttribute("padding","1,0,2,0"); dot1->SetAttribute("width","5"); this->Add(dot1); p2=new CEditUI(); p2->SetName("p2"); p2->SetAttribute("width","20"); p2->SetAttribute("bkcolor","#00000000"); p2->SetAttribute("texttype","integer"); p2->SetAttribute("minvalue","0"); p2->SetAttribute("maxvalue","255"); this->Add(p2); CLabelUI *dot2=new CLabelUI(); dot2->SetText("."); dot2->SetAttribute("padding","1,0,2,0"); dot2->SetAttribute("width","5"); this->Add(dot2); p3=new CEditUI(); p3->SetName("p3"); p3->SetAttribute("width","20"); p3->SetAttribute("bkcolor","#00000000"); p3->SetAttribute("texttype","integer"); p3->SetAttribute("minvalue","0"); p3->SetAttribute("maxvalue","255"); this->Add(p3); CLabelUI *dot3=new CLabelUI(); dot3->SetText("."); dot3->SetAttribute("padding","1,0,2,0"); dot3->SetAttribute("width","5"); this->Add(dot3); p4=new CEditUI(); p4->SetName("p4"); p4->SetAttribute("width","20"); p4->SetAttribute("bkcolor","#00000000"); p4->SetAttribute("texttype","integer"); p4->SetAttribute("minvalue","0"); p4->SetAttribute("maxvalue","255"); this->Add(p4); } void CIpAddressUI::SetPos(RECT rc) { CHorizontalLayoutUI::SetPos(rc); int width=this->GetWidth()/4-4; char abc[100]; _stprintf_s(abc,"%d",width); if(p!=NULL) { RECT rcCtrl = rc; rcCtrl.right=rcCtrl.left+width; p->SetPos(rcCtrl); rcCtrl.left=rcCtrl.right; rcCtrl.right=rcCtrl.left+width; p2->SetPos(rcCtrl); rcCtrl.left=rcCtrl.right; rcCtrl.right=rcCtrl.left+width; p3->SetPos(rcCtrl); rcCtrl.left=rcCtrl.right; rcCtrl.right=rcCtrl.left+width; p4->SetPos(rcCtrl); //p3->SetAttribute("width",abc); //p4->SetAttribute("width",abc);/**/ } } CDuiString CIpAddressUI::GetText() const { //m_sText=p->GetText()+_T(".")+p2->GetText()+p3->GetText()+p4->GetText(); return m_sText; } void CIpAddressUI::SetText(LPCTSTR pstrText) { CHorizontalLayoutUI::SetText(pstrText); CDuiString one=pstrText; int pot=one.Find("."); if(p!=NULL) p->SetText(one.Left(pot)); one=one.Right(one.GetLength()-pot-1); pot=one.Find("."); if(p2!=NULL) p2->SetText(one.Left(pot)); one=one.Right(one.GetLength()-pot-1); pot=one.Find("."); if(p3!=NULL) p3->SetText(one.Left(pot)); one=one.Right(one.GetLength()-pot-1); //pot=one.Find("."); if(p4!=NULL) p4->SetText(one); //one=one.Right(one.GetLength()-pot); } void CIpAddressUI::DoEvent(TEventUI& e) { //char *pppp=(char*)e.pSender->GetClass(); if(e.Type==UIEVENT__TEXTCHANGED) { if(_tcscmp(e.pSender->GetClass(),_T("EditUI"))==0) { CDuiString one=p->GetText(); CDuiString two=p2->GetText(); CDuiString three=p3->GetText(); CDuiString f=p4->GetText(); CDuiString dot=_T("."); CDuiString fff=one+dot+two+dot+three+dot+f; m_sText=fff.GetData(); } } if(e.Type==UIEVENT_KEYDOWN) { if((e.wParam==VK_TAB||e.wParam==VK_RIGHT)) { if(_tcscmp(e.pSender->GetName(),_T("p"))==0) { p2->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p2"))==0) { p3->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p3"))==0) { p4->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p4"))==0) { p->SetFocus(); } } if(e.wParam==VK_LEFT ) { if(_tcscmp(e.pSender->GetName(),_T("p"))==0) { p4->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p2"))==0) { p->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p3"))==0) { p2->SetFocus(); } if(_tcscmp(e.pSender->GetName(),_T("p4"))==0) { p3->SetFocus(); } } } } }
相关文章推荐
- duilib bkimage 属性
- 用Duilib界面库开发的一个日历控件
- duilib 开源界面库
- DUILIB多级菜单例子
- DuiLib中CTileLayoutUI的一个bug
- Duilib 快捷键实现
- Duilib 下关于Gif的使用
- Duilib 改造之路 <1> 扩展标签
- Duilib 改造之路 <2> 渲染效果 1 不打马赛克的世界
- Duilib学习笔记《01》— duilib整体框架认识
- Duilib技巧:背景图片平铺
- 用duilib制作仿QQ2013动态背景登录器
- 仿酷狗音乐播放器开发日志二十——换肤功能背景图片控件的制作(附源码)
- 【1】使用DuiLib准备
- 深入浅出CChart 每日一课——快乐高四第三课 巨人的垫脚石,DirectUI之DuiLib篇
- 视频播放器进度条的制作
- 第一个duilib程序–HelloWorld
- CIPAddressCtrl控件之IP地址与CString的互相转化
- Duilib 事件类型定义
- MFC的IP控件的使用,获取本地IP显示到控件