fixed code to compile both as ansi and unicode version, build as unicode by default
[reactos.git] / reactos / subsys / system / calc / stats.c
1 /*
2 * WineCalc (stats.c)
3 *
4 * Copyright 2003 James Briggs
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdio.h> // sprintf
22
23 #include <windows.h>
24 #include <tchar.h>
25
26 #include "stats.h"
27 #include "resource.h"
28 #include "winecalc.h"
29
30 HWND hWndListBox;
31
32 extern CALC calc;
33 extern HWND hWndDlgStats;
34
35 BOOL CALLBACK StatsDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
36 {
37 HDC hdc;
38 PAINTSTRUCT ps;
39
40
41 switch( uMsg ) {
42
43 case WM_INITDIALOG:
44 hWndListBox = CreateWindow(
45 TEXT("LISTBOX"), // pointer to registered class name
46 TEXT("Listbox"), // pointer to window name
47 WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_NOINTEGRALHEIGHT, // window style
48 6, // horizontal position of window
49 6, // vertical position of window
50 208, // window width
51 66, // window height
52 hDlg, // handle to parent or owner window
53 NULL, // handle to menu or child-window identifier
54 NULL, // handle to application instance
55 NULL // pointer to window-creation data
56 );
57
58 ShowWindow(hWndListBox, SW_SHOW);
59
60 SendMessage (hWndListBox, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), TRUE);
61
62 // SetFocus(hWndDlgStats);
63
64 return TRUE;
65
66 case WM_COMMAND:
67 switch( LOWORD( wParam ) ) {
68
69 case ID_STATS_RET:
70 SetFocus(GetParent(hDlg));
71 return 0;
72
73 case ID_STATS_LOAD:
74 {
75 int i;
76
77 i = SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);
78 SendMessage(hWndListBox, LB_GETTEXT, i, (LPARAM)calc.buffer);
79 calc_buffer_display(&calc);
80 }
81 return 0;
82
83 case ID_STATS_CD:
84 {
85 int i;
86
87 i = SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);
88 SendMessage(hWndListBox, LB_DELETESTRING, i, 0);
89 InvalidateRect(hDlg,NULL,TRUE);
90 UpdateWindow(hDlg);
91 }
92 return 0;
93
94 case ID_STATS_CAD:
95 SendMessage(hWndListBox, LB_RESETCONTENT, 0, 0);
96 InvalidateRect(hDlg,NULL,TRUE);
97 UpdateWindow(hDlg);
98 return 0;
99 }
100 break;
101
102 case WM_PAINT:
103 {
104 TCHAR s[CALC_BUF_SIZE];
105 int lb_count;
106 HFONT hFont;
107 HFONT hFontOrg;
108
109 hdc = BeginPaint( hDlg, &ps );
110 hFont = GetStockObject(DEFAULT_GUI_FONT);
111 hFontOrg = SelectObject(hdc, hFont);
112
113 lb_count = SendMessage(hWndListBox, LB_GETCOUNT, 0, 0);
114 _stprintf(s, TEXT("n=%d"), lb_count);
115
116 SetBkMode(hdc, TRANSPARENT);
117 TextOut(hdc, 98, 121, s, _tcslen(s));
118 SelectObject(hdc, hFontOrg);
119 EndPaint( hDlg, &ps );
120
121 return 0;
122 }
123 case WM_CLOSE:
124 hWndDlgStats = 0; // invalidate stats dialog
125 SendMessage(GetParent(hDlg), WM_CHAR, TEXT('\x13'), 1); // disable stats related calculator buttons
126 DestroyWindow( hDlg );
127
128 return 0;
129 }
130 return FALSE;
131 }
132