|
7 | 7 | #include <commctrl.h> |
8 | 8 |
|
9 | 9 |
|
10 | | -AboutDlg::AboutDlg(HINSTANCE hIntance, HWND hParent, int nCmdId) : m_nCmdId(nCmdId), StaticDialog() |
| 10 | +AboutDlg::AboutDlg(HINSTANCE hIntance, HWND hParent, int nCmdId) |
| 11 | + : m_nCmdId(nCmdId) |
| 12 | + , StaticDialog() |
11 | 13 | { |
12 | | - init(hIntance, hParent); |
| 14 | + init(hIntance, hParent); |
13 | 15 | } |
14 | 16 |
|
15 | 17 |
|
16 | 18 | bool AboutDlg::ShowDlg(bool bShow) |
17 | 19 | { |
18 | | - bool bShouldShow = bShow && !isVisible(); |
19 | | - if (bShouldShow) |
20 | | - { |
21 | | - if (!isCreated()) |
22 | | - create(IDD_ABOUTDLG); |
23 | | - |
24 | | - // Adjust the position of AboutBox |
25 | | - goToCenter(); |
26 | | - } |
27 | | - else |
28 | | - { |
29 | | - SendMessage(_hSelf, WM_COMMAND, IDCANCEL, NULL); |
30 | | - } |
31 | | - return bShouldShow; |
| 20 | + bool bShouldShow = bShow && !isVisible(); |
| 21 | + if (bShouldShow) |
| 22 | + { |
| 23 | + if (!isCreated()) |
| 24 | + create(IDD_ABOUTDLG); |
| 25 | + |
| 26 | + // Adjust the position of AboutBox |
| 27 | + goToCenter(); |
| 28 | + } |
| 29 | + else |
| 30 | + { |
| 31 | + SendMessage(_hSelf, WM_COMMAND, IDCANCEL, NULL); |
| 32 | + } |
| 33 | + return bShouldShow; |
32 | 34 | } |
33 | 35 |
|
34 | 36 |
|
35 | 37 | INT_PTR AboutDlg::run_dlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) |
36 | 38 | { |
37 | | - AboutDlg* pSelf = nullptr; |
38 | | - switch (uMsg) |
39 | | - { |
40 | | - case WM_INITDIALOG: |
41 | | - { |
42 | | - ::SetWindowLongPtr(_hSelf, DWLP_USER, lParam); |
43 | | - |
44 | | - pSelf = reinterpret_cast<AboutDlg*>(static_cast<LONG_PTR> (::GetWindowLongPtr(_hSelf, DWLP_USER))); |
45 | | - if (pSelf) |
46 | | - { |
47 | | - pSelf->SetVersion(_hSelf); |
48 | | - } |
49 | | - SetFocus(GetDlgItem(_hSelf, IDOK)); |
50 | | - |
51 | | - // Set links |
52 | | - std::wstring urlIssue(TEXT("<a href=\"__URL__\">__URL__</a>")); |
53 | | - std::wstring urlRepo = urlIssue; |
54 | | - |
55 | | - urlIssue = StringHelper::ReplaceAll(urlIssue, TEXT("__URL__"), URL_REPORT_ISSUE); |
56 | | - urlRepo = StringHelper::ReplaceAll(urlRepo, TEXT("__URL__"), URL_SOURCE_CODE); |
57 | | - |
58 | | - SetWindowText(::GetDlgItem(_hSelf, IDC_WEB_ISSUE), urlIssue.c_str()); |
59 | | - SetWindowText(::GetDlgItem(_hSelf, IDC_WEB_SOURCE), urlRepo.c_str()); |
60 | | - |
61 | | - return TRUE; |
62 | | - } |
63 | | - |
64 | | - case WM_NOTIFY: |
65 | | - { |
66 | | - switch (reinterpret_cast<LPNMHDR>(lParam)->code) |
67 | | - { |
68 | | - case NM_CLICK: |
69 | | - case NM_RETURN: |
70 | | - { |
71 | | - auto nmLink = reinterpret_cast<PNMLINK>(lParam); |
72 | | - LITEM item = nmLink->item; |
73 | | - |
74 | | - ShellExecute(nullptr, L"open", item.szUrl, nullptr, nullptr, SW_SHOW); |
75 | | - return TRUE; |
76 | | - } |
77 | | - } |
78 | | - return FALSE; |
79 | | - } |
80 | | - |
81 | | - case WM_COMMAND: |
82 | | - { |
83 | | - pSelf = reinterpret_cast<AboutDlg*>(static_cast<LONG_PTR> (::GetWindowLongPtr(_hSelf, DWLP_USER))); |
84 | | - switch (LOWORD(wParam)) |
85 | | - { |
86 | | - case IDCANCEL: // Close this dialog when clicking to close button |
87 | | - case IDOK: |
88 | | - if (pSelf) |
89 | | - ::SendMessage(pSelf->_hParent, NPPM_SETMENUITEMCHECK, static_cast<WPARAM>(pSelf->m_nCmdId), false); |
90 | | - EndDialog(_hSelf, wParam); |
91 | | - _hSelf = nullptr; |
92 | | - return TRUE; |
93 | | - } |
94 | | - } |
95 | | - } |
96 | | - return FALSE; |
| 39 | + AboutDlg *pSelf = nullptr; |
| 40 | + switch (uMsg) |
| 41 | + { |
| 42 | + case WM_INITDIALOG: |
| 43 | + { |
| 44 | + ::SetWindowLongPtr(_hSelf, DWLP_USER, lParam); |
| 45 | + |
| 46 | + pSelf = reinterpret_cast<AboutDlg *>(static_cast<LONG_PTR>(::GetWindowLongPtr(_hSelf, DWLP_USER))); |
| 47 | + if (pSelf) |
| 48 | + { |
| 49 | + pSelf->SetVersion(_hSelf); |
| 50 | + } |
| 51 | + SetFocus(GetDlgItem(_hSelf, IDOK)); |
| 52 | + |
| 53 | + // Set links |
| 54 | + std::wstring urlIssue(TEXT("<a href=\"__URL__\">__URL__</a>")); |
| 55 | + std::wstring urlRepo = urlIssue; |
| 56 | + |
| 57 | + urlIssue = StringHelper::ReplaceAll(urlIssue, TEXT("__URL__"), URL_REPORT_ISSUE); |
| 58 | + urlRepo = StringHelper::ReplaceAll(urlRepo, TEXT("__URL__"), URL_SOURCE_CODE); |
| 59 | + |
| 60 | + SetWindowText(::GetDlgItem(_hSelf, IDC_WEB_ISSUE), urlIssue.c_str()); |
| 61 | + SetWindowText(::GetDlgItem(_hSelf, IDC_WEB_SOURCE), urlRepo.c_str()); |
| 62 | + |
| 63 | + return TRUE; |
| 64 | + } |
| 65 | + |
| 66 | + case WM_NOTIFY: |
| 67 | + { |
| 68 | + switch (reinterpret_cast<LPNMHDR>(lParam)->code) |
| 69 | + { |
| 70 | + case NM_CLICK: |
| 71 | + case NM_RETURN: |
| 72 | + { |
| 73 | + auto nmLink = reinterpret_cast<PNMLINK>(lParam); |
| 74 | + LITEM item = nmLink->item; |
| 75 | + |
| 76 | + ShellExecute(nullptr, L"open", item.szUrl, nullptr, nullptr, SW_SHOW); |
| 77 | + return TRUE; |
| 78 | + } |
| 79 | + } |
| 80 | + return FALSE; |
| 81 | + } |
| 82 | + |
| 83 | + case WM_COMMAND: |
| 84 | + { |
| 85 | + pSelf = reinterpret_cast<AboutDlg *>(static_cast<LONG_PTR>(::GetWindowLongPtr(_hSelf, DWLP_USER))); |
| 86 | + switch (LOWORD(wParam)) |
| 87 | + { |
| 88 | + case IDCANCEL: // Close this dialog when clicking to close button |
| 89 | + case IDOK: |
| 90 | + if (pSelf) |
| 91 | + ::SendMessage(pSelf->_hParent, NPPM_SETMENUITEMCHECK, static_cast<WPARAM>(pSelf->m_nCmdId), false); |
| 92 | + EndDialog(_hSelf, wParam); |
| 93 | + _hSelf = nullptr; |
| 94 | + return TRUE; |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + return FALSE; |
97 | 99 | } |
98 | 100 |
|
99 | 101 | void AboutDlg::SetVersion(HWND hWnd) |
100 | 102 | { |
101 | | - std::wstring version; |
102 | | - |
103 | | - // Get module path |
104 | | - wchar_t moduleFileName[MAX_PATH + 1] = {}; |
105 | | - ::GetModuleFileName(static_cast<HMODULE>(getHinst()), moduleFileName, _MAX_PATH); |
106 | | - |
107 | | - version = CUtility::GetVersion(moduleFileName); |
108 | | - if (!version.empty()) |
109 | | - { |
110 | | - std::wstring text(PLUGIN_NAME); |
111 | | - text += TEXT(" ("); |
112 | | - text += STR_VERSION; |
113 | | - text += version; |
114 | | - text += TEXT(") "); |
115 | | - ::SetWindowText(::GetDlgItem(hWnd, IDC_GB_TITLE), text.c_str()); |
116 | | - } |
| 103 | + std::wstring version; |
| 104 | + |
| 105 | + // Get module path |
| 106 | + wchar_t moduleFileName[MAX_PATH + 1] = {}; |
| 107 | + ::GetModuleFileName(static_cast<HMODULE>(getHinst()), moduleFileName, _MAX_PATH); |
| 108 | + |
| 109 | + version = CUtility::GetVersion(moduleFileName); |
| 110 | + if (!version.empty()) |
| 111 | + { |
| 112 | + std::wstring text(PLUGIN_NAME); |
| 113 | + text += TEXT(" ("); |
| 114 | + text += STR_VERSION; |
| 115 | + text += version; |
| 116 | + text += TEXT(") "); |
| 117 | + ::SetWindowText(::GetDlgItem(hWnd, IDC_GB_TITLE), text.c_str()); |
| 118 | + } |
117 | 119 | } |
118 | | - |
|
0 commit comments