Annotation of mstools/samples/congui/gui.c, revision 1.1.1.1

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: // GUI.C
                     13: // ================================================================
                     14: // This module contains all of the functions that interface to the
                     15: // 'graphical' part of this program. This currently only relates to
                     16: // the code that brings up the dialog box, and calls the WinHelp
                     17: // engine.
                     18: 
                     19: #include <stdio.h>
                     20: #include <string.h>
                     21: #include <ctype.h>
                     22: #include <windows.h>
                     23: #include "ConGUI.h"
                     24: 
                     25: int DoHelp (char *szHelpTopic);
                     26: int GetDialogArgs (char ***pargv);
                     27: BOOL CenterWindow (HWND hwnd);
                     28: BOOL APIENTRY CLDlgProc (HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
                     29: 
                     30: 
                     31: // Use WINHELP to bring up the applicaiton help file
                     32: int DoHelp (char *szHelpTopic)
                     33: {
                     34:     WinHelp (GetFocus(), "ConGUI.HLP", HELP_KEY, (DWORD)(LPSTR)szHelpTopic);
                     35:     return TRUE;
                     36: }
                     37: 
                     38: 
                     39: // Bring up the dialog box, and pass back a 'command line' as was
                     40: // specified by the user
                     41: int GetDialogArgs (char ***pargv)
                     42: {
                     43:     int ret;
                     44:     HANDLE hinst;
                     45:     HWND hwnd;
                     46:     char szFile[80];
                     47: 
                     48:     hinst = GetModuleHandle (NULL);
                     49:     hwnd = GetFocus();
                     50: 
                     51:     ret = DialogBoxParam (hinst, "CL", NULL, CLDlgProc, (LPARAM)pargv);
                     52: 
                     53:     if (-1 == ret) {
                     54:         ret = GetLastError();
                     55:         printf ("Unable to create dialog: %d\n", ret);
                     56:         GetModuleFileName (hinst, szFile, sizeof(szFile));
                     57:         printf ("hinst = %d\n", hinst);
                     58:         printf ("hwnd = %d\n", hwnd);
                     59:         printf ("File = %s\n", szFile);
                     60:         return FALSE;
                     61: 
                     62:     }
                     63:     return ret;
                     64: }
                     65: 
                     66: // A quick little routine that will center a window on the screen.
                     67: // Handy for dialog boxes
                     68: BOOL CenterWindow (HWND hwnd)
                     69: {
                     70:     RECT    rect;
                     71:     int     w, h;
                     72:     int     wScreen, hScreen, xNew, yNew;
                     73:     HDC     hdc;
                     74: 
                     75:     GetWindowRect (hwnd, &rect);
                     76:     w = rect.right - rect.left;
                     77:     h = rect.bottom - rect.top;
                     78: 
                     79:     hdc = GetDC (hwnd);
                     80:     wScreen = GetDeviceCaps (hdc, HORZRES);
                     81:     hScreen = GetDeviceCaps (hdc, VERTRES);
                     82:     ReleaseDC (hwnd, hdc);
                     83: 
                     84:     xNew = wScreen/2 - w/2;
                     85:     yNew = hScreen/2 - h/2;
                     86: 
                     87:     return SetWindowPos (hwnd, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
                     88: }
                     89: 
                     90: 
                     91: // Create a data structure that will hold the strings for the combo boxes
                     92: // we have in our dialog. This just illustrates 'a' way to do this, not
                     93: // necessarily the best.
                     94: 
                     95: typedef struct tagDlgCtrls {
                     96:     int ctrlId;
                     97:     int def;
                     98:     char str[25];
                     99:     char opt[5];
                    100: } DlgCtrls;
                    101: 
                    102: DlgCtrls dlgctrls[] = {
                    103:     { 415, FALSE, "DOS EXE", "..." },
                    104:     { 415, FALSE, "Windows 3.0 EXE", "..."  },
                    105:     { 415, FALSE, "Windows 3.0 DLL", "..."  },
                    106:     { 415, FALSE, "Windows 3.1 EXE", "..."  },
                    107:     { 415, FALSE, "Windows 3.1 DLL", "..."  },
                    108:     { 415, TRUE,  "Windows NT EXE", "..."  },
                    109:     { 415, FALSE, "Windows NT DLL", "..."  },
                    110:     { 415, FALSE, "Windows NT Console App", "..."  },
                    111: 
                    112:     { 402, FALSE, "Small", "AS" },
                    113:     { 402, FALSE, "Medium", "AM" },
                    114:     { 402, FALSE, "Compact", "AC" },
                    115:     { 402, TRUE,  "Large", "AL" },
                    116:     { 402, FALSE, "Huge", "AH" },
                    117:     { 402, FALSE, "Customize", "A?" },
                    118: 
                    119:     { 404, FALSE, "8086", "G0" },
                    120:     { 404, FALSE, "80186", "G1" },
                    121:     { 404, TRUE,  "80286", "G2" },
                    122:     { 404, FALSE, "80386", "G3" },
                    123:     { 404, FALSE, "80486", "G4" },
                    124: 
                    125:     { 406, TRUE,  "stdcall", "Gz" },
                    126:     { 406, FALSE, "Pascal", "Gc" },
                    127:     { 406, FALSE, "C", "Gd" },
                    128: 
                    129:     { 408, FALSE, "Level 0", "W0" },
                    130:     { 408, FALSE, "Level 1", "W1" },
                    131:     { 408, FALSE, "Level 2", "W2" },
                    132:     { 408, TRUE,  "Level 3", "W3" },
                    133:     { 408, FALSE, "Level 4", "W4" },
                    134: 
                    135:     { 411, FALSE, "None", "" },
                    136:     { 411, FALSE, "Line Numbers Only", "Zd" },
                    137:     { 411, TRUE,  "Full Information", "Zi" },
                    138: 
                    139:     { 418, FALSE, "Ansi C", "Za" },
                    140:     { 418, TRUE, "MS Extensions", "Ze" },
                    141: 
                    142:     { 413, FALSE, "None", "" },
                    143:     { 413, TRUE,  "Protect Mode App", "GA" },
                    144:     { 413, FALSE, "Protect Mode DLL", "GD" },
                    145: 
                    146:     { 0, 0}  // End Of List
                    147: };
                    148: 
                    149: 
                    150: BOOL APIENTRY CLDlgProc (HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    151: {
                    152:     int wmId;
                    153:     static char ***pargv;
                    154:     static char **argv;
                    155: 
                    156:     int i, item, index, iCtrl, argc;
                    157:     char *cmd;
                    158:     char *cmdline;
                    159: 
                    160:     switch (msg) {
                    161:         case WM_INITDIALOG:
                    162:             // We need to initialize stuff in the dialog box...
                    163: 
                    164:             pargv = (char ***)lParam;
                    165:             argv = *pargv;
                    166:             CenterWindow (hdlg);
                    167: 
                    168:             iCtrl = i = 0;
                    169:             while (dlgctrls[i].ctrlId) {
                    170:                 if (dlgctrls[i].ctrlId != iCtrl) { // Starting a new list
                    171:                     iCtrl = dlgctrls[i].ctrlId;
                    172:                 }
                    173:                 index = SendDlgItemMessage (hdlg, iCtrl, CB_ADDSTRING, 0, (DWORD)(LPSTR)dlgctrls[i].str);
                    174:                 SendDlgItemMessage (hdlg, iCtrl, CB_SETITEMDATA, index, i);
                    175:                 if (dlgctrls[i].def) {
                    176:                     SendDlgItemMessage (hdlg, dlgctrls[i].ctrlId, CB_SETCURSEL, index, 0);
                    177:                 }
                    178:                 i++;
                    179:             }
                    180:             return (TRUE);
                    181: 
                    182:         case WM_DESTROY:
                    183:             break;
                    184: 
                    185:         case WM_COMMAND:
                    186:             wmId = LOWORD(wParam);
                    187:             switch (wmId) {
                    188: 
                    189:                 case T_HELP:
                    190:                     DoHelp ("Contents");
                    191:                     break;
                    192: 
                    193:                 case IDOK:
                    194:                     cmd = cmdline = (char *)GlobalAlloc (GPTR, 128);
                    195:                     argv[0] = cmdline;
                    196:                     argc = 0;
                    197: 
                    198:                     if (cmdline) {
                    199:                         iCtrl = i = 0;
                    200:                         while (dlgctrls[i].ctrlId) {
                    201:                             if (dlgctrls[i].ctrlId != iCtrl) {
                    202:                                 iCtrl = dlgctrls[i].ctrlId;
                    203:                                 index = SendDlgItemMessage(hdlg, iCtrl, CB_GETCURSEL, 0, 0);
                    204:                                 if (index) {
                    205:                                     item = SendDlgItemMessage (hdlg, iCtrl, CB_GETITEMDATA, index, 0);
                    206:                                     wsprintf ((LPSTR)cmd, "-%s", (LPSTR)dlgctrls[item].opt);
                    207:                                     cmd += strlen(cmd);
                    208:                                     cmd[0] = 0;
                    209:                                     argv[++argc] = ++cmd;
                    210:                                 }
                    211:                             }
                    212:                             i++;
                    213:                         }
                    214: 
                    215:                     } // if (cmdline)...
                    216: 
                    217:                     EndDialog(hdlg, argc);
                    218:                     return (TRUE);
                    219: 
                    220:                 case IDCANCEL:
                    221:                     EndDialog(hdlg, 0);
                    222:                     return (TRUE);
                    223:             }
                    224:             break;
                    225:     }
                    226:     return (FALSE);
                    227: 
                    228:     lParam; // unreferenced formal parameter
                    229: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.