Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #include <sstream> | |
2 #include <string> | |
3 #include <Windows.h> | |
4 | |
5 #include "../shared/Dictionary.h" | |
6 #include "../shared/Utils.h" | |
7 #include "UpdateInstallDialog.h" | |
8 | |
9 namespace | |
10 { | |
11 LRESULT CALLBACK ProcessWindowMessage(HWND window, UINT message, | |
12 WPARAM wParam, LPARAM lParam) | |
13 { | |
14 switch (message) | |
15 { | |
16 case WM_CLOSE: | |
17 PostQuitMessage(0); | |
18 return 0; | |
19 case WM_COMMAND: | |
20 switch (LOWORD(wParam)) | |
21 { | |
22 case IDYES: | |
23 PostQuitMessage(1); | |
24 return 0; | |
25 case IDNO: | |
26 PostQuitMessage(0); | |
27 return 0; | |
28 } | |
29 break; | |
30 } | |
31 return DefWindowProc(window, message, wParam, lParam); | |
32 } | |
33 } | |
34 | |
35 UpdateInstallDialog::UpdateInstallDialog() | |
36 { | |
37 const std::wstring windowClassName = L"UPDATE_INSTALL_DIALOG"; | |
38 WNDCLASSEX windowClass = {}; | |
Wladimir Palant
2013/08/01 09:58:24
We should use WNDCLASSEXW explicitly.
| |
39 windowClass.cbSize = sizeof(WNDCLASSEX); | |
Wladimir Palant
2013/08/01 09:58:24
sizeof(windowClass) to avoid repeating the type na
Felix Dahlke
2013/08/02 10:48:01
Done.
| |
40 windowClass.lpfnWndProc = ProcessWindowMessage; | |
41 windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_MENU + 1); | |
42 windowClass.lpszClassName = windowClassName.c_str(); | |
Oleksandr
2013/08/01 07:05:12
Maybe use hIcon here with ABP logo? A default wind
| |
43 if (!RegisterClassEx(&windowClass)) | |
44 { | |
45 std::stringstream stream; | |
46 stream << "Failed to register window class " | |
47 << ToUtf8String(windowClassName) << ": " << GetLastError(); | |
48 throw std::runtime_error(stream.str()); | |
49 } | |
50 | |
51 Dictionary* dictionary = Dictionary::GetInstance(); | |
52 std::wstring title = dictionary->Lookup("updater", "install-question-title"); | |
Oleksandr
2013/07/31 22:16:59
This is fine only for when download is ready. How
Felix Dahlke
2013/08/01 07:21:17
Like I said earlier, I think it's better to focus
| |
53 | |
54 RECT workArea; | |
55 SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0); | |
56 | |
57 const int width = 300; | |
58 const int height = 150; | |
Wladimir Palant
2013/08/01 09:58:24
Where do these numbers come from? What will happen
Felix Dahlke
2013/08/02 10:48:01
Done.
| |
59 const int margin = 10; | |
60 | |
61 window = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, | |
62 windowClassName.c_str(), title.c_str(), WS_SYSMENU, | |
63 workArea.right - width - margin, | |
64 workArea.bottom - height - margin, | |
65 width, height, 0, 0, 0, 0); | |
Oleksandr
2013/08/01 07:05:12
Should we do something like:
SetForegroundWindow(
| |
66 CreateText(); | |
67 CreateButtons(); | |
Oleksandr
2013/07/31 22:16:59
No CreateButtons() in the overridden constructor I
Felix Dahlke
2013/08/01 07:21:17
As I said above, let's make this more generic when
| |
68 } | |
69 | |
70 UpdateInstallDialog::~UpdateInstallDialog() | |
71 { | |
72 DestroyWindow(window); | |
73 } | |
74 | |
75 bool UpdateInstallDialog::Show() | |
76 { | |
77 ShowWindow(window, SW_SHOW); | |
78 MSG message; | |
79 while(GetMessage(&message, 0, 0, 0) > 0) | |
80 { | |
81 TranslateMessage(&message); | |
82 DispatchMessage(&message); | |
83 } | |
84 ShowWindow(window, SW_HIDE); | |
85 return message.wParam; | |
Wladimir Palant
2013/08/01 09:58:24
Doesn't this cause a warning? I would rather cast
Felix Dahlke
2013/08/02 10:48:01
Done. Opted for message.wParam == 0 in case of yes
| |
86 } | |
87 | |
88 void UpdateInstallDialog::CreateText() | |
89 { | |
90 Dictionary* dictionary = Dictionary::GetInstance(); | |
91 std::wstring text = dictionary->Lookup("updater", "install-question-text"); | |
92 | |
93 RECT clientRect; | |
94 GetClientRect(window, &clientRect); | |
95 | |
96 const int margin = 10; | |
97 const int width = clientRect.right - margin * 2; | |
98 const int height = 60; | |
99 | |
100 CreateWindowW(L"STATIC", text.c_str(), WS_CHILD | WS_VISIBLE| SS_LEFT, | |
101 margin, margin, width, height, window, 0, 0, 0); | |
102 } | |
103 | |
104 void UpdateInstallDialog::CreateButtons() | |
105 { | |
106 Dictionary* dictionary = Dictionary::GetInstance(); | |
107 const std::wstring yesLabel = dictionary->Lookup("general", "button-yes"); | |
108 const std::wstring noLabel = dictionary->Lookup("general", "button-no"); | |
109 | |
110 const DWORD buttonFlags = WS_CHILD | WS_VISIBLE; | |
111 | |
112 RECT clientRect; | |
113 GetClientRect(window, &clientRect); | |
114 | |
115 const int buttonWidth = 100; | |
116 const int buttonHeight = 30; | |
Felix Dahlke
2013/08/02 10:48:01
Done.
| |
117 const int margin = 10; | |
118 const int combinedWidth = buttonWidth * 2 + margin; | |
119 const int yesButtonX = clientRect.right - combinedWidth - margin; | |
120 const int noButtonX = yesButtonX + buttonWidth + margin; | |
121 const int buttonY = clientRect.bottom - buttonHeight - margin; | |
122 | |
123 CreateWindowW(L"BUTTON", yesLabel.c_str(), buttonFlags, | |
124 yesButtonX, buttonY, buttonWidth, buttonHeight, | |
125 window, reinterpret_cast<HMENU>(IDYES), 0, 0); | |
126 CreateWindowW(L"BUTTON", noLabel.c_str(), buttonFlags, | |
127 noButtonX, buttonY, buttonWidth, buttonHeight, | |
128 window, reinterpret_cast<HMENU>(IDNO), 0, 0); | |
129 } | |
OLD | NEW |