23 |
|
|
24 |
#include "wptW32API.h" |
#include "wptW32API.h" |
25 |
|
|
26 |
#define PD_WINDOWNAME "ClsTrayPop" |
#define PD_WINDOWNAME "WinPT_TrayPop" |
27 |
#define PD_TIMER_IDENTIFIER 23 |
#define PD_TIMER_IDENTIFIER 23 |
28 |
#define PD_TIMER_TIMEOUT 1500 |
#define PD_TIMER_TIMEOUT 1500 |
29 |
|
|
43 |
if (alert_text) |
if (alert_text) |
44 |
text = alert_text; |
text = alert_text; |
45 |
return text; |
return text; |
46 |
} /* store_text */ |
} |
47 |
|
|
48 |
|
|
49 |
static void |
static void |
67 |
FF_DONTCARE, // pitch and family |
FF_DONTCARE, // pitch and family |
68 |
"Tahoma" // typeface name |
"Tahoma" // typeface name |
69 |
); |
); |
70 |
|
|
71 |
HFONT hOldFont = (HFONT) SelectObject(*p_hdc, hFont); |
HFONT hOldFont = (HFONT) SelectObject (*p_hdc, hFont); |
72 |
RECT recttext; |
RECT recttext; |
73 |
recttext.top = 0; |
recttext.top = 0; |
74 |
recttext.bottom = PD_TRAYPOP_HEIGHT - 2; |
recttext.bottom = PD_TRAYPOP_HEIGHT - 2; |
75 |
recttext.left = 10; |
recttext.left = 10; |
76 |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
77 |
|
|
78 |
MoveToEx(*p_hdc, 0, 0, (LPPOINT) NULL); |
MoveToEx (*p_hdc, 0, 0, (LPPOINT) NULL); |
79 |
LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, 0); |
LineTo (*p_hdc, PD_TRAYPOP_WIDTH - 3, 0); |
80 |
LineTo(*p_hdc, PD_TRAYPOP_WIDTH - 3, PD_TRAYPOP_HEIGHT - 3); |
LineTo (*p_hdc, PD_TRAYPOP_WIDTH - 3, PD_TRAYPOP_HEIGHT - 3); |
81 |
LineTo(*p_hdc, 0, PD_TRAYPOP_HEIGHT - 3); |
LineTo (*p_hdc, 0, PD_TRAYPOP_HEIGHT - 3); |
82 |
LineTo(*p_hdc, 0, 0); |
LineTo (*p_hdc, 0, 0); |
83 |
|
|
84 |
UINT dtFormat = DT_END_ELLIPSIS | DT_NOPREFIX | DT_WORDBREAK; |
UINT dtFormat = DT_END_ELLIPSIS | DT_NOPREFIX | DT_WORDBREAK; |
85 |
|
|
86 |
// determine text height |
/* determine text height */ |
87 |
int text_height = DrawText( |
int text_height = DrawText (*p_hdc, store_text (NULL), |
88 |
*p_hdc, // handle to DC |
-1, &recttext, |
89 |
store_text(NULL), // text to draw |
dtFormat | DT_CENTER | DT_CALCRECT); |
|
-1, // text length // TODO: future i18n problem, see docs |
|
|
&recttext, // formatting dimensions |
|
|
dtFormat | DT_CENTER | DT_CALCRECT |
|
|
); |
|
90 |
|
|
91 |
// vertically center text in the box |
/* vertically center text in the box */ |
92 |
recttext.top = PD_TRAYPOP_HEIGHT/2 - text_height/2 - 5; |
recttext.top = PD_TRAYPOP_HEIGHT/2 - text_height/2 - 5; |
93 |
recttext.bottom = PD_TRAYPOP_HEIGHT/2 + text_height/2 + 5; |
recttext.bottom = PD_TRAYPOP_HEIGHT/2 + text_height/2 + 5; |
94 |
recttext.left = 10; |
recttext.left = 10; |
95 |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
recttext.right = PD_TRAYPOP_WIDTH - 12; |
96 |
|
|
97 |
// change over to left-justified from centered, for longer lines |
/* change over to left-justified from centered, for longer lines */ |
98 |
(text_height > 30)? (dtFormat |= DT_LEFT) : (dtFormat |= DT_CENTER); |
(text_height > 30)? (dtFormat |= DT_LEFT) : (dtFormat |= DT_CENTER); |
99 |
|
|
100 |
DrawText (*p_hdc, |
DrawText (*p_hdc, store_text (NULL), |
101 |
store_text (NULL), |
-1, &recttext, dtFormat); |
|
-1, // text length // TODO: future i18n problem, see docs |
|
|
&recttext, // formatting dimensions |
|
|
dtFormat); |
|
102 |
|
|
103 |
hFont = (HFONT) SelectObject(*p_hdc, hOldFont); |
hFont = (HFONT) SelectObject(*p_hdc, hOldFont); |
104 |
DeleteObject(hFont); |
DeleteObject(hFont); |
105 |
} /* paint_alert */ |
} |
106 |
|
|
107 |
|
|
108 |
|
/* Window procedure for the message box. */ |
109 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
110 |
WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
window_proc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
111 |
{ |
{ |
112 |
PAINTSTRUCT ps; |
PAINTSTRUCT ps; |
113 |
HDC hdc; |
HDC hdc; |
114 |
|
|
115 |
switch (msg) |
switch (msg) { |
|
{ |
|
116 |
case WM_PAINT: |
case WM_PAINT: |
117 |
hdc = BeginPaint (hWnd, &ps); |
hdc = BeginPaint (hWnd, &ps); |
118 |
paint_alert (&hdc, &ps); |
paint_alert (&hdc, &ps); |
128 |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
KillTimer (hWnd, PD_TIMER_IDENTIFIER); |
129 |
PostQuitMessage (1); |
PostQuitMessage (1); |
130 |
break; |
break; |
131 |
|
|
132 |
default: |
default: |
133 |
return DefWindowProc (hWnd, msg, wParam, lParam); |
return DefWindowProc (hWnd, msg, wParam, lParam); |
134 |
} |
} |
135 |
|
|
136 |
return 0; |
return 0; |
137 |
} /* WndProc */ |
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
/* Simple timer function which destroys the (message) window . */ |
142 |
static VOID CALLBACK |
static VOID CALLBACK |
143 |
popup_timer_proc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
popup_timer_proc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
144 |
{ |
{ |
145 |
DestroyWindow(hwnd); |
DestroyWindow (hwnd); |
146 |
} /* popup_timer_proc */ |
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
/* Init window class. */ |
151 |
static void |
static void |
152 |
init_wclass (WNDCLASS *p_wclass, HINSTANCE hInst) |
init_wclass (WNDCLASS *p_wclass, HINSTANCE hInst) |
153 |
{ |
{ |
154 |
p_wclass->style = CS_HREDRAW | CS_VREDRAW; |
p_wclass->style = CS_HREDRAW | CS_VREDRAW; |
155 |
p_wclass->lpfnWndProc = WndProc; |
p_wclass->lpfnWndProc = window_proc; |
156 |
p_wclass->cbClsExtra = 0; |
p_wclass->cbClsExtra = 0; |
157 |
p_wclass->cbWndExtra = 0; |
p_wclass->cbWndExtra = 0; |
158 |
p_wclass->hInstance = hInst; |
p_wclass->hInstance = hInst; |
161 |
p_wclass->hbrBackground = (HBRUSH) (COLOR_INFOBK + 1); |
p_wclass->hbrBackground = (HBRUSH) (COLOR_INFOBK + 1); |
162 |
p_wclass->lpszMenuName = NULL; |
p_wclass->lpszMenuName = NULL; |
163 |
p_wclass->lpszClassName = PD_WINDOWNAME; |
p_wclass->lpszClassName = PD_WINDOWNAME; |
164 |
} /* init_wclass */ |
} |
165 |
|
|
166 |
|
|
167 |
/* Show the given message in a pop-up window for millis miliseconds. */ |
/* Show the given message in a pop-up window for millis miliseconds. */ |
182 |
init_wclass (&wClass, glob_hinst); |
init_wclass (&wClass, glob_hinst); |
183 |
RegisterClass (&wClass); |
RegisterClass (&wClass); |
184 |
|
|
185 |
hWnd = CreateWindowEx( |
hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TOPMOST, |
186 |
WS_EX_TOOLWINDOW | WS_EX_TOPMOST, // extended style |
PD_WINDOWNAME, PD_WINDOWNAME, |
187 |
PD_WINDOWNAME, // class name |
WS_POPUP, |
188 |
PD_WINDOWNAME, // window name |
(parent.right + parent.left) / 2, |
189 |
WS_POPUP, // window style |
(parent.bottom + parent.top) / 2, |
190 |
(parent.right + parent.left) / 2, (parent.bottom + parent.top) / 2, |
nWndWidth - 2, nWndHeight - 2, |
191 |
nWndWidth - 2, nWndHeight - 2, // width and height, with corrections |
NULL, NULL, glob_hinst, NULL); |
|
NULL, NULL, glob_hinst, NULL); |
|
|
|
|
|
|
|
192 |
if (hWnd == NULL) |
if (hWnd == NULL) |
193 |
return 0; |
return 0; |
194 |
else { |
else { /* Ensure parent never loses focus. */ |
195 |
ShowWindow (hWnd, SW_SHOW); |
ShowWindow (hWnd, SW_SHOW); |
196 |
UpdateWindow (hWnd); |
UpdateWindow (hWnd); |
|
// ensure parent never loses focus |
|
197 |
EnableWindow (hParentWnd, TRUE); |
EnableWindow (hParentWnd, TRUE); |
198 |
center_window (hWnd, hParentWnd); |
center_window (hWnd, hParentWnd); |
199 |
SetActiveWindow (NULL); |
SetActiveWindow (NULL); |