OSDN Git Service

cd42e3264889eaaca1f0314a7a7e6a3145c08755
[yamy/yamy.git] / dlgversion.cpp
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // dlgversion.cpp
3
4
5 #include "misc.h"
6
7 #include "mayu.h"
8 #include "mayurc.h"
9 #include "windowstool.h"
10 #include "compiler_specific_func.h"
11 #include "layoutmanager.h"
12
13 #include <cstdio>
14 #include <windowsx.h>
15
16
17 ///
18 class DlgVersion : public LayoutManager
19 {
20   HWND m_hwnd;          ///
21   
22 public:
23   ///
24   DlgVersion(HWND i_hwnd)
25     : LayoutManager(i_hwnd),
26       m_hwnd(i_hwnd)
27   {
28   }
29   
30   /// WM_INITDIALOG
31   BOOL wmInitDialog(HWND /* i_focus */, LPARAM i_lParam)
32   {
33     TCHAR *mayudVersion = (TCHAR*)i_lParam;
34     setSmallIcon(m_hwnd, IDI_ICON_mayu);
35     setBigIcon(m_hwnd, IDI_ICON_mayu);
36     
37     _TCHAR modulebuf[1024];
38     CHECK_TRUE( GetModuleFileName(g_hInst, modulebuf,
39                                   NUMBER_OF(modulebuf)) );
40     
41     _TCHAR buf[1024];
42     _sntprintf(buf, NUMBER_OF(buf), loadString(IDS_version).c_str(),
43                _T(VERSION)
44 #ifndef NDEBUG
45                _T(" (DEBUG)")
46 #endif // !NDEBUG
47 #ifdef _UNICODE
48                _T(" (UNICODE)")
49 #endif // !_UNICODE
50                ,
51                mayudVersion,
52                loadString(IDS_homepage).c_str(),
53                (_T(LOGNAME) _T("@") + toLower(_T(COMPUTERNAME))).c_str(),
54                _T(__DATE__) _T(" ") _T(__TIME__),
55                getCompilerVersionString().c_str(),
56                modulebuf);
57     
58     
59     Edit_SetText(GetDlgItem(m_hwnd, IDC_EDIT_builtBy), buf);
60     
61     // set layout manager
62     typedef LayoutManager LM;
63
64     addItem(GetDlgItem(m_hwnd, IDC_STATIC_mayuIcon),
65             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE,
66             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE);
67     addItem(GetDlgItem(m_hwnd, IDC_EDIT_builtBy),
68             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE,
69             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_BOTTOM_EDGE);
70     addItem(GetDlgItem(m_hwnd, IDC_BUTTON_download),
71             LM::ORIGIN_CENTER, LM::ORIGIN_BOTTOM_EDGE,
72             LM::ORIGIN_CENTER, LM::ORIGIN_BOTTOM_EDGE);
73     addItem(GetDlgItem(m_hwnd, IDOK),
74             LM::ORIGIN_CENTER, LM::ORIGIN_BOTTOM_EDGE,
75             LM::ORIGIN_CENTER, LM::ORIGIN_BOTTOM_EDGE);
76     restrictSmallestSize();
77     
78     return TRUE;
79   }
80   
81   /// WM_CLOSE
82   BOOL wmClose()
83   {
84     CHECK_TRUE( EndDialog(m_hwnd, 0) );
85     return TRUE;
86   }
87
88   /// WM_COMMAND
89   BOOL wmCommand(int /* i_notifyCode */, int i_id, HWND /* i_hwndControl */)
90   {
91     switch (i_id)
92     {
93       case IDOK:
94       {
95         CHECK_TRUE( EndDialog(m_hwnd, 0) );
96         return TRUE;
97       }
98       case IDC_BUTTON_download:
99       {
100         ShellExecute(NULL, NULL, loadString(IDS_homepage).c_str(),
101                      NULL, NULL, SW_SHOWNORMAL);
102         CHECK_TRUE( EndDialog(m_hwnd, 0) );
103         return TRUE;
104       }
105     }
106     return FALSE;
107   }
108 };
109
110
111 //
112 #ifdef MAYU64
113 INT_PTR CALLBACK dlgVersion_dlgProc(
114 #else
115 BOOL CALLBACK dlgVersion_dlgProc(
116 #endif
117   HWND i_hwnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam)
118 {
119   DlgVersion *wc;
120   getUserData(i_hwnd, &wc);
121   if (!wc)
122     switch (i_message)
123     {
124       case WM_INITDIALOG:
125         wc = setUserData(i_hwnd, new DlgVersion(i_hwnd));
126         return wc->wmInitDialog(reinterpret_cast<HWND>(i_wParam), i_lParam);
127     }
128   else
129     switch (i_message)
130     {
131       case WM_COMMAND:
132         return wc->wmCommand(HIWORD(i_wParam), LOWORD(i_wParam),
133                              reinterpret_cast<HWND>(i_lParam));
134       case WM_CLOSE:
135         return wc->wmClose();
136       case WM_NCDESTROY:
137         delete wc;
138         return TRUE;
139       default:
140         return wc->defaultWMHandler(i_message, i_wParam, i_lParam);
141     }
142   return FALSE;
143 }