|
|
1.1 root 1: /**************************************************************************\
2: * getsys.c -- sample program demonstrating the GetSys... APIs
3: *
1.1.1.2 ! root 4: * Steve Firebaugh
! 5: * Microsoft Developer Support
! 6: * Copyright (c) 1992 Microsoft Corporation
! 7: *
1.1 root 8: * In this sample the main window is a dialog box. There is no need to
9: * register a new window class or create a new window. Instead just call
10: * DialogBox() and use the template defined in the .RC file. All of the
11: * interesting code is thus in the window procedure for the dialog box.
12: * In this case, simply respond to the button command messsages and fill
13: * the list box with appropriate values.
14: *
15: * The dialog template currently specifies a "monospaced font." This makes
16: * the dialog look somewhat odd, but makes text formatting much easier. If
17: * the specified font does not exist on the system running this sample, the
18: * program will work fine, but the contents of the listbox will not look
19: * very good.
20: *
21: \**************************************************************************/
22:
23: #include <windows.h>
24: #include "getsys.h"
25:
26:
27: /**************************************************************************\
28: *
29: * function: WinMain()
30: *
31: * input parameters: c.f. generic sample
32: *
33: \**************************************************************************/
34: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
35: LPSTR lpCmdLine, int nCmdShow)
36: {
37: int ret;
38:
39: UNREFERENCED_PARAMETER( hPrevInstance );
40: UNREFERENCED_PARAMETER( lpCmdLine );
41: UNREFERENCED_PARAMETER( nCmdShow);
42:
43: ret = DialogBox (hInstance, "getsysDlg", NULL, (DLGPROC)MainDlgProc);
44: return ret;
45: }
46:
47:
48:
49: /**************************************************************************\
50: *
51: * function: MainDlgProc()
52: *
53: * input parameters: standard window procedure parameters.
54: *
55: \**************************************************************************/
1.1.1.2 ! root 56: LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1 root 57: {
58: UNREFERENCED_PARAMETER(lParam);
59:
60:
61: switch (message) {
62:
63: /********************************************************************\
64: * WM_SYSCOMMAND
65: *
66: * ignore all syscommand messages, except for SC_CLOSE.
67: * on this one, call EndDialog().
68: \********************************************************************/
69: case WM_SYSCOMMAND:
70: if (wParam == SC_CLOSE) {
71: EndDialog (hwnd, TRUE);
72: return TRUE;
73: } else
74: return FALSE;
75: break;
76:
77:
78: /********************************************************************\
79: * WM_COMMAND
80: *
81: * When the different buttons are hit, clear the list box, disable
82: * updating to it, call the function which will fill it, reenable
83: * updating, and then force a repaint.
84: *
85: \********************************************************************/
86: case WM_COMMAND:
87:
88: /* if the list box sends back messages, return. Otherwise we will
89: * clear it out, and that is not what we want to do at this point.
90: */
91: if (LOWORD(wParam)==DID_LISTBOX) return TRUE;
92:
93: SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, FALSE, 0);
94: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0, 0);
95:
96: /* switch on the control ID of the button that is pressed. */
97: switch (LOWORD(wParam)) {
98: case DID_SYSCOLORS : doSysColors (hwnd); break;
99: case DID_DIRECTORY : doDirectory (hwnd); break;
100: case DID_INFO : doInfo (hwnd); break;
101: case DID_METRICS : doMetrics (hwnd); break;
102: case DID_PALETTE : doPalette (hwnd); break;
103: case DID_TIME : doTime (hwnd); break;
104: } /* end switch (LOWORD()) */
105:
106: SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
107: InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
108: return TRUE;
109: break; /* end WM_COMMAND */
110:
111:
112: default: return FALSE;
113: } /* end switch(message) */
114: }
115:
116:
117:
118:
119:
120:
121: /**************************************************************************\
122: *
123: * functions: do...()
124: *
125: * In all of the functions that follow, first set the text int the static
126: * text field to label the contents of the list box. Then, query the
127: * desired system information, format it into strings, and add those strings
128: * to the listbox.
129: *
130: * input parameters: HWND - window handle for the dialog box.
131: * global variables: buffer - array of char's to hold string w/ info.
132: *
133: \**************************************************************************/
134:
135: VOID doSysColors (HWND hwnd)
136: {
137: int i;
138: DWORD answer;
139:
140: SetDlgItemText (hwnd, DID_TEXT, "System Colors");
141:
142: for (i = 0; i<NSYSCOLORS; i++) {
143:
144: /*******************************************************/
145: /*******************************************************/
146: answer = GetSysColor (SysColors[i].Value);
147: /*******************************************************/
148: /*******************************************************/
149:
150: wsprintf (buffer, SysColors[i].String, (int)answer);
151: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
152: }
153: return;
154: }
155:
156:
157:
158: VOID doDirectory (HWND hwnd)
159: {
160: char buffer[MAX_PATH];
161:
162: SetDlgItemText (hwnd, DID_TEXT, "System Directory");
163:
164: /*******************************************************/
165: /*******************************************************/
166: GetSystemDirectory (buffer, MAX_PATH);
167: /*******************************************************/
168: /*******************************************************/
169:
170: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
171:
172: return;
173: }
174:
175:
176: VOID doInfo(HWND hwnd)
177: {
178: SYSTEM_INFO si;
179:
180: SetDlgItemText (hwnd, DID_TEXT, "SYSTEM_INFO");
181:
182: /*******************************************************/
183: /*******************************************************/
184: GetSystemInfo (&si);
185: /*******************************************************/
186: /*******************************************************/
187:
188: wsprintf (buffer, "dwOemId \t%d", (int) si.dwOemId );
189: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
190: wsprintf (buffer, "dwPageSize \t%d", (int) si.dwPageSize );
191: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
192: wsprintf (buffer, "lpMinimumApplicationAddress \t%08lx", (LONG)si.lpMinimumApplicationAddress );
193: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
194: wsprintf (buffer, "lpMaximumApplicationAddress \t%08lx", (LONG)si.lpMaximumApplicationAddress );
195: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
196: wsprintf (buffer, "dwActiveProcessorMask \t%d", (int) si.dwActiveProcessorMask );
197: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
198: wsprintf (buffer, "dwNumberOfProcessors \t%d", (int) si.dwNumberOfProcessors );
199: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
200: wsprintf (buffer, "dwProcessorType \t%d", (int) si.dwProcessorType );
201: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
1.1.1.2 ! root 202: wsprintf (buffer, "dwReserved1 \t%d", (int) si.dwReserved1 );
1.1 root 203: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
1.1.1.2 ! root 204: wsprintf (buffer, "dwReserved2 \t%d", (int) si.dwReserved2 );
1.1 root 205: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
206:
207: return;
208: }
209:
210:
211:
212: VOID doMetrics (HWND hwnd)
213: {
214: int i;
215: int answer;
216:
217: SetDlgItemText (hwnd, DID_TEXT, "System Metrics");
218:
219: for (i = 0; i<NSYSMETRICS; i++) {
220:
221: /*******************************************************/
222: /*******************************************************/
223: answer = GetSystemMetrics (SystemMetrics[i].Value);
224: /*******************************************************/
225: /*******************************************************/
226:
227: wsprintf (buffer, SystemMetrics[i].String, (int)answer);
228: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
229: }
230:
231: return;
232: }
233:
234:
235:
236: VOID doPalette(HWND hwnd)
237: {
238: int nEntries;
239: HDC hdc;
240: int i;
241: LPPALETTEENTRY lpp;
242:
243: SetDlgItemText (hwnd, DID_TEXT, "System Palette");
244:
245: /* this function is slightly different because the amount of information
246: * is not known until run time. First find the number of entries in the
247: * palette (16 for VGA, but 256 for 8514, ...), then allocate enough
248: * space to hold all of them, query the information, put it in the list
249: * box, and then free up the memory allocated.
250: */
251: hdc = GetDC (hwnd);
252: nEntries = GetSystemPaletteEntries (hdc, 0,0, NULL);
253: lpp = (LPPALETTEENTRY)LocalAlloc (LPTR,
254: (DWORD) (nEntries* sizeof (PALETTEENTRY)));
255:
256: if (lpp == NULL) {
257: MessageBox (hwnd, "Memory allocation failed.", "Warning", MB_ICONSTOP | MB_OK);
258: return;
259: }
260:
261: /*******************************************************/
262: /*******************************************************/
263: nEntries = GetSystemPaletteEntries (hdc, 0,nEntries, lpp);
264: /*******************************************************/
265: /*******************************************************/
266:
267: ReleaseDC (hwnd, hdc);
268:
269: for (i = 0; i<nEntries; i++) {
270: wsprintf (buffer, "%d) \t%x \t%x \t%x \t%x", i,
271: lpp[i].peRed, lpp[i].peGreen, lpp[i].peBlue, lpp[i].peFlags);
272: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
273: }
274:
275: LocalFree (LocalHandle ((LPSTR)lpp));
276: return;
277: }
278:
279:
280:
281:
282: VOID doTime (HWND hwnd)
283: {
284: SYSTEMTIME st;
285:
286: SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");
287:
288: /*******************************************************/
289: /*******************************************************/
290: GetSystemTime (&st);
291: /*******************************************************/
292: /*******************************************************/
293:
294: wsprintf (buffer, "wYear \t%d", (int)st.wYear );
295: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
296: wsprintf (buffer, "wMonth \t%d", (int)st.wMonth );
297: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
298: wsprintf (buffer, "wDayOfWeek \t%d", (int)st.wDayOfWeek );
299: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
300: wsprintf (buffer, "wDay \t%d", (int)st.wDay );
301: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
302: wsprintf (buffer, "wHour \t%d", (int)st.wHour );
303: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
304: wsprintf (buffer, "wMinute \t%d", (int)st.wMinute );
305: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
306: wsprintf (buffer, "wSecond \t%d", (int)st.wSecond );
307: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
308: wsprintf (buffer, "wMilliseconds \t%d", (int)st.wMilliseconds );
309: SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
310: return;
311: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.