duilib实现计时器小工具
初学者练手的项目,仅供参考,源码已经全部贴出,如需完整工程请与作者联系;
转载请保留出处,谢谢。
效果图一:计时器界面
效果图二:倒计时界面
以下是 wnd_timer.h \ wnd_timer.cpp \ xml
1 //计时器窗口类 2 class wnd_timer : public WindowImplBase 3 { 4 public: 5 //构造函数 6 wnd_timer(void); 7 //析构函数 8 virtual ~wnd_timer(void); 9 10 virtual void OnFinalMessage(HWND); 11 virtual CDuiString GetSkinFile(); 12 virtual CDuiString GetSkinFolder(); 13 virtual LPCTSTR GetWindowClassName(void) const; 14 virtual void Notify(TNotifyUI &msg); 15 virtual void InitWindow(); 16 DUI_DECLARE_MESSAGE_MAP() 17 virtual void OnClick(TNotifyUI& msg); 18 virtual LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 19 LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 20 21 virtual LPCTSTR GetResourceID() const; 22 virtual int GetResourceType() const; 23 24 private: 25 26 //根据数值动态设置对应的数值的图片背景 27 void Set_Control_Bkimage(CControlUI* objectUI,const int value); 28 29 //设置计时器小时显示 30 //参数itype: 0:代表十位 1:代表个位 31 //参数value:目标值 32 void Set_Timer_Hour_Value(const int itype,const int value); 33 //设置计时器分钟显示 34 //参数itype: 0:代表十位 1:代表个位 35 //参数value:目标值 36 void Set_Timer_Min_Value(const int itype, const int value); 37 //设置计时器秒钟显示 38 //参数itype: 0:代表十位 1:代表个位 39 //参数value:目标值 40 void Set_Timer_Sec_Value(const int itype, const int value); 41 42 //设置倒计时器分钟显示 43 //参数itype: 0:代表十位 1:代表个位 44 //参数value:目标值 45 void Set_CountDown_Min_Value(const int itype, const int value); 46 47 //设置倒计时器秒钟显示 48 //参数itype: 0:代表十位 1:代表个位 49 //参数value:目标值 50 void Set_CountDown_Sec_Value(const int itype, const int value); 51 52 //微调增加倒计时分钟数 53 void Up_CountDown_Min_Value(const int itype); 54 //微调增加倒计时t秒钟数 55 void Up_CountDown_Sec_Value(const int itype); 56 57 //微调减少倒计时分钟数 58 void Down_CountDown_Min_Value(const int itype); 59 //微调减少倒计时秒钟数 60 void Down_CountDown_Sec_Value(const int itype); 61 62 //微调增加计时器秒数 63 void Up_Timer_Sec_Value(const int itype); 64 //微调增加计时器分钟数 65 void Up_Timer_Min_Value(const int itype); 66 //微调增加计时器小时数 67 void Up_Timer_Hour_Value(const int itype); 68 69 //计时器开启后的状态控制 70 void Set_Mode_Enable(const int status); 71 72 //重置 73 void Reset(); 74 //开始 75 void Start(); 76 //暂停 77 void Pause(); 78 //继续 79 void Resume(); 80 private: 81 //UI根节点 82 CVerticalLayoutUI* rootmain; 83 //帮助按钮 84 CButtonUI* btn_help; 85 //简洁显示按钮 86 CButtonUI* btn_concise; 87 //关闭按钮 88 CButtonUI* btn_close; 89 90 //单选按钮 计时器 91 COptionUI* opt_timer; 92 //单选按钮 倒计时器 93 COptionUI* opt_countdown; 94 95 //计时器显示 小时十位数字控件 96 CLabelUI* lbl_timer_hour_0; 97 //计时器显示 小时个位数字控件 98 CLabelUI* lbl_timer_hour_1; 99 100 //计时器显示 分钟十位数字控件 101 CLabelUI* lbl_timer_min_0; 102 //计时器显示 分钟个位数字控件 103 CLabelUI* lbl_timer_min_1; 104 105 //计时器显示 秒钟十位数字控件 106 CLabelUI* lbl_timer_sec_0; 107 //计时器显示 秒钟个位数字控件 108 CLabelUI* lbl_timer_sec_1; 109 110 //倒计时30秒按钮 111 CButtonUI* btn_30_sec; 112 //倒计时1分钟按钮 113 CButtonUI* btn_1_min; 114 //倒计时5分钟按钮 115 CButtonUI* btn_5_min; 116 117 //倒计时增加 分钟十位增加 118 CButtonUI* btn_up_min_0; 119 //倒计时增加 分钟个位增加 120 CButtonUI* btn_up_min_1; 121 122 //倒计时增加 秒钟十位增加 123 CButtonUI* btn_up_sec_0; 124 //倒计时增加 秒钟个位增加 125 CButtonUI* btn_up_sec_1; 126 127 //倒计时显示 分钟十位数字控件 128 CLabelUI* lbl_countdown_min_0; 129 //倒计时显示 分钟个位数字控件 130 CLabelUI* lbl_countdown_min_1; 131 132 //倒计时显示 秒钟十位数字控件 133 CLabelUI* lbl_countdown_sec_0; 134 //倒计时显示 秒钟个位数字控件 135 CLabelUI* lbl_countdown_sec_1; 136 137 //倒计时减 分钟十位减少 138 CButtonUI* btn_down_min_0; 139 //倒计时减 分钟个位减少 140 CButtonUI* btn_down_min_1; 141 142 //倒计时减 秒钟十位减少 143 CButtonUI* btn_down_sec_0; 144 //倒计时减 秒钟个位减少 145 CButtonUI* btn_down_sec_1; 146 147 //重置按钮 148 CButtonUI* btn_reset; 149 //开始按钮 150 CButtonUI* btn_start; 151 //暂停按钮 152 CButtonUI* btn_pause; 153 //继续按钮 154 CButtonUI* btn_resume; 155 //倒计时里面 分钟和秒钟中间的":"文本标签控件 156 CLabelUI* lbl_point; 157 158 //倒计时快捷按钮区域 159 CVerticalLayoutUI* layout_quick; 160 161 //占位控件 用于控制内容居中 162 CControlUI* control_1; 163 CControlUI* control_2; 164 };
1 #include "wnd_timer.h" 2 3 namespace wnd_timer 4 { 5 DUI_BEGIN_MESSAGE_MAP(wnd_timer, WindowImplBase) 6 DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK, OnClick) 7 DUI_END_MESSAGE_MAP() 8 9 wnd_timer::wnd_timer() 10 { 11 12 } 13 14 wnd_timer::~wnd_timer() 15 { 16 17 } 18 19 void wnd_timer::OnFinalMessage(HWND hwnd) 20 { 21 __super::OnFinalMessage(hwnd); 22 delete this; 23 exit(EXIT_SUCCESS); 24 } 25 26 CDuiString wnd_timer::GetSkinFile() 27 { 28 return TEXT("wnd_timer.xml"); 29 } 30 31 CDuiString wnd_timer::GetSkinFolder() 32 { 33 return TEXT(""); 34 } 35 36 LPCTSTR wnd_timer::GetWindowClassName(void) const 37 { 38 return _T("wnd_timer"); 39 } 40 41 void wnd_timer::Notify(TNotifyUI &msg) 42 { 43 return WindowImplBase::Notify(msg); 44 } 45 46 void wnd_timer::InitWindow() 47 { 48 //设置软件ICO 49 SetIcon(IDI_SMALL); 50 51 // Make topmost 52 ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 53 54 SetWindowLong(m_hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);//隐藏任务拦按钮 55 56 57 rootmain= static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("rootmain"))); 58 btn_help = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_help"))); 59 btn_concise= static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_concise"))); 60 btn_close= static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_close"))); 61 62 opt_timer = static_cast<COptionUI*>(m_pm.FindControl(_T("opt_timer"))); 63 opt_countdown= static_cast<COptionUI*>(m_pm.FindControl(_T("opt_countdown"))); 64 65 lbl_timer_hour_0 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_hour_0"))); 66 lbl_timer_hour_1 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_hour_1"))); 67 68 lbl_timer_min_0 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_min_0"))); 69 lbl_timer_min_1 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_min_1"))); 70 71 lbl_timer_sec_0 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_sec_0"))); 72 lbl_timer_sec_1 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_timer_sec_1"))); 73 74 btn_30_sec = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_30_sec"))); 75 btn_1_min = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_1_min"))); 76 btn_5_min = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_5_min"))); 77 78 btn_up_min_0 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_up_min_0"))); 79 btn_up_min_1 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_up_min_1"))); 80 81 btn_up_sec_0 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_up_sec_0"))); 82 btn_up_sec_1 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_up_sec_1"))); 83 84 lbl_countdown_min_0 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_countdown_min_0"))); 85 lbl_countdown_min_1 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_countdown_min_1"))); 86 87 lbl_countdown_sec_0 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_countdown_sec_0"))); 88 lbl_countdown_sec_1 = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_countdown_sec_1"))); 89 90 btn_down_min_0 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_down_min_0"))); 91 btn_down_min_1 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_down_min_1"))); 92 93 btn_down_sec_0 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_down_sec_0"))); 94 btn_down_sec_1 = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_down_sec_1"))); 95 96 btn_reset = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_reset"))); 97 btn_start = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_start"))); 98 btn_pause = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_pause"))); 99 btn_resume = static_cast<CButtonUI*>(m_pm.FindControl(_T("btn_resume"))); 100 101 lbl_point = static_cast<CLabelUI*>(m_pm.FindControl(_T("lbl_point"))); 102 layout_quick= static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("layout_quick"))); 103 104 control_1= static_cast<CControlUI*>(m_pm.FindControl(_T("control_1"))); 105 control_2= static_cast<CControlUI*>(m_pm.FindControl(_T("control_2"))); 106 } 107 108 void wnd_timer::OnClick(TNotifyUI& msg) 109 { 110 if (msg.pSender == btn_close) 111 { 112 SendMessage(WM_SYSCOMMAND, SC_CLOSE, 0); 113 } 114 else if (msg.pSender == btn_reset) 115 { 116 Reset(); 117 } 118 else if (msg.pSender == btn_start) 119 { 120 Start(); 121 } 122 else if (msg.pSender == btn_pause) 123 { 124 Pause(); 125 } 126 else if (msg.pSender == btn_resume) 127 { 128 Resume(); 129 } 130 else if (msg.pSender == btn_up_min_0) 131 { 132 Up_CountDown_Min_Value(0); 133 } 134 else if (msg.pSender == btn_up_min_1) 135 { 136 Up_CountDown_Min_Value(1); 137 } 138 else if (msg.pSender == btn_up_sec_0) 139 { 140 Up_CountDown_Sec_Value(0); 141 } 142 else if (msg.pSender == btn_up_sec_1) 143 { 144 Up_CountDown_Sec_Value(1); 145 } 146 else if (msg.pSender == btn_down_min_0) 147 { 148 Down_CountDown_Min_Value(0); 149 } 150 else if (msg.pSender == btn_down_min_1) 151 { 152 Down_CountDown_Min_Value(1); 153 } 154 else if (msg.pSender == btn_down_sec_0) 155 { 156 Down_CountDown_Sec_Value(0); 157 } 158 else if (msg.pSender == btn_down_sec_1) 159 { 160 Down_CountDown_Sec_Value(1); 161 } 162 else if (msg.pSender == btn_30_sec) 163 { 164 Reset(); 165 Set_CountDown_Sec_Value(0, 3); 166 } 167 else if (msg.pSender == btn_1_min) 168 { 169 Reset(); 170 Set_CountDown_Min_Value(1, 1); 171 } 172 else if (msg.pSender == btn_5_min) 173 { 174 Reset(); 175 Set_CountDown_Min_Value(1, 5); 176 } 177 } 178 179 LRESULT wnd_timer::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 180 { 181 if (wParam == SC_CLOSE) 182 { 183 this->Close(); 184 bHandled = TRUE; 185 return 0; 186 } 187 LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam); 188 return lRes; 189 } 190 191 LRESULT wnd_timer::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 192 { 193 // 关闭窗口,退出程序 194 if (uMsg == WM_DESTROY) 195 { 196 this->Close(); 197 bHandled = TRUE; 198 return 0; 199 } 200 if (uMsg == WM_TIMER) 201 { 202 if (wParam == 121526) 203 { 204 //计时器 205 if (opt_timer->IsSelected()) 206 { 207 Up_Timer_Sec_Value(1); 208 } 209 //倒计时 210 else 211 { 212 if (lbl_countdown_min_0->GetTag() == 0 && lbl_countdown_min_1->GetTag() == 0 && lbl_countdown_sec_0->GetTag() == 0 && lbl_countdown_sec_1->GetTag() == 0) 213 { 214 Reset(); 215 } 216 else 217 { 218 Down_CountDown_Sec_Value(1); 219 } 220 } 221 } 222 } 223 bHandled = FALSE; 224 return 0; 225 } 226 227 LPCTSTR wnd_timer::GetResourceID() const 228 { 229 return MAKEINTRESOURCE(IDR_ZIPRES1); 230 } 231 232 int wnd_timer::GetResourceType() const 233 { 234 return UILIB_ZIPRESOURCE; 235 } 236 237 //根据数值动态设置对应的数值的图片背景 238 void wnd_timer::Set_Control_Bkimage(CControlUI* objectUI, const int value) 239 { 240 objectUI->SetTag(value); 241 switch (value) 242 { 243 case 0: 244 objectUI->SetAttribute(_T("bkimage"),_T("LED\\0.png")); 245 break; 246 case 1: 247 objectUI->SetAttribute(_T("bkimage"), _T("LED\\1.png")); 248 break; 249 case 2: 250 objectUI->SetAttribute(_T("bkimage"), _T("LED\\2.png")); 251 break; 252 case 3: 253 objectUI->SetAttribute(_T("bkimage"), _T("LED\\3.png")); 254 break; 255 case 4: 256 objectUI->SetAttribute(_T("bkimage"), _T("LED\\4.png")); 257 break; 258 case 5: 259 objectUI->SetAttribute(_T("bkimage"), _T("LED\\5.png")); 260 break; 261 case 6: 262 objectUI->SetAttribute(_T("bkimage"), _T("LED\\6.png")); 263 break; 264 case 7: 265 objectUI->SetAttribute(_T("bkimage"), _T("LED\\7.png")); 266 break; 267 case 8: 268 objectUI->SetAttribute(_T("bkimage"), _T("LED\\8.png")); 269 break; 270 case 9: 271 objectUI->SetAttribute(_T("bkimage"), _T("LED\\9.png")); 272 break; 273 default: 274 objectUI->SetAttribute(_T("bkimage"), _T("LED\\0.png")); 275 break; 276 } 277 } 278 279 //设置计时器小时显示 280 //参数itype: 0:代表十位 1:代表个位 281 //参数value:目标值 282 void wnd_timer::Set_Timer_Hour_Value(const int itype, const int value) 283 { 284 if (itype == 0) 285 { 286 if (value > 5) 287 { 288 Set_Control_Bkimage(lbl_timer_hour_0, 0); 289 } 290 else 291 { 292 Set_Control_Bkimage(lbl_timer_hour_0, value); 293 } 294 } 295 else 296 { 297 Set_Control_Bkimage(lbl_timer_hour_1, value); 298 } 299 } 300 301 //设置计时器分钟显示 302 //参数itype: 0:代表十位 1:代表个位 303 //参数value:目标值 304 void wnd_timer::Set_Timer_Min_Value(const int itype, const int value) 305 { 306 if (itype == 0) 307 { 308 if (value > 5) 309 { 310 Set_Control_Bkimage(lbl_timer_min_0, 0); 311 } 312 else 313 { 314 Set_Control_Bkimage(lbl_timer_min_0, value); 315 } 316 } 317 else 318 { 319 Set_Control_Bkimage(lbl_timer_min_1, value); 320 } 321 } 322 323 //设置计时器秒钟显示 324 //参数itype: 0:代表十位 1:代表个位 325 //参数value:目标值 326 void wnd_timer::Set_Timer_Sec_Value(const int itype, const int value) 327 { 328 if (itype == 0) 329 { 330 if (value > 5) 331 { 332 Set_Control_Bkimage(lbl_timer_sec_0, 0); 333 } 334 else 335 { 336 Set_Control_Bkimage(lbl_timer_sec_0, value); 337 } 338 } 339 else 340 { 341 Set_Control_Bkimage(lbl_timer_sec_1, value); 342 } 343 } 344 345 //设置倒计时器分钟显示 346 //参数itype: 0:代表十位 1:代表个位 347 //参数value:目标值 348 void wnd_timer::Set_CountDown_Min_Value(const int itype, const int value) 349 { 350 if (itype == 0) 351 { 352 if (value > 5) 353 { 354 Set_Control_Bkimage(lbl_countdown_min_0, 0); 355 } 356 else 357 { 358 Set_Control_Bkimage(lbl_countdown_min_0, value); 359 } 360 361 } 362 else 363 { 364 Set_Control_Bkimage(lbl_countdown_min_1, value); 365 } 366 } 367 368 //设置倒计时器秒钟显示 369 //参数itype: 0:代表十位 1:代表个位 370 //参数value:目标值 371 void wnd_timer::Set_CountDown_Sec_Value(const int itype, const int value) 372 { 373 if (itype == 0) 374 { 375 if (value > 5) 376 { 377 Set_Control_Bkimage(lbl_countdown_sec_0, 0); 378 } 379 else 380 { 381 Set_Control_Bkimage(lbl_countdown_sec_0, value); 382 } 383 384 } 385 else 386 { 387 Set_Control_Bkimage(lbl_countdown_sec_1, value); 388 } 389 } 390 391 //微调增加计时器秒数 392 void wnd_timer::Up_Timer_Sec_Value(const int itype) 393 { 394 if (itype == 0) 395 { 396 int value = lbl_timer_sec_0->GetTag(); 397 value += 1; 398 if (value > 5) 399 { 400 Up_Timer_Min_Value(1); 401 value = 0; 402 } 403 Set_Control_Bkimage(lbl_timer_sec_0, value); 404 } 405 else 406 { 407 int value = lbl_timer_sec_1->GetTag(); 408 value += 1; 409 if (value > 9) 410 { 411 Up_Timer_Sec_Value(0); 412 value = 0; 413 } 414 Set_Control_Bkimage(lbl_timer_sec_1, value); 415 } 416 } 417 418 //微调增加计时器分钟数 419 void wnd_timer::Up_Timer_Min_Value(const int itype) 420 { 421 if (itype == 0) 422 { 423 int value = lbl_timer_min_0->GetTag(); 424 value += 1; 425 if (value > 5) 426 { 427 Up_Timer_Hour_Value(1); 428 value = 0; 429 } 430 Set_Control_Bkimage(lbl_timer_min_0, value); 431 } 432 else 433 { 434 int value = lbl_timer_min_1->GetTag(); 435 value += 1; 436 if (value > 9) 437 { 438 Up_Timer_Min_Value(0); 439 value = 0; 440 } 441 Set_Control_Bkimage(lbl_timer_min_1, value); 442 } 443 } 444 //微调增加计时器小时数 445 void wnd_timer::Up_Timer_Hour_Value(const int itype) 446 { 447 if (itype == 0) 448 { 449 int value = lbl_timer_hour_0->GetTag(); 450 value += 1; 451 if (value > 9) 452 { 453 value = 0; 454 } 455 Set_Control_Bkimage(lbl_timer_hour_0, value); 456 } 457 else 458 { 459 int value = lbl_timer_hour_1->GetTag(); 460 value += 1; 461 if (value > 9) 462 { 463 Up_Timer_Hour_Value(0); 464 value = 0; 465 } 466 Set_Control_Bkimage(lbl_timer_hour_1, value); 467 } 468 } 469 470 //微调增加倒计时分钟数 471 void wnd_timer::Up_CountDown_Min_Value(const int itype) 472 { 473 if (itype == 0) 474 { 475 int value=lbl_countdown_min_0->GetTag(); 476 value += 1; 477 if (value > 5) 478 { 479 value = 0; 480 } 481 Set_Control_Bkimage(lbl_countdown_min_0, value); 482 } 483 else 484 { 485 int value = lbl_countdown_min_1->GetTag(); 486 value += 1; 487 if (value > 9) 488 { 489 value = 0; 490 } 491 Set_Control_Bkimage(lbl_countdown_min_1, value); 492 } 493 } 494 495 //微调增加倒计时t秒钟数 496 void wnd_timer::Up_CountDown_Sec_Value(const int itype) 497 { 498 if (itype == 0) 499 { 500 int value = lbl_countdown_sec_0->GetTag(); 501 value += 1; 502 if (value > 5) 503 { 504 value = 0; 505 } 506 Set_Control_Bkimage(lbl_countdown_sec_0, value); 507 } 508 else 509 { 510 int value = lbl_countdown_sec_1->GetTag(); 511 value += 1; 512 if (value > 9) 513 { 514 value = 0; 515 } 516 Set_Control_Bkimage(lbl_countdown_sec_1, value); 517 } 518 } 519 520 //微调减少倒计时分钟数 521 void wnd_timer::Down_CountDown_Min_Value(const int itype) 522 { 523 if (itype == 0) 524 { 525 int value = lbl_countdown_min_0->GetTag(); 526 value -= 1; 527 if (value < 0) 528 { 529 value = 5; 530 } 531 Set_Control_Bkimage(lbl_countdown_min_0, value); 532 } 533 else 534 { 535 int value = lbl_countdown_min_1->GetTag(); 536 value -= 1; 537 if (value < 0) 538 { 539 Down_CountDown_Min_Value(0); 540 value = 9; 541 } 542 Set_Control_Bkimage(lbl_countdown_min_1, value); 543 } 544 } 545 546 //微调减少倒计时秒钟数 547 void wnd_timer::Down_CountDown_Sec_Value(const int itype) 548 { 549 if (itype == 0) 550 { 551 int value = lbl_countdown_sec_0->GetTag(); 552 value -= 1; 553 if (value < 0) 554 { 555 Down_CountDown_Min_Value(1); 556 value = 5; 557 } 558 Set_Control_Bkimage(lbl_countdown_sec_0, value); 559 } 560 else 561 { 562 int value = lbl_countdown_sec_1->GetTag(); 563 value -= 1; 564 if (value < 0) 565 { 566 Down_CountDown_Sec_Value(0); 567 value = 9; 568 } 569 Set_Control_Bkimage(lbl_countdown_sec_1, value); 570 } 571 } 572 573 //重置 574 void wnd_timer::Reset() 575 { 576 //停止计时器 577 KillTimer(m_hWnd, 121526); 578 579 Set_Control_Bkimage(lbl_timer_hour_0, 0); 580 Set_Control_Bkimage(lbl_timer_hour_1, 0); 581 582 Set_Control_Bkimage(lbl_timer_min_0, 0); 583 Set_Control_Bkimage(lbl_timer_min_1, 0); 584 585 Set_Control_Bkimage(lbl_timer_sec_0, 0); 586 Set_Control_Bkimage(lbl_timer_sec_1, 0); 587 588 Set_Control_Bkimage(lbl_countdown_min_0, 0); 589 Set_Control_Bkimage(lbl_countdown_min_1, 0); 590 591 Set_Control_Bkimage(lbl_countdown_sec_0, 0); 592 Set_Control_Bkimage(lbl_countdown_sec_1, 0); 593 594 Set_Mode_Enable(1); 595 } 596 597 //计时器开启后的状态控制 598 void wnd_timer::Set_Mode_Enable(const int status) 599 { 600 //计时器 601 if (opt_timer->IsSelected()) 602 { 603 //禁用 604 if (status == 0) 605 { 606 opt_countdown->SetEnabled(false); 607 opt_countdown->SetMouseEnabled(false); 608 btn_start->SetVisible(false); 609 btn_pause->SetVisible(true); 610 btn_resume->SetVisible(false); 611 } 612 //启用 613 else 614 { 615 opt_countdown->SetEnabled(true); 616 opt_countdown->SetMouseEnabled(true); 617 btn_start->SetVisible(true); 618 btn_pause->SetVisible(false); 619 btn_resume->SetVisible(false); 620 } 621 } 622 //倒计时器 623 else 624 { 625 //禁用 626 if (status == 0) 627 { 628 opt_timer->SetEnabled(false); 629 opt_timer->SetMouseEnabled(false); 630 btn_start->SetVisible(false); 631 btn_pause->SetVisible(true); 632 btn_resume->SetVisible(false); 633 634 btn_down_min_0->SetEnabled(false); 635 btn_down_min_0->SetMouseEnabled(false); 636 btn_down_min_1->SetEnabled(false); 637 btn_down_min_1->SetMouseEnabled(false); 638 639 btn_down_sec_0->SetEnabled(false); 640 btn_down_sec_0->SetMouseEnabled(false); 641 btn_down_sec_1->SetEnabled(false); 642 btn_down_sec_1->SetMouseEnabled(false); 643 644 btn_up_min_0->SetEnabled(false); 645 btn_up_min_0->SetMouseEnabled(false); 646 btn_up_min_1->SetEnabled(false); 647 btn_up_min_1->SetMouseEnabled(false); 648 649 btn_up_sec_0->SetEnabled(false); 650 btn_up_sec_0->SetMouseEnabled(false); 651 btn_up_sec_1->SetEnabled(false); 652 btn_up_sec_1->SetMouseEnabled(false); 653 654 btn_30_sec->SetEnabled(false); 655 btn_30_sec->SetMouseEnabled(false); 656 btn_1_min->SetEnabled(false); 657 btn_1_min->SetMouseEnabled(false); 658 btn_5_min->SetEnabled(false); 659 btn_5_min->SetMouseEnabled(false); 660 661 layout_quick->SetVisible(false); 662 control_1->SetVisible(true); 663 control_2->SetVisible(true); 664 } 665 //启用 666 else 667 { 668 opt_timer->SetEnabled(true); 669 opt_timer->SetMouseEnabled(true); 670 btn_start->SetVisible(true); 671 btn_pause->SetVisible(false); 672 btn_resume->SetVisible(false); 673 674 btn_down_min_0->SetEnabled(true); 675 btn_down_min_0->SetMouseEnabled(true); 676 btn_down_min_1->SetEnabled(true); 677 btn_down_min_1->SetMouseEnabled(true); 678 679 btn_down_sec_0->SetEnabled(true); 680 btn_down_sec_0->SetMouseEnabled(true); 681 btn_down_sec_1->SetEnabled(true); 682 btn_down_sec_1->SetMouseEnabled(true); 683 684 btn_up_min_0->SetEnabled(true); 685 btn_up_min_0->SetMouseEnabled(true); 686 btn_up_min_1->SetEnabled(true); 687 btn_up_min_1->SetMouseEnabled(true); 688 689 btn_up_sec_0->SetEnabled(true); 690 btn_up_sec_0->SetMouseEnabled(true); 691 btn_up_sec_1->SetEnabled(true); 692 btn_up_sec_1->SetMouseEnabled(true); 693 694 btn_30_sec->SetEnabled(true); 695 btn_30_sec->SetMouseEnabled(true); 696 btn_1_min->SetEnabled(true); 697 btn_1_min->SetMouseEnabled(true); 698 btn_5_min->SetEnabled(true); 699 btn_5_min->SetMouseEnabled(true); 700 701 layout_quick->SetVisible(true); 702 control_1->SetVisible(false); 703 control_2->SetVisible(false); 704 } 705 } 706 } 707 708 //开始 709 void wnd_timer::Start() 710 { 711 Set_Mode_Enable(0); 712 SetTimer(m_hWnd, 121526, 1000,NULL); 713 btn_start->SetVisible(false); 714 btn_pause->SetVisible(true); 715 btn_resume->SetVisible(false); 716 } 717 718 //暂停 719 void wnd_timer::Pause() 720 { 721 Set_Mode_Enable(0); 722 btn_start->SetVisible(false); 723 btn_pause->SetVisible(false); 724 btn_resume->SetVisible(true); 725 //停止计时器 726 KillTimer(m_hWnd, 121526); 727 728 } 729 730 //继续 731 void wnd_timer::Resume() 732 { 733 Set_Mode_Enable(0); 734 btn_start->SetVisible(false); 735 btn_pause->SetVisible(true); 736 btn_resume->SetVisible(false); 737 SetTimer(m_hWnd, 121526, 1000, NULL); 738 739 } 740 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <Window size="414,240" caption="0,0,0,240" showshadow="true" shadowsize="8" shadowdarkness="60" shadowsharpness="8" shadowposition="0,2" shadowcolor="0x000000"> 3 <Font id = "0" name="微软雅黑" size="14" bold="false" italic="false" shared="true"/> 4 <Font id = "1" name="微软雅黑" size="12" bold="false" italic="false" shared="true"/> 5 <Font id = "2" name="微软雅黑" size="16" bold="false" italic="false" shared="true"/> 6 <Font id = "3" name="微软雅黑" size="18" bold="false" italic="false" shared="true"/> 7 <Font id = "4" name="微软雅黑" size="25" bold="false" italic="false" shared="true"/> 8 <Font id = "5" name="微软雅黑" size="16" bold="true" italic="false" shared="true"/> 9 <Font id = "6" name="微软雅黑" size="18" bold="true" italic="false" shared="true"/> 10 <Font id = "7" name="微软雅黑" size="20" bold="false" italic="false" shared="true"/> 11 <Font id = "24" name="微软雅黑" size="24" bold="false" italic="false" shared="true"/> 12 <Font id = "10" name="微软雅黑" size="10" bold="false" italic="false" shared="true"/> 13 <Font id = "12" name="微软雅黑" size="12" bold="false" italic="false" shared="true"/> 14 <Font id = "18" name="微软雅黑" size="18" bold="true" italic="false" shared="true"/> 15 <Font id = "14" name="微软雅黑" size="14" bold="true" italic="false" shared="true"/> 16 <Font id = "16" name="微软雅黑" size="16" bold="true" italic="false" shared="true"/> 17 <Font id = "60" name="微软雅黑" size="60" bold="true" italic="false" shared="true"/> 18 19 <VerticalLayout name="rootmain" bkcolor="0xFF2D2D30"> 20 <!--标题栏--> 21 <HorizontalLayout height="40"> 22 23 <!--标题--> 24 <Label name="lbl_title" text="计时器v1.0" autocalcwidth="true" font="1" textcolor="0xFF818181" padding="10,0,5,0"/> 25 26 <!--占位--> 27 <Control/> 28 29 <!--帮助按钮--> 30 <Button name="btn_help" visible="false" autocalcwidth="true" text="帮助" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="10,0,10,0" padding="5,0,5,0"/> 31 32 <!--简洁显示按钮--> 33 <Button name="btn_concise" visible="false" autocalcwidth="true" text="简洁显示" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="10,0,10,0" padding="5,0,5,0"/> 34 35 <!--关闭按钮--> 36 <Button name="btn_close" autocalcwidth="true" text="关闭" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="10,0,10,0" padding="5,0,0,0" /> 37 </HorizontalLayout> 38 39 <!--Body 区--> 40 <VerticalLayout bkcolor="0xFF1E1E1E"> 41 42 <!--导航标签--> 43 <HorizontalLayout height="40"> 44 <!--占位--> 45 <Control/> 46 47 <!--计时器导航标签单选按钮--> 48 <Option name="opt_timer" group="timer_type" selected="true" bindtablayoutname="tab_host" bindtabindex="0" autocalcwidth="true" text="计时器" font="0" selectedtextcolor="0xFFFFFFFF" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 49 50 <!--倒计时导航标签单选按钮--> 51 <Option name="opt_countdown" group="timer_type" selected="false" bindtablayoutname="tab_host" bindtabindex="1" autocalcwidth="true" text="倒计时" font="0" selectedtextcolor="0xFFFFFFFF" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 52 53 <!--占位--> 54 <Control/> 55 56 </HorizontalLayout> 57 58 <!--计时器与倒计时器的Tab容器--> 59 <AnimationTabLayout name="tab_host"> 60 <!--计时器区域--> 61 <HorizontalLayout> 62 63 <!--占位--> 64 <Control/> 65 66 <Label name="lbl_timer_hour_0" bkimage="LED\0.png" width="64" height="64" padding="0,20,0,36"/> 67 <Label name="lbl_timer_hour_1" bkimage="LED\0.png" width="64" height="64" padding="-20,20,0,36"/> 68 69 <Label text=":" font="60" textcolor="0xFFFFFFFF" autocalcwidth="true" height="64" padding="-20,15,0,28"/> 70 71 <Label name="lbl_timer_min_0" bkimage="LED\0.png" width="64" height="64" padding="-20,20,0,36"/> 72 <Label name="lbl_timer_min_1" bkimage="LED\0.png" width="64" height="64" padding="-20,20,0,36"/> 73 74 <Label text=":" font="60" textcolor="0xFFFFFFFF" autocalcwidth="true" height="64" padding="-20,15,0,28"/> 75 76 <Label name="lbl_timer_sec_0" bkimage="LED\0.png" width="64" height="64" padding="-20,20,0,36"/> 77 <Label name="lbl_timer_sec_1" bkimage="LED\0.png" width="64" height="64" padding="-20,20,0,36"/> 78 79 <!--占位--> 80 <Control/> 81 82 </HorizontalLayout> 83 84 <!--倒计时区域--> 85 <HorizontalLayout> 86 87 <!--快捷设置按钮区域--> 88 <VerticalLayout name="layout_quick" width="90"> 89 <!--30秒按钮--> 90 <Button name="btn_30_sec" text="30秒" height="40" font="1" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 91 <!--1分钟按钮--> 92 <Button name="btn_1_min" text="1分钟" height="40" font="1" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 93 <!--5分钟按钮--> 94 <Button name="btn_5_min" text="5分钟" height="40" font="1" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 95 </VerticalLayout> 96 97 <!--占位--> 98 <Control name="control_1" width="45" visible="false"/> 99 100 <VerticalLayout> 101 <!--微调 增 区域--> 102 <HorizontalLayout height="25"> 103 <!--增 分钟十位按钮--> 104 <Button name="btn_up_min_0" text="+" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 105 <!--增 分钟个位按钮--> 106 <Button name="btn_up_min_1" text="+" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 107 108 <!--占位--> 109 <Label text=":" font="60" textcolor="0xFF1E1E1E" autocalcwidth="true" height="64"/> 110 111 <!--增 秒钟十位按钮--> 112 <Button name="btn_up_sec_0" text="+" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41"/> 113 <!--增 秒钟个位按钮--> 114 <Button name="btn_up_sec_1" text="+" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41"/> 115 </HorizontalLayout> 116 117 <!--倒计时显示 区域--> 118 <HorizontalLayout> 119 120 <Label name="lbl_countdown_min_0" bkimage="LED\0.png" width="64" height="64"/> 121 <Label name="lbl_countdown_min_1" bkimage="LED\0.png" width="64" height="64"/> 122 123 <Label name="lbl_point" tag="0" text=":" font="60" textcolor="0xFFFFFFFF" autocalcwidth="true" height="64" padding="0,-5,0,0"/> 124 125 <Label name="lbl_countdown_sec_0" bkimage="LED\0.png" width="64" height="64"/> 126 <Label name="lbl_countdown_sec_1" bkimage="LED\0.png" width="64" height="64"/> 127 128 </HorizontalLayout> 129 130 <!--微调 减 区域--> 131 <HorizontalLayout height="25"> 132 <!--减 分钟十位按钮--> 133 <Button name="btn_down_min_0" text="-" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 134 <!--减 分钟个位按钮--> 135 <Button name="btn_down_min_1" text="-" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0"/> 136 137 <!--占位--> 138 <Label text=":" font="60" textcolor="0xFF1E1E1E" autocalcwidth="true" height="64"/> 139 140 <!--减 秒钟十位按钮--> 141 <Button name="btn_down_sec_0" text="-" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41"/> 142 <!--减 秒钟个位按钮--> 143 <Button name="btn_down_sec_1" text="-" font="1" width="64" textcolor="0xFF818181" disabledtextcolor="0xFF2D2D30" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41"/> 144 </HorizontalLayout> 145 </VerticalLayout> 146 147 <!--占位--> 148 <Control name="control_2" width="45" visible="false"/> 149 150 </HorizontalLayout> 151 </AnimationTabLayout> 152 </VerticalLayout> 153 154 <!--Button 区--> 155 <HorizontalLayout height="40"> 156 157 <!--占位--> 158 <Control/> 159 160 <!--重置按钮--> 161 <Button name="btn_reset" autocalcwidth="true" text="重置" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 162 163 <!--开始按钮--> 164 <Button name="btn_start" autocalcwidth="true" text="开始" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 165 <!--暂停按钮--> 166 <Button name="btn_pause" visible="false" autocalcwidth="true" text="暂停" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 167 <!--继续按钮--> 168 <Button name="btn_resume" visible="false" autocalcwidth="true" text="继续" font="1" textcolor="0xFF818181" hottextcolor="0xFFF1F1F1" hotbkcolor="0xFF3F3F41" textpadding="20,0,20,0" padding="5,0,5,0"/> 169 170 <!--占位--> 171 <Control/> 172 173 </HorizontalLayout> 174 </VerticalLayout> 175 </Window>