OSDN Git Service

ecfba3adb6488a93801c57a1e3ac2591ebeba36b
[wintimer/wintimer.git] / wintimer / application.cpp
1 /*
2   ==============================================================================
3
4    This file is part of the mini timer
5    Copyright 2005-10 by Satoshi Fujiwara.
6
7    mini timer can be redistributed and/or modified under the terms of the
8    GNU General Public License, as published by the Free Software Foundation;
9    either version 2 of the License, or (at your option) any later version.
10
11    mini timer is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with mini timer; if not, visit www.gnu.org/licenses or write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
19    Boston, MA 02111-1307 USA
20
21   ==============================================================================
22 */
23 #include "StdAfx.h"
24 #include "toplevel_window.h"
25 #include "sf_windows.h"
26 #include "message_loop.h"
27 #include "sf_com.h"
28 #include "application.h"
29
30 namespace sf {
31 #ifdef _DEBUG
32   std::wstring application::app_id_(L"SF.MiniTimerDebug");
33 #else
34   std::wstring application::app_id_(L"SF.MiniTimer");
35 #endif
36
37 int application::execute(HINSTANCE hInstance,
38                      HINSTANCE hPrevInstance,
39                      LPTSTR    lpCmdLine,
40                      int       nCmdShow)
41 {
42   UNREFERENCED_PARAMETER(hPrevInstance);
43         UNREFERENCED_PARAMETER(lpCmdLine);
44
45   std::wcout.imbue(std::locale(""));
46
47   // 2\8fd\8bN\93®\82Ì\96h\8e~
48         SECURITY_DESCRIPTOR sd;
49         InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
50         SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);     
51         SECURITY_ATTRIBUTES sec_attr;
52         sec_attr.nLength = sizeof (sec_attr);
53         sec_attr.lpSecurityDescriptor = &sd;
54         sec_attr.bInheritHandle = TRUE; 
55 #ifdef _DEBUG 
56   sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("wintimer_mutex_debug")));
57 #else
58   sf::handle_holder handle(::CreateMutex(&sec_attr, FALSE, _T("wintimer_mutex")));
59 #endif
60
61         if(NULL == handle.get() || ::GetLastError() == ERROR_ALREADY_EXISTS)
62         {
63     return 0;
64         }
65
66   // COM\82Ì\8f\89\8aú\89»
67   sf::com_initialize init();
68
69   // \83A\83v\83\8a\83P\81[\83V\83\87\83\93ID\82Ì\93o\98^
70   sf::throw_if_err<application::exception>()(SetCurrentProcessExplicitAppUserModelID(app_id_.c_str()));
71   
72
73   // \83E\83B\83\93\83h\83E\82Ì\8dì\90¬
74   sf::toplevel_window_ptr 
75     window(
76       sf::create_toplevel_window(
77         std::wstring(L"\83~\83j\83^\83C\83}\81["),std::wstring(L"\83~\83j\83^\83C\83}\81[")));
78   
79   // \83\81\83b\83Z\81[\83W\83\8b\81[\83v\82Ì\8eÀ\8ds
80   WPARAM ret = sf::run_message_loop()();
81   return ret;
82 }
83
84 }