4 // Screensaver Configuration dialog
14 // needed for slider-controls
15 //#pragma comment(lib, "comctl32.lib")
18 // Called once for every font - add to list
20 int CALLBACK
EnumFontProc(ENUMLOGFONT
*lpelfe
, NEWTEXTMETRIC
*lpntme
, int FontType
, LPARAM lParam
)
22 SendMessage((HWND
)lParam
, CB_ADDSTRING
, 0, (LPARAM
)lpelfe
->elfLogFont
.lfFaceName
);
27 // Add every fontname into specified combobox
29 void AddFonts(HWND hwndCombo
)
34 lf
.lfCharSet
= ANSI_CHARSET
;
35 lf
.lfPitchAndFamily
= 0;
36 lf
.lfFaceName
[0] = _T('\0');
39 EnumFontFamiliesEx(hdc
, &lf
, (FONTENUMPROC
)EnumFontProc
, (LONG
)hwndCombo
, 0);
44 // Redraw preview control with current font/fontsize
46 void UpdatePreview(HWND hwnd
)
48 g_nFontSize
= SendDlgItemMessage(hwnd
, IDC_SLIDER4
, TBM_GETPOS
,0, 0);
49 SetMessageFont(hwnd
, g_szFontName
, g_nFontSize
, g_fFontBold
);
50 InvalidateRect(GetDlgItem(hwnd
, IDC_PREVIEW
), 0, 0);
54 // Dialogbox procedure for Configuration window
56 BOOL CALLBACK
ConfigDlgProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
58 static TCHAR buf
[256];
59 HWND hwndCombo
, hwndCtrl
;
60 int index
, items
, val
;
62 static int prevwidth
, prevheight
;
68 prevwidth
= GetSystemMetrics(SM_CXSCREEN
) / GLYPH_WIDTH
;
69 prevheight
= GetSystemMetrics(SM_CYSCREEN
) / GLYPH_HEIGHT
+ 1;
71 //Add any saved messages to the combo box
72 for(index
= 0; index
< g_nNumMessages
; index
++)
74 if(lstrlen(g_szMessages
[index
]) > 0)
75 SendDlgItemMessage(hwnd
, IDC_COMBO1
, CB_ADDSTRING
, 0, (LPARAM
)g_szMessages
[index
]);
78 //select the first message, and preview it
79 SendDlgItemMessage(hwnd
, IDC_COMBO1
, CB_SETCURSEL
, 0, 0);
81 SendDlgItemMessage(hwnd
, IDC_SLIDER1
, TBM_SETRANGE
, 0, MAKELONG(SPEED_MIN
, SPEED_MAX
));
82 SendDlgItemMessage(hwnd
, IDC_SLIDER2
, TBM_SETRANGE
, 0, MAKELONG(DENSITY_MIN
, DENSITY_MAX
));
83 SendDlgItemMessage(hwnd
, IDC_SLIDER3
, TBM_SETRANGE
, 0, MAKELONG(MSGSPEED_MIN
, MSGSPEED_MAX
));
84 SendDlgItemMessage(hwnd
, IDC_SLIDER4
, TBM_SETRANGE
, 0, MAKELONG(FONT_MIN
, FONT_MAX
));
86 //SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_SETTICFREQ, 5, 0);
87 SendDlgItemMessage(hwnd
, IDC_SLIDER2
, TBM_SETTICFREQ
, 5, 0);
88 SendDlgItemMessage(hwnd
, IDC_SLIDER3
, TBM_SETTICFREQ
, 50, 0);
89 SendDlgItemMessage(hwnd
, IDC_SLIDER4
, TBM_SETTICFREQ
, 2, 0);
91 SendDlgItemMessage(hwnd
, IDC_SLIDER1
, TBM_SETPOS
, TRUE
, g_nMatrixSpeed
);
92 SendDlgItemMessage(hwnd
, IDC_SLIDER2
, TBM_SETPOS
, TRUE
, g_nDensity
);
93 SendDlgItemMessage(hwnd
, IDC_SLIDER3
, TBM_SETPOS
, TRUE
, g_nMessageSpeed
);
94 SendDlgItemMessage(hwnd
, IDC_SLIDER4
, TBM_SETPOS
, TRUE
, g_nFontSize
);
96 CheckDlgButton(hwnd
, IDC_RANDOM
, g_fRandomizeMessages
);
97 CheckDlgButton(hwnd
, IDC_BOLD
, g_fFontBold
);
99 AddFonts(GetDlgItem(hwnd
, IDC_COMBO2
));
100 index
= SendDlgItemMessage(hwnd
, IDC_COMBO2
, CB_FINDSTRING
, 0, (LPARAM
)g_szFontName
);
101 SendDlgItemMessage(hwnd
, IDC_COMBO2
, CB_SETCURSEL
, index
, 0);
109 case WM_CTLCOLORSTATIC
:
111 if(GetDlgCtrlID((HWND
)lParam
) == IDC_ABOUT
)
113 SetTextColor((HDC
)wParam
, RGB(0,80,0));
114 SetBkColor((HDC
)wParam
, GetSysColor(COLOR_3DFACE
));
115 return (BOOL
)GetSysColorBrush(COLOR_3DFACE
);
117 else if(GetDlgCtrlID((HWND
)lParam
) == IDC_PREVIEW
)
119 HDC hdc
= (HDC
)wParam
;
122 GetDlgItemText(hwnd
, IDC_COMBO1
, buf
, 256);
124 GetClientRect((HWND
)lParam
, &rect
);
126 if(prevwidth
< rect
.right
)
128 rect
.left
= (rect
.right
-prevwidth
) / 2;
129 rect
.right
= rect
.left
+ prevwidth
;
134 rect
.right
= prevwidth
;
137 if(prevheight
< rect
.bottom
)
139 rect
.top
= (rect
.bottom
-prevheight
) / 2;
140 rect
.bottom
= rect
.top
+ prevheight
;
145 rect
.bottom
= prevheight
;
148 SetTextColor(hdc
, RGB(128,255,128));
151 //SetRect(&rect, 0, 0, PrevMessage->width, MAXMSG_HEIGHT);
152 CopyRect(&clip
, &rect
);
153 FillRect(hdc
, &rect
, GetStockObject(BLACK_BRUSH
));
155 SelectObject(hdc
, g_hFont
);
157 InflateRect(&clip
, 2, 2);
159 FrameRect(hdc
, &clip
, GetSysColorBrush(COLOR_3DSHADOW
));
160 IntersectClipRect(hdc
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
162 // figure out where the bounding rectangle should be
163 DrawText(hdc
, buf
, -1, &rect
, DT_CENTER
|DT_VCENTER
|DT_WORDBREAK
|DT_CALCRECT
);
164 OffsetRect(&rect
, (prevwidth
-(rect
.right
-rect
.left
))/2, (prevheight
-(rect
.bottom
-rect
.top
))/2);
167 DrawText(hdc
, buf
, -1, &rect
, DT_CENTER
|DT_VCENTER
|DT_WORDBREAK
);
170 return (BOOL
)GetStockObject(NULL_BRUSH
);
179 if((HWND
)lParam
== GetDlgItem(hwnd
, IDC_SLIDER4
))
181 // one of the sliders changed..update
189 switch(HIWORD(wParam
))
194 //fall through to Preview:
195 index
= SendDlgItemMessage(hwnd
, IDC_COMBO2
, CB_GETCURSEL
, 0, 0);
196 SendDlgItemMessage(hwnd
, IDC_COMBO2
, CB_GETLBTEXT
, index
, (LPARAM
)g_szFontName
);
197 //SetMessageFont(hwnd, g_szFontName, g_nFontSize, TRUE);
203 switch(LOWORD(wParam
))
206 g_fRandomizeMessages
= IsDlgButtonChecked(hwnd
, IDC_RANDOM
);
210 g_fFontBold
= IsDlgButtonChecked(hwnd
, IDC_BOLD
);
216 hwndCtrl
= GetDlgItem(hwnd
, IDC_COMBO1
);
218 items
= min(MAX_MESSAGES
, SendMessage(hwndCtrl
, CB_GETCOUNT
, 0, 0));
220 for(index
= 0; index
< items
; index
++)
222 SendMessage(hwndCtrl
, CB_GETLBTEXT
, index
, (LPARAM
)g_szMessages
[index
]);
225 g_nNumMessages
= items
;
228 val
= SendDlgItemMessage(hwnd
, IDC_SLIDER1
, TBM_GETPOS
, 0, 0);
229 if(val
>= SPEED_MIN
&& val
<= SPEED_MAX
)
230 g_nMatrixSpeed
= val
;
233 val
= SendDlgItemMessage(hwnd
, IDC_SLIDER2
, TBM_GETPOS
, 0, 0);
234 if(val
>= DENSITY_MIN
&& val
<= DENSITY_MAX
)
238 val
= SendDlgItemMessage(hwnd
, IDC_SLIDER3
, TBM_GETPOS
, 0, 0);
239 if(val
>= MSGSPEED_MIN
&& val
<= MSGSPEED_MAX
)
240 g_nMessageSpeed
= val
;
243 val
= SendDlgItemMessage(hwnd
, IDC_SLIDER4
, TBM_GETPOS
, 0, 0);
244 if(val
>= FONT_MIN
&& val
<= FONT_MAX
)
257 hwndCombo
= GetDlgItem(hwnd
, IDC_COMBO1
);
259 if(GetWindowText(hwndCombo
, buf
, 256))
261 SendMessage(hwndCombo
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
269 hwndCombo
= GetDlgItem(hwnd
, IDC_COMBO1
);
270 GetWindowText(hwndCombo
, buf
, 256);
272 index
= SendMessage(hwndCombo
, CB_GETCURSEL
, 0, 0);
273 SendMessage(hwndCombo
, CB_DELETESTRING
, index
, 0);
275 SendMessage(hwndCombo
, CB_SETCURSEL
, 0, 0);
289 // Display the configuration dialog
291 int Configure(HWND hwndParent
)
293 INITCOMMONCONTROLSEX icc
;
295 icc
.dwICC
= ICC_UPDOWN_CLASS
| ICC_BAR_CLASSES
;
296 icc
.dwSize
= sizeof(icc
);
298 InitCommonControlsEx(&icc
);
301 if(hwndParent
== NULL
)
304 if(hwndParent
== NULL
)
305 hwndParent
= GetForegroundWindow();
308 DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_CONFIG
), hwndParent
, ConfigDlgProc
);