ReactOS  0.4.13-dev-479-gec9c8fd
config.c
Go to the documentation of this file.
1 //
2 // config.c
3 //
4 // Screensaver Configuration dialog
5 //
6 #include <windows.h>
7 #include <commctrl.h>
8 #include <tchar.h>
9 #include "resource.h"
10 #include "globals.h"
11 #include "message.h"
12 #include "matrix.h"
13 
14 // needed for slider-controls
15 //#pragma comment(lib, "comctl32.lib")
16 
17 //
18 // Called once for every font - add to list
19 //
20 int CALLBACK EnumFontProc(ENUMLOGFONT *lpelfe, NEWTEXTMETRIC *lpntme, int FontType, LPARAM lParam)
21 {
23  return 1;
24 }
25 
26 //
27 // Add every fontname into specified combobox
28 //
29 void AddFonts(HWND hwndCombo)
30 {
31  HDC hdc;
32  LOGFONT lf;
33 
35  lf.lfPitchAndFamily = 0;
36  lf.lfFaceName[0] = _T('\0');
37 
38  hdc = GetDC(0);
40  ReleaseDC(0, hdc);
41 }
42 
43 //
44 // Redraw preview control with current font/fontsize
45 //
47 {
51 }
52 
53 //
54 // Dialogbox procedure for Configuration window
55 //
57 {
58  static TCHAR buf[256];
59  HWND hwndCombo, hwndCtrl;
60  int index, items, val;
61  RECT rect;
62  static int prevwidth, prevheight;
63 
64  switch(uMsg)
65  {
66  case WM_INITDIALOG:
67 
69  prevheight = GetSystemMetrics(SM_CYSCREEN) / GLYPH_HEIGHT + 1;
70 
71  //Add any saved messages to the combo box
72  for(index = 0; index < g_nNumMessages; index++)
73  {
74  if(lstrlen(g_szMessages[index]) > 0)
76  }
77 
78  //select the first message, and preview it
80 
85 
86  //SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_SETTICFREQ, 5, 0);
90 
95 
98 
103  return 0;
104 
105  case WM_DESTROY:
106  //DeInitMessage();
107  return 0;
108 
109  case WM_CTLCOLORSTATIC:
110 
112  {
113  SetTextColor((HDC)wParam, RGB(0,80,0));
116  }
117  else if(GetDlgCtrlID((HWND)lParam) == IDC_PREVIEW)
118  {
119  HDC hdc = (HDC)wParam;
120  RECT clip;
121 
123 
125 
126  if(prevwidth < rect.right)
127  {
128  rect.left = (rect.right-prevwidth) / 2;
129  rect.right = rect.left + prevwidth;
130  }
131  else
132  {
133  rect.left = 0;
134  rect.right = prevwidth;
135  }
136 
137  if(prevheight < rect.bottom)
138  {
139  rect.top = (rect.bottom-prevheight) / 2;
140  rect.bottom = rect.top + prevheight;
141  }
142  else
143  {
144  rect.top = 0;
145  rect.bottom = prevheight;
146  }
147 
148  SetTextColor(hdc, RGB(128,255,128));
149  SetBkColor(hdc, 0);
150 
151  //SetRect(&rect, 0, 0, PrevMessage->width, MAXMSG_HEIGHT);
152  CopyRect(&clip, &rect);
154 
156 
157  InflateRect(&clip, 2, 2);
158 
160  IntersectClipRect(hdc, rect.left, rect.top, rect.right, rect.bottom);
161 
162  // figure out where the bounding rectangle should be
164  OffsetRect(&rect, (prevwidth-(rect.right-rect.left))/2, (prevheight-(rect.bottom-rect.top))/2);
165 
166  // now draw it!
168 
169 
171  }
172  else
173  {
174  break;
175  }
176 
177  case WM_HSCROLL:
178 
180  {
181  // one of the sliders changed..update
183  }
184 
185  return 0;
186 
187  case WM_COMMAND:
188 
189  switch(HIWORD(wParam))
190  {
191  case CBN_EDITCHANGE:
192  case CBN_SELCHANGE:
193 
194  //fall through to Preview:
197  //SetMessageFont(hwnd, g_szFontName, g_nFontSize, TRUE);
198 
200  return 0;
201  }
202 
203  switch(LOWORD(wParam))
204  {
205  case IDC_RANDOM:
207  break;
208 
209  case IDC_BOLD:
212  break;
213 
214  case IDOK:
215 
216  hwndCtrl = GetDlgItem(hwnd, IDC_COMBO1);
217 
218  items = min(MAX_MESSAGES, SendMessage(hwndCtrl, CB_GETCOUNT, 0, 0));
219 
220  for(index = 0; index < items; index++)
221  {
223  }
224 
226 
227  //matrix speed
229  if(val >= SPEED_MIN && val <= SPEED_MAX)
231 
232  //density
234  if(val >= DENSITY_MIN && val <= DENSITY_MAX)
235  g_nDensity = val;
236 
237  //message speed
239  if(val >= MSGSPEED_MIN && val <= MSGSPEED_MAX)
241 
242  //font size
244  if(val >= FONT_MIN && val <= FONT_MAX)
245  g_nFontSize = val;
246 
247  SaveSettings();
248  EndDialog(hwnd, 0);
249  return 0;
250 
251  case IDCANCEL:
252  EndDialog(hwnd, 0);
253  return TRUE;
254 
255  case IDC_ADD:
256 
257  hwndCombo = GetDlgItem(hwnd, IDC_COMBO1);
258 
259  if(GetWindowText(hwndCombo, buf, 256))
260  {
261  SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)buf);
262  }
263 
265 
266  return 0;
267 
268  case IDC_REMOVE:
269  hwndCombo = GetDlgItem(hwnd, IDC_COMBO1);
270  GetWindowText(hwndCombo, buf, 256);
271 
272  index = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
273  SendMessage(hwndCombo, CB_DELETESTRING, index, 0);
274 
275  SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
277  return 0;
278  }
279  return 0;
280 
281  case WM_CLOSE:
282  EndDialog(hwnd, 0);
283  return 0;
284  }
285  return 0;
286 }
287 
288 //
289 // Display the configuration dialog
290 //
292 {
294 
296  icc.dwSize = sizeof(icc);
297 
298  InitCommonControlsEx(&icc);
299 
300 #ifdef _DEBUG
301  if(hwndParent == NULL)
302  hwndParent = 0;
303 #else
304  if(hwndParent == NULL)
306 #endif
307 
309 
310  return 0;
311 }
312 
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DENSITY_MAX
Definition: globals.h:11
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define MSGSPEED_MAX
Definition: globals.h:27
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define MAX_MESSAGES
Definition: globals.h:30
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
HDC WINAPI GetDC(_In_opt_ HWND)
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CB_GETLBTEXT
Definition: winuser.h:1913
TCHAR g_szMessages[MAX_MESSAGES][MAXMSG_LENGTH]
Definition: settings.c:13
#define IDC_REMOVE
Definition: resource.h:18
#define NULL_BRUSH
Definition: wingdi.h:900
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1748
#define DT_WORDBREAK
Definition: winuser.h:544
#define IDC_SLIDER1
Definition: resource.h:15
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
#define TBM_SETRANGE
Definition: commctrl.h:2009
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define SPEED_MIN
Definition: globals.h:21
int g_nNumMessages
Definition: settings.c:14
#define TBM_SETPOS
Definition: commctrl.h:2008
BYTE lfCharSet
Definition: dimm.idl:50
UINT_PTR WPARAM
Definition: windef.h:207
#define IDC_SLIDER4
Definition: resource.h:18
#define SendDlgItemMessage
Definition: winuser.h:5708
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_SLIDER3
Definition: resource.h:17
#define IDC_COMBO1
Definition: resource.h:8
#define CB_GETCURSEL
Definition: winuser.h:1904
DWORD WINAPI GetSysColor(_In_ int)
& rect
Definition: startmenu.cpp:1413
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define COLOR_3DSHADOW
Definition: winuser.h:921
#define DrawText
Definition: winuser.h:5637
#define GetWindowText
Definition: winuser.h:5664
TCHAR g_szFontName[]
Definition: settings.c:16
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
void SaveSettings(void)
Definition: settings.c:113
#define GLYPH_WIDTH
Definition: globals.h:17
int WINAPI GetDlgCtrlID(_In_ HWND)
#define IDC_COMBO2
Definition: resource.h:20
#define DialogBox
Definition: winuser.h:5627
#define SM_CXSCREEN
Definition: winuser.h:949
#define COLOR_3DFACE
Definition: winuser.h:919
#define DT_CALCRECT
Definition: winuser.h:526
#define IDD_CONFIG
Definition: resource.h:4
#define ICC_UPDOWN_CLASS
Definition: commctrl.h:62
#define TBM_GETPOS
Definition: commctrl.h:2003
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define SPEED_MAX
Definition: globals.h:20
#define CB_ADDSTRING
Definition: winuser.h:1897
#define MAKELONG(a, b)
Definition: typedefs.h:248
smooth NULL
Definition: ftsmooth.c:416
static HWND hwndParent
Definition: cryptui.c:300
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_ADD
Definition: resource.h:16
GLuint index
Definition: glext.h:6031
BYTE lfPitchAndFamily
Definition: dimm.idl:54
#define DT_VCENTER
Definition: winuser.h:543
#define TBM_SETTICFREQ
Definition: commctrl.h:2022
#define IDC_BOLD
Definition: resource.h:19
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
int g_nMessageSpeed
Definition: settings.c:15
#define WM_DESTROY
Definition: winuser.h:1591
GLuint GLfloat * val
Definition: glext.h:7180
#define BLACK_BRUSH
Definition: wingdi.h:895
char TCHAR
Definition: xmlstorage.h:189
#define SM_CYSCREEN
Definition: winuser.h:950
#define ICC_BAR_CLASSES
Definition: commctrl.h:60
int Configure(HWND hwndParent)
Definition: config.c:291
#define _T(x)
Definition: vfdio.h:22
#define FONT_MIN
Definition: globals.h:32
#define GetDlgItemText
Definition: winuser.h:5651
#define CBN_EDITCHANGE
Definition: winuser.h:1936
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
int g_nFontSize
Definition: settings.c:20
#define WM_CLOSE
Definition: winuser.h:1603
#define IDC_SLIDER2
Definition: resource.h:16
#define RGB(r, g, b)
Definition: wingdi.h:2918
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
int WINAPI GetSystemMetrics(_In_ int)
BOOL g_fFontBold
Definition: settings.c:22
#define FONT_MAX
Definition: globals.h:33
BOOL g_fRandomizeMessages
Definition: settings.c:21
#define index(s, c)
Definition: various.h:29
HDC hdc
Definition: main.c:9
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define IDC_RANDOM
Definition: resource.h:14
#define CB_SETCURSEL
Definition: winuser.h:1922
LOGFONTA elfLogFont
Definition: wingdi.h:2664
#define WM_COMMAND
Definition: winuser.h:1716
#define IDC_PREVIEW
Definition: wordpad.h:171
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:886
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define lstrlen
Definition: winbase.h:3690
void AddFonts(HWND hwndCombo)
Definition: config.c:29
#define GetModuleHandle
Definition: winbase.h:3641
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define WM_HSCROLL
Definition: winuser.h:1719
void SetMessageFont(HWND hwnd, TCHAR *szFontName, int nPointSize, BOOL fBold)
Definition: message.c:201
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
#define EnumFontFamiliesEx
Definition: wingdi.h:4429
#define CBN_SELCHANGE
Definition: winuser.h:1940
HFONT g_hFont
Definition: settings.c:25
int g_nMatrixSpeed
Definition: settings.c:18
FONTENUMPROCA FONTENUMPROC
Definition: wingdi.h:2880
#define SendMessage
Definition: winuser.h:5709
INT_PTR CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: config.c:56
BOOL WINAPI CopyRect(_Out_ LPRECT, _In_ LPCRECT)
#define HIWORD(l)
Definition: typedefs.h:246
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
#define DT_CENTER
Definition: winuser.h:527
#define CB_GETCOUNT
Definition: winuser.h:1903
#define ANSI_CHARSET
Definition: wingdi.h:382
#define CB_DELETESTRING
Definition: winuser.h:1898
#define IDCANCEL
Definition: winuser.h:825
static TCHAR * items[]
Definition: page1.c:45
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define MSGSPEED_MIN
Definition: globals.h:28
#define DENSITY_MIN
Definition: globals.h:12
#define GLYPH_HEIGHT
Definition: globals.h:18
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define CB_FINDSTRING
Definition: winuser.h:1900
#define IDC_ABOUT
Definition: resource.h:29
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
int g_nDensity
Definition: settings.c:19
int CALLBACK EnumFontProc(ENUMLOGFONT *lpelfe, NEWTEXTMETRIC *lpntme, int FontType, LPARAM lParam)
Definition: config.c:20
int WINAPI FrameRect(_In_ HDC, _In_ LPCRECT, _In_ HBRUSH)
void UpdatePreview(HWND hwnd)
Definition: config.c:46