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