OSDN Git Service

とりあえず動くバージョン
authorSFPGMR <sfpg@git.sourceforge.jp>
Mon, 25 Apr 2011 09:37:56 +0000 (18:37 +0900)
committerSFPGMR <sfpg@git.sourceforge.jp>
Mon, 25 Apr 2011 09:37:56 +0000 (18:37 +0900)
wintimer/toplevel_window.cpp
wintimer/toplevel_window.h

index 695c2e9..4693189 100644 (file)
@@ -42,7 +42,8 @@ namespace sf
   }
   
   toplevel_window::toplevel_window(const std::wstring& menu_name,const std::wstring& name,
-    bool fit_to_display,float width,float height) : base_window(menu_name,name,fit_to_display,width,height) , wm_task_bar_create_(0)
+    bool fit_to_display,float width,float height) 
+    : base_window(menu_name,name,fit_to_display,width,height) , wm_task_bar_create_(0),timer_id_(0),result_time_(INTERVAL_SEC1),status_(active)
   {
     on_render.connect(boost::bind(&toplevel_window::render,this));
   };
@@ -59,7 +60,7 @@ namespace sf
       WS_EX_APPWINDOW,
       name_.c_str(),
       title_.c_str(),
-      WS_SYSMENU ,
+      0 ,
       CW_USEDEFAULT,
       CW_USEDEFAULT,
       static_cast<boost::uint32_t>(ceil(width_ /** dpiX / 96.f*/)),
@@ -82,6 +83,8 @@ namespace sf
         // TODO:
         create_device();
         wm_task_bar_create_ = RegisterWindowMessage(L"TaskbarButtonCreated");
+        //MARGINS mgn = {-1,0,0,0};//let,right,top,bottom
+        //HRESULT hr = DwmExtendFrameIntoClientArea(hwnd_, &mgn);
         break;
       }
     case WM_SIZE:
@@ -108,7 +111,7 @@ namespace sf
           render();
         }
 
-        ::ShowWindow(hwnd_,SW_MINIMIZE);
+//        ::ShowWindow(hwnd_,SW_MINIMIZE);
         return FALSE;
       }
     case WM_DISPLAYCHANGE:
@@ -123,20 +126,68 @@ namespace sf
       {
         //                                     on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); 
       }
+      break;
     case WM_LBUTTONDOWN:
       {
       }
+      break;
+    case WM_TIMER:
+      {
+        switch (status_)
+        {
+        case active:
+          --result_time_;
+          taskbar_list_->SetProgressValue(hwnd_,result_time_,INTERVAL_SEC1);
+
+          if(result_time_ == 0)
+          {
+            ::MessageBeep(MB_ICONEXCLAMATION);
+            status_ = sleep;
+            result_time_ = INTERVAL_SEC2;
+            taskbar_list_->SetProgressState(hwnd_,TBPF_PAUSED);
+            taskbar_list_->SetProgressValue(hwnd_,result_time_,INTERVAL_SEC2);
+          }
+            ::InvalidateRect(hwnd_,NULL,FALSE);
+          break;
+        case sleep:
+          {
+            --result_time_;
+            taskbar_list_->SetProgressValue(hwnd_,result_time_,INTERVAL_SEC2);
+            if(result_time_ == 0)
+            {
+              ::MessageBeep(MB_OK);
+              status_ = active;
+              result_time_ = INTERVAL_SEC1;
+              taskbar_list_->SetProgressState(hwnd_,TBPF_INDETERMINATE);
+              taskbar_list_->SetProgressValue(hwnd_,result_time_,INTERVAL_SEC1);
+            }
+            ::InvalidateRect(hwnd_,NULL,FALSE);
+          }
+          break;
+        }
+    case WM_DWMCOMPOSITIONCHANGED:
+      {
+        //MARGINS mgn = {-1,0,0,0};//let,right,top,bottom
+        //HRESULT hr = DwmExtendFrameIntoClientArea(hwnd_, &mgn);
+      }
+      break;
+        //::SetTimer(hwnd_,(UINT_PTR)&timer_id_,1000,NULL);
+      }
     }
 
     if(message == wm_task_bar_create_)
     {
       THROW_IFERR(taskbar_list_.CreateInstance(CLSID_TaskbarList,0,CLSCTX_INPROC));
-      taskbar_list_->SetProgressState(hwnd_,TBPF_NORMAL);
-      taskbar_list_->SetProgressValue(hwnd_,30,100);
+      taskbar_list_->SetOverlayIcon(hwnd_,NULL,L"ミニタイマー");
+      taskbar_list_->SetProgressState(hwnd_,TBPF_INDETERMINATE);
+      taskbar_list_->SetProgressValue(hwnd_,100,100);
+      // タイマーの設定
+      ::SetTimer(hwnd_,(UINT_PTR)&timer_id_,1000,NULL);
     }
 
     if(message == WM_CLOSE)
     {
+      ::KillTimer(hwnd_,(UINT_PTR)&timer_id_);
       //
       safe_release(taskbar_list_);
       // 後始末
@@ -189,13 +240,18 @@ namespace sf
           DWRITE_FONT_WEIGHT_REGULAR,
           DWRITE_FONT_STYLE_NORMAL,
           DWRITE_FONT_STRETCH_NORMAL,
-          10.0f,
+          18.0f,
           L"ja-jp",
           &write_text_format
           ));
         // Actually draw the text at the origin.
-        std::wstring m(L"こんにちは、64Bitの世界!By S.F.");
-        render_target_->DrawTextW(
+        if(status_ == active){
+          ::SetWindowTextW(hwnd_,L"ミニタイマー(活動中)");
+        } else {
+          ::SetWindowTextW(hwnd_,L"ミニタイマー(休憩中)");
+        }
+         std::wstring m((boost::wformat(L"残り%d分%d秒") % (result_time_ / 60) % (result_time_ % 60)).str());
+         render_target_->DrawTextW(
           m.c_str(),
           m.size(),
           write_text_format,
index dc3f4b8..69fa085 100644 (file)
@@ -15,8 +15,8 @@ namespace sf
     const std::wstring& name,
     const boost::uint32_t show_flag = SW_NORMAL,
     bool fit_to_display = false,
-    float width = 100,
-    float height = 80
+    float width = 180,
+    float height = 60
     );
 
 
@@ -45,6 +45,18 @@ namespace sf
   private:
     long wm_task_bar_create_;
     ITaskbarList3Ptr taskbar_list_;
+    UINT timer_id_;
+    static const int INTERVAL_SEC1 = 60 * 15;// 15分
+    static const int INTERVAL_SEC2 = 30;// 30秒
+
+    int result_time_;
+    enum timer_status {
+      active,
+      sleep
+    };
+
+    timer_status status_;
+    
   };