Annotation of mstools/samples/ddeml/ddeinst/ddemain.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: /*
                     13:    ddemain.c
                     14: */
                     15: 
                     16: #include <windows.h>
                     17: #include <stdio.h>
                     18: #include <stdlib.h>
                     19: #include <string.h>
                     20: 
                     21: #include "ddeinst.h"
                     22: #include "ddeglbl.h"
                     23: 
                     24: 
                     25: HMENU   hMenu;
                     26: 
                     27: /********************************************************************
                     28: 
                     29:    WinMain.
                     30:    
                     31:    Function that starts the app.
                     32: 
                     33: ********************************************************************/
                     34: 
                     35: int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst,
                     36:       LPSTR lpCmdLine, int iShowCmd) {
                     37:    MSG   msg;
                     38: 
                     39:    ghModule = GetModuleHandle (NULL);
                     40: 
                     41: 
                     42: // Initialize the Application
                     43:    if (!InitializeApp ()) {
                     44:       MessageBox (ghwndMain, "memory: InitializeApp failure!", "Error", MB_OK);
                     45:       return (FALSE);
                     46:    }/*endIf*/
                     47: 
                     48: 
                     49: // Parse the command line
                     50:    if (!DecodeOptions (lpCmdLine)) {
                     51:       MessageBox (ghwndMain, "decode: Command line errors!", "Error", MB_OK);
                     52:       CleanUpApp ();
                     53:       return (FALSE);
                     54:    }/*endIf*/
                     55: 
                     56: 
                     57: // Load the accelerators
                     58:    if (!(ghAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID)))) {
                     59:       MessageBox(ghwndMain, "memory: Load Accel failure!", "Error", MB_OK);
                     60:    }/*endIf*/
                     61: 
                     62: 
                     63: // Test
                     64:    PostMessage (ghwndMain, WM_USER_GET_APPS, 0, 0L);
                     65: 
                     66: // Get the group names from the Program Manager
                     67:    PostMessage (ghwndMain, WM_USER_GET_GROUPS, 0, 0L);
                     68: 
                     69: // Main Event Loop
                     70:    while (GetMessage (&msg, NULL, 0, 0)) {
                     71:       if (!TranslateAccelerator (ghwndMain, ghAccel, &msg)) {
                     72:          TranslateMessage (&msg);
                     73:          DispatchMessage (&msg);
                     74:       }/*endIf*/
                     75:    }/*endWhile*/
                     76: 
                     77: // Clean up
                     78:    CleanUpApp ();
                     79:    return (TRUE);
                     80: }/* end WinMain */
                     81: 
                     82: /********************************************************************
                     83: 
                     84:    InitializeApp.
                     85:    
                     86:    Function that registers the window classes and creates the main
                     87:    window.
                     88: 
                     89: ********************************************************************/
                     90: 
                     91: BOOL InitializeApp () {
                     92:    char      szErrorString[80];
                     93:    WNDCLASS wc;
                     94:    long      lError;
                     95: 
                     96: // Fill in the class info for the main window.
                     97:    wc.style         = CS_OWNDC;
                     98:    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
                     99:    wc.cbClsExtra    = 0;
                    100:    wc.cbWndExtra    = sizeof(LONG);
                    101:    wc.hInstance     = ghModule;
                    102:    wc.hIcon         = LoadIcon(ghModule, MAKEINTRESOURCE(APPICON));
                    103:    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
                    104:    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
                    105:    wc.lpszMenuName  = "MainMenu";
                    106:    wc.lpszClassName = "DDEMLInstaller";
                    107: 
                    108:    if (!RegisterClass(&wc))
                    109:       return FALSE;
                    110: 
                    111: // Fill in the class info for the status bar.
                    112:    wc.style         = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
                    113:    wc.lpfnWndProc   = (WNDPROC)StatusBarWndProc;
                    114:    wc.hIcon         = NULL;
                    115:    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
                    116:    wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW);
                    117:    wc.lpszMenuName  = NULL;
                    118:    wc.lpszClassName = "StatusBar";
                    119: 
                    120:    if (!RegisterClass(&wc))
                    121:       return FALSE;
                    122: 
                    123:    hMenu = LoadMenu (ghModule, MAKEINTRESOURCE (MainMenu));
                    124:    if (!hMenu) {
                    125:       lError = GetLastError ();
                    126:       sprintf (szErrorString, "MainMenu load failed %ld", lError);
                    127:       MessageBox (GetDesktopWindow (), szErrorString, "Error", MB_OK);
                    128:    }/*endIf*/
                    129: 
                    130:    ghwndMain = CreateWindowEx (0L, "DDEMLInstaller", "Sample Installer",
                    131:          WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
                    132:          WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
                    133:          WS_CLIPCHILDREN | WS_SYSMENU,
                    134:          80, 70, 550, 250,
                    135:          NULL, hMenu, ghModule, NULL);
                    136: 
                    137:    if (ghwndMain == NULL)
                    138:       return FALSE;
                    139: 
                    140:    ShowWindow (ghwndMain, SW_SHOWDEFAULT);
                    141:    UpdateWindow (ghwndMain);
                    142: 
                    143:    SetWindowLong (ghwndMain, GWL_USERDATA, 0L);
                    144: 
                    145: // Set the initial focus to the main window
                    146:    SetFocus(ghwndMain);    /* set initial focus */
                    147: 
                    148:    return TRUE;
                    149: }/* end InitializeApp */
                    150: 
                    151: /********************************************************************
                    152: 
                    153:    CleanUpApp.
                    154:    
                    155:    Function that takes care of house cleaning when app terminates.
                    156: 
                    157: ********************************************************************/
                    158: 
                    159: void CleanUpApp () {
                    160: 
                    161: // Destroy the menu loaded in InitializeApp.
                    162:    DestroyMenu (hMenu);
                    163: 
                    164: // If the DDEML conversation id is non-zero the Uninitialize the conversation
                    165:    if (lIdInst2) {
                    166:       DdeUninitialize (lIdInst2);
                    167:    }/*endIf*/
                    168: 
                    169: // If memory has been allocated for the user defined path then release it.
                    170:    if (szUserPath) {
                    171:       VirtualFree (szUserPath, MAX_PATH, MEM_DECOMMIT);
                    172:    }/*endIf*/
                    173:    if (szUserGroup) {
                    174:       VirtualFree (szUserGroup, MAX_PATH, MEM_DECOMMIT);
                    175:    }/*endIf*/
                    176: }/* end CleanUpApp */
                    177: 
                    178: /********************************************************************
                    179: 
                    180:    DecodeOptions.
                    181:    
                    182:    Function that decodes the command line looking for the user specified
                    183:    arguments.
                    184: 
                    185: ********************************************************************/
                    186: 
                    187: BOOL DecodeOptions (LPSTR lpCmdLine) {
                    188:    LPSTR  szFirst;
                    189:    LPSTR  szToken;
                    190: 
                    191: // Allocate a block of memory to use for the user specified path.
                    192:    szUserPath = VirtualAlloc (NULL, MAX_PATH, MEM_COMMIT, PAGE_READWRITE);
                    193:    szUserGroup = VirtualAlloc (NULL, MAX_PATH, MEM_COMMIT, PAGE_READWRITE);
                    194:    if (!GetEnvironmentVariable ("MSTOOLS", szUserPath, MAX_PATH - 1)) {
                    195:       strcpy (szUserPath, "c:\\mstools\\samples");
                    196:    } else {
                    197:       strcat (szUserPath, "\\samples");
                    198:    }/*endIf*/
                    199:    strcpy (szUserGroup, "Sample Applications");
                    200:    fBatch = FALSE;
                    201:    if (!(szToken = strtok (lpCmdLine, "-/"))) {
                    202:       return (TRUE);
                    203:    }/*endIf*/
                    204:    do {
                    205:       switch (*szToken) {
                    206:          case 's':
                    207:          case 'S':{
                    208:             szFirst = szToken + 1;
                    209:             while (*szFirst == ' ') {
                    210:                szFirst++;
                    211:             }/*endWhile*/
                    212:             strcpy (szUserPath, szFirst);
                    213:             while (szFirst = strrchr (szUserPath, ' ')) {
                    214:                *szFirst = '\0';
                    215:             }/*endWhile*/
                    216:             break;
                    217:          }/*endCase*/
                    218:          case 'b':
                    219:          case 'B': {
                    220:             fBatch = TRUE;
                    221:             break;
                    222:          }/*endCase*/
                    223:          case 'i':
                    224:          case 'I': {
                    225:             fBatch = FALSE;
                    226:             break;
                    227:          }/*endCase*/
                    228:          case 'g':
                    229:          case 'G': {
                    230:             szFirst = szToken + 1;
                    231:             while (*szFirst == ' ') szFirst++;
                    232:             strcpy (szUserGroup, szFirst);
                    233:             while (szFirst = strrchr (szUserGroup, ' ')) {
                    234:                *szFirst = '\0';
                    235:             }/*endWhile*/
                    236:             break;
                    237:          }/*endCase*/
                    238:       }/*endSwitch*/
                    239:    } while (szToken = strtok (NULL, "-/"));
                    240:    return (TRUE);
                    241: }/* end DecodeOptions */

unix.superglobalmegacorp.com

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