Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit c53de9f

Browse files
committed
ClockWindowProc logically (and alphabetically) belongs first
1 parent c98e87d commit c53de9f

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

uclock.c

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,66 @@ struct clock_window {
5656
HFONT hFontUptime;
5757
};
5858

59-
static int CreateClockWindow(HWND hwnd);
60-
static void DestroyClockWindow(struct clock_window *window);
61-
6259
static LRESULT CALLBACK ClockWindowProc(HWND hwnd, UINT uMsg,
6360
WPARAM wParam, LPARAM lParam);
61+
static int CreateClockWindow(HWND hwnd);
62+
static void DestroyClockWindow(struct clock_window *window);
6463
static void PaintClock(struct clock_window *window);
6564
static void RefreshClock(struct clock_window *window);
6665
static void ResizeClock(struct clock_window *window);
6766

67+
/*
68+
* Process clock window messages.
69+
*/
70+
LRESULT CALLBACK
71+
ClockWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
72+
{
73+
struct clock_window *window =
74+
(uMsg == WM_CREATE) ? NULL :
75+
(struct clock_window*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
76+
77+
switch (uMsg) {
78+
case WM_CREATE:
79+
return CreateClockWindow(hwnd);
80+
81+
case WM_KEYDOWN:
82+
switch (wParam) {
83+
case VK_ESCAPE:
84+
case VK_CONTROL | 'q':
85+
case VK_CONTROL | 'Q':
86+
case VK_CONTROL | 'w':
87+
case VK_CONTROL | 'W':
88+
// Close the window when Esc, Ctrl+Q, or Ctrl+W is pressed
89+
DestroyWindow(hwnd);
90+
return 0;
91+
}
92+
break;
93+
94+
case WM_PAINT:
95+
PaintClock(window);
96+
return 0;
97+
98+
case WM_SIZE:
99+
ResizeClock(window);
100+
return 0;
101+
102+
case WM_TIMER:
103+
switch (wParam) {
104+
case IDT_REFRESH:
105+
RefreshClock(window);
106+
break;
107+
}
108+
return 0;
109+
110+
case WM_DESTROY:
111+
DestroyClockWindow(window);
112+
PostQuitMessage(0);
113+
return 0;
114+
}
115+
116+
return DefWindowProc(hwnd, uMsg, wParam, lParam);
117+
}
118+
68119
/*
69120
* Create the clock window.
70121
* Processes WM_CREATE for ClockWindowProc().
@@ -181,58 +232,6 @@ DestroyClockWindow(struct clock_window *window)
181232
free(window);
182233
}
183234

184-
/*
185-
* Process clock window messages.
186-
*/
187-
LRESULT CALLBACK
188-
ClockWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
189-
{
190-
struct clock_window *window =
191-
(uMsg == WM_CREATE) ? NULL :
192-
(struct clock_window*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
193-
194-
switch (uMsg) {
195-
case WM_CREATE:
196-
return CreateClockWindow(hwnd);
197-
198-
case WM_KEYDOWN:
199-
switch (wParam) {
200-
case VK_ESCAPE:
201-
case VK_CONTROL | 'q':
202-
case VK_CONTROL | 'Q':
203-
case VK_CONTROL | 'w':
204-
case VK_CONTROL | 'W':
205-
// Close the window when Esc, Ctrl+Q, or Ctrl+W is pressed
206-
DestroyWindow(hwnd);
207-
return 0;
208-
}
209-
break;
210-
211-
case WM_PAINT:
212-
PaintClock(window);
213-
return 0;
214-
215-
case WM_SIZE:
216-
ResizeClock(window);
217-
return 0;
218-
219-
case WM_TIMER:
220-
switch (wParam) {
221-
case IDT_REFRESH:
222-
RefreshClock(window);
223-
break;
224-
}
225-
return 0;
226-
227-
case WM_DESTROY:
228-
DestroyClockWindow(window);
229-
PostQuitMessage(0);
230-
return 0;
231-
}
232-
233-
return DefWindowProc(hwnd, uMsg, wParam, lParam);
234-
}
235-
236235
/*
237236
* Paint the clock window.
238237
* Processes WM_PAINT for ClockWindowProc().
@@ -249,6 +248,7 @@ PaintClock(struct clock_window *window)
249248

250249
/*
251250
* Refresh the clock display.
251+
* Processes WM_TIMER for ClockWindowProc().
252252
*/
253253
void
254254
RefreshClock(struct clock_window *window)

0 commit comments

Comments
 (0)