Annotation of mstools/samples/sdktools/winat/winat.c, revision 1.1.1.1

1.1       root        1: //===========================================================================
                      2: //
                      3: // Module: WINAT.C
                      4: //
                      5: // Purpose: Main program for WINAT.exe.  This program is a GUI Windows
                      6: //          NT AT Command Scheduler.  The base code was taken from the
                      7: //          Windows NT AT command files.  I have preserved (mostly) the
                      8: //          same algorithms and data structures.
                      9: //
                     10: // Author: Kory Gill
                     11: //
                     12: // Date  : March 1993
                     13: //
                     14: // Copyright: Copyright Microsoft Corporation 1993
                     15: //
                     16: // Original banner from Windows NT at.c
                     17: //
                     18: //      /*++
                     19: //
                     20: //      Copyright (c) 1987-1992  Microsoft Corporation
                     21: //
                     22: //      Module Name:
                     23: //
                     24: //          atcmd.c
                     25: //
                     26: //      Abstract:
                     27: //
                     28: //          Code for AT command, to be used with SCHEDULE service on
                     29: //          Windows NT.
                     30: //
                     31: //          The module was taken from LanManager\at.c and then modified
                     32: //          considerably to work with NT Schedule service.
                     33: //
                     34: //      Author:
                     35: //
                     36: //          Vladimir Z. Vulovic     (vladimv)       06 - November - 1992
                     37: //
                     38: //      Environment:
                     39: //
                     40: //          User Mode - Win32
                     41: //
                     42: //      Revision History:
                     43: //
                     44: //          06-Nov-1992     vladimv
                     45: //              Created
                     46: //
                     47: //          20-Feb-1993     yihsins
                     48: //              Get rid of hard coded strings and parse/print time according
                     49: //              to user profile
                     50: //
                     51: //      --*/
                     52: //
                     53: //===========================================================================
                     54: 
                     55: 
                     56: //===========================================================================
                     57: // includes
                     58: //===========================================================================
                     59: 
                     60: #include <windows.h>    // required for all Windows applications
                     61: #include "lmcons.h"     // LAN Manager defines
                     62: #include "MYnetmsg.h"   // APE2 defines
                     63: #include "lmerr.h"      // LAN Manager error messages
                     64: #include "lmat.h"       // AT Command prototypes
                     65: #include "lmapibuf.h"   // NetApiBufferFree
                     66: #include "WINAT.h"      // specific to this program
                     67: #include "listhapi.h"   // hotizontal listbox routines
                     68: #include <assert.h>     // assert
                     69: #include <stdio.h>      // assert
                     70: 
                     71: 
                     72: //===========================================================================
                     73: // global variables
                     74: //===========================================================================
                     75: 
                     76: ATTIME  AtTime[NUM_TIMES] =                 // time strings and ms since 12am
                     77:     {
                     78:         "00:00",  0, "00:30",  0, "01:00",  0, "01:30",  0,
                     79:         "02:00",  0, "02:30",  0, "03:00",  0, "03:30",  0,
                     80:         "04:00",  0, "04:30",  0, "05:00",  0, "05:30",  0,
                     81:         "06:00",  0, "06:30",  0, "07:00",  0, "07:30",  0,
                     82:         "08:00",  0, "08:30",  0, "09:00",  0, "09:30",  0,
                     83:         "10:00",  0, "10:30",  0, "11:00",  0, "11:30",  0,
                     84:         "12:00",  0, "12:30",  0, "13:00",  0, "13:30",  0,
                     85:         "14:00",  0, "14:30",  0, "15:00",  0, "15:30",  0,
                     86:         "16:00",  0, "16:30",  0, "17:00",  0, "17:30",  0,
                     87:         "18:00",  0, "18:30",  0, "19:00",  0, "19:30",  0,
                     88:         "20:00",  0, "20:30",  0, "21:00",  0, "21:30",  0,
                     89:         "22:00",  0, "22:30",  0, "23:00",  0, "23:30",  0
                     90:     };
                     91: AT_INFO GlobalAtInfo;                       // at information structure
                     92: BOOL    fTimer;                             // flag for timer events
                     93: DWORD   GlobalJobId;                        // job id as dword
                     94: DWORD   dwDisposition;                      // used for registry calls
                     95: DWORD   dwH = DWH;                          // height of main window
                     96: DWORD   dwTime;                             // time in milliseconds
                     97: DWORD   dwW = DWW;                          // width of main window
                     98: DWORD   dwX = DWX;                          // x location of main window
                     99: DWORD   dwY = DWY;                          // y location of main window
                    100: FARPROC lpAmPmProc;                                                    // subclass for add/change AmPm edit control
                    101: FARPROC lpAmPmDefProc;                                         // default handler for add/change AmPm edit control
                    102: FARPROC lpDownButtonProc;                                      // subclass for spin button
                    103: FARPROC lpDownButtonDefProc;                           // default handler for spin buttons
                    104: FARPROC lpHourProc;                                                    // subclass for add/change hour edit control
                    105: FARPROC lpHourDefProc;                                         // default handler for add/change hour edit control
                    106: FARPROC lpMinProc;                                                     // subclass for add/change min edit control
                    107: FARPROC lpMinDefProc;                                          // default handler for add/change min edit control
                    108: FARPROC lpUpButtonProc;                                                // subclass for spin button
                    109: FARPROC lpUpButtonDefProc;                                     // default handler for spin buttons
                    110: HANDLE  hInst;                              // instance
                    111: HCURSOR hCursorOld;                         // old cursor
                    112: HCURSOR hCursorWait;                        // hourglass cursor
                    113: HFONT   hFont;                              // handle to font
                    114: HANDLE  GlobalMessageHandle;                // handle to netmsg.dll
                    115: HKEY    hkHandle;                           // hangle to registry
                    116: HWND    hCurrentFocus = NULL;                          // handle to window with focus (used for hour/min/ampm spin buttons)
                    117: HWND    hGlobalhWnd;                        // handle to main window
                    118: HWND    hGlobalAddChg = NULL;               // handle to Add/Change dialog when active
                    119: HWND   hHour = NULL;                       // handle to hour
                    120: HWND   hMin = NULL;                        // handle to minutes
                    121: HWND    hAmPm = NULL;                       // handle to ampm 
                    122: LOGFONT lf;                                 // font
                    123: PWSTR   GlobalComputerName;                 // currently selected comp. name
                    124: UCHAR   szRegistryPath[] = SZREGPATH;       // path to registry for stored info
                    125: UCHAR   szAppName[] = SZAPPTITLE;           // name of this application
                    126: UCHAR   szAtCommand[MAX_ATCMD_LEN+1];       // entire line in atcommand listbox
                    127: UCHAR   szCommandM[MAXCOMMANDLEN+1];        // multibyte command
                    128: UCHAR   szComputerM[MAXCOMPUTERNAMELEN+1];  // multibyte comp. name
                    129: UCHAR   szDateAbbr[4];                      // store day of month as string
                    130: UCHAR   szDayAbbr[7][4]   =                 // abbreviations
                    131:     {
                    132:         "M ", "T ", "W ", "Th ", "F ", "Sa ", "Su "
                    133:     };
                    134: UCHAR   szDefault[] = " ";                  // default char for wide conversion
                    135: UCHAR   szError[] = SZGENERROR;             // error message
                    136: UCHAR   szNoEntries[] = SZNOENTRIES;        // error message
                    137: UCHAR   szTime[8];                          // store time as string
                    138: UCHAR   szTitle[]   = SZAPPTITLE;           // title bar text
                    139: UCHAR   szWhenDay[MAXWHENDAYLEN + 1];       // used to build when/day string
                    140: UINT    uAmPmChars;                                                    // count of characters in add/change AmPm edit control
                    141: UINT    uHourChars;                                                    // count of characters in add/change hour edit control
                    142: UINT    uMinChars;                                                     // count of characters in add/change min edit control
                    143: UINT    uTimer;                             // handle of timer 
                    144: WCHAR   szCommandW[MAXCOMMANDLEN+1];        // widechar command
                    145: WCHAR   szComputerW[MAXCOMPUTERNAMELEN+1];  // widechar comp. name
                    146: 
                    147: 
                    148: 
                    149: //===========================================================================
                    150: // FUNCTION: AddChangeDlgProc()
                    151: //===========================================================================
                    152: 
                    153: BOOL APIENTRY
                    154: AddChangeDlgProc(
                    155:     HWND hWnd,         // window handle
                    156:     UINT message,      // type of message
                    157:     UINT uParam,       // additional information
                    158:     LONG lParam        // additional information
                    159:     )
                    160: {
                    161: 
                    162:     NET_API_STATUS  status;
                    163:     PAT_INFO        pAtInfo = NULL;
                    164:     SYSTEMTIME      SystemTime;
                    165:     UCHAR           szAtCommand[MAX_ATCMD_LEN];
                    166:     UCHAR           szTemp[30];
                    167:     char *          ptr;
                    168:     int             JobId;
                    169:     int             i;
                    170:     int             wmEvent;
                    171:     int             wmId;
                    172:     static BOOL     fChange;
                    173:     BOOL                       Translated;
                    174:     UINT                       Value;
                    175:     int                        Delta;    
                    176:     
                    177:     // owner draw stuff
                    178:     static LPDRAWITEMSTRUCT  lpdis;          // Long Pointer to owner-draw struct
                    179:     LPMEASUREITEMSTRUCT      lpmis;          // Long Pointer to o-d measure struct
                    180:     static HBITMAP           hButtonUpDef,   // for button's regular state bm
                    181:                              hButtonUpDep,   // for button's pushed  state bm
                    182:                              hButtonDownDef, // for button's regular state bm
                    183:                              hButtonDownDep; // for button's pushed  state bm
                    184:     
                    185:     switch (message) {
                    186:                
                    187:                case WM_SPINBUTTON:
                    188:             
                    189:             if ( (hCurrentFocus != hHour) && (hCurrentFocus != hMin) && (hCurrentFocus != hAmPm) ) {
                    190:             
                    191:                break;
                    192:                
                    193:             }
                    194:             
                    195:                if ( lParam == UP ) {
                    196:                                
                    197:                        Delta = UP;
                    198:                                        
                    199:                } else {
                    200:                                
                    201:                                Delta = DOWN;                   
                    202:                                        
                    203:                }
                    204:                                        
                    205:                if ( uParam == (UINT)GetDlgItem( hWnd, IDC_HOUR ) ) {
                    206:                                                
                    207:                                Value = GetDlgItemInt( hWnd, IDC_HOUR, &Translated, FALSE );
                    208:                                                        
                    209:                                if ( Translated == 0 ) {
                    210:                                                                
                    211:                                        SetDlgItemInt( hWnd, IDC_HOUR, DEFAULT_HOUR, FALSE );
                    212:                                                                
                    213:                                } else {
                    214:                                                                
                    215:                                        if ( ( Value >= 12 || Value < 1 ) && Delta == UP ) {
                    216:                                                                 
                    217:                                                Value = 1;
                    218:                                                                        
                    219:                                        } else if ( ( Value > 12 || Value <= 1 ) && Delta == DOWN ) {
                    220:                                                                
                    221:                                                Value = 12;
                    222:                                                                    
                    223:                                        } else {
                    224:                                                                        
                    225:                                                if ( (Value == 11 && Delta == UP) || (Value == 12 && Delta == DOWN) ) {
                    226:                                                                                
                    227:                                                        GetDlgItemText( hWnd, IDC_AMPM, (LPTSTR)&szTemp, sizeof(szTemp) );   
                    228:                                                                        
                    229:                                                if ( szTemp[0] == 'A' || szTemp[0] == 'a' ) {
                    230:                                                                        
                    231:                                                        SetDlgItemText( hWnd, IDC_AMPM,  (LPCTSTR)"PM" );
                    232:                                                                                
                    233:                                                } else {
                    234:                                                                        
                    235:                                                                SetDlgItemText( hWnd, IDC_AMPM,  (LPCTSTR)"AM" );
                    236:                                                                                        
                    237:                                                        }
                    238:                                                }
                    239:                                                                        
                    240:                                                Value += Delta;
                    241:                                                                        
                    242:                                        }
                    243:                                                                
                    244:                                        SetDlgItemInt( hWnd, IDC_HOUR, Value, FALSE );
                    245:                                                                        
                    246:                                }
                    247:                                
                    248:                                SendDlgItemMessage( hWnd, IDC_HOUR, EM_SETSEL, 0, -1 );         
                    249:                                //SetFocus( (HWND)uParam );
                    250:                                                
                    251:                        } else if ( uParam == (UINT)GetDlgItem( hWnd, IDC_MIN ) ) {
                    252:                                
                    253:                Value = GetDlgItemInt( hWnd, IDC_MIN, &Translated, FALSE );
                    254:                                                        
                    255:                                if ( Translated == 0 ) {
                    256:                                                                
                    257:                                        SetDlgItemInt( hWnd, IDC_MIN, DEFAULT_MIN, FALSE );
                    258:                                                                
                    259:                                } else {
                    260:                                                                
                    261:                                        if ( ( Value >= 59 || Value < 0 ) && Delta == UP ) {
                    262:                                                                
                    263:                                                Value = 0;
                    264:                                                                                              
                    265:                                        } else if ( ( Value > 59 || Value <= 0 ) && Delta == DOWN ) {
                    266:                                                                
                    267:                                                Value = 59;
                    268:                                                                
                    269:                                        } else {
                    270:                                                                        
                    271:                                                Value += Delta;
                    272:                                                                        
                    273:                                        }
                    274:                                                        
                    275:                                }
                    276:                                
                    277:                                if ( Value > 9 ) {
                    278:                                                                
                    279:                                        SetDlgItemInt( hWnd, IDC_MIN, Value, FALSE );
                    280:                                                                
                    281:                                } else {
                    282:                                                                        
                    283:                                        szTemp[0] = '0';
                    284:                                        szTemp[1] = '0' + Value;
                    285:                                        szTemp[2] = '\0';
                    286:                                                                
                    287:                                SetDlgItemText( hWnd, IDC_MIN, szTemp );
                    288:                            }          
                    289:                                
                    290:                                SendDlgItemMessage( hWnd, IDC_MIN, EM_SETSEL, 0, -1 );                          
                    291:                                //SetFocus( (HWND)uParam );
                    292:                                                        
                    293:                } else if ( uParam == (UINT)GetDlgItem( hWnd, IDC_AMPM ) ) {
                    294:                                                
                    295:                        GetDlgItemText( hWnd, IDC_AMPM, (LPTSTR)&szTemp, sizeof(szTemp) );   
                    296:                                                
                    297:                        if ( szTemp[0] == 'A' || szTemp[0] == 'a' ) {
                    298:                                                
                    299:                                SetDlgItemText( hWnd, IDC_AMPM,  (LPCTSTR)"PM" );
                    300:                                                        
                    301:                        } else {
                    302:                                                
                    303:                                        SetDlgItemText( hWnd, IDC_AMPM,  (LPCTSTR)"AM" );
                    304:                                                                
                    305:                                }
                    306:                 
                    307:                 SendDlgItemMessage( hWnd, IDC_AMPM, EM_SETSEL, 0, -1 );                
                    308:                        //SetFocus( (HWND)uParam );
                    309: 
                    310:                        }
                    311:                                
                    312:                break;
                    313:                        
                    314:         case WM_MEASUREITEM:
                    315: 
                    316:             lpmis = (LPMEASUREITEMSTRUCT)lParam; // for convenience
                    317:             lpmis->itemWidth  = 7;
                    318:             lpmis->itemHeight = 7;
                    319: 
                    320:             break;
                    321: 
                    322:         case WM_DRAWITEM:
                    323: 
                    324:             lpdis = (LPDRAWITEMSTRUCT)lParam;    // for convenience
                    325: 
                    326:             switch (lpdis->itemAction) {
                    327: 
                    328:                 case ODA_DRAWENTIRE:
                    329:                     if ( lpdis->CtlID == IDD_DOWNBUT ) {
                    330:                        DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonDownDef, SRCCOPY);
                    331:                     } else {
                    332:                        DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonUpDef, SRCCOPY);
                    333:                     }
                    334:                     
                    335:                     break;
                    336:                 
                    337:                 case ODA_SELECT:
                    338:                     // handle select state -- text is right & down 2 pixels
                    339:                     // also handle focus state since it's associated
                    340:                     if (lpdis->itemState & ODS_SELECTED) {
                    341:                         if ( lpdis->CtlID == IDD_DOWNBUT ) {
                    342:                                DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonDownDep, SRCCOPY);
                    343:                            } else {
                    344:                                DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonUpDep, SRCCOPY);
                    345:                            }
                    346:                     }
                    347:                     else {
                    348:                         if ( lpdis->CtlID == IDD_DOWNBUT ) {
                    349:                                DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonDownDef, SRCCOPY);
                    350:                            } else {
                    351:                                DrawBitmap(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hButtonUpDef, SRCCOPY);
                    352:                            }
                    353:                                
                    354:                                if ( hCurrentFocus != NULL ) {
                    355:                                
                    356:                                        SetFocus( hCurrentFocus );
                    357:                                        
                    358:                                }
                    359:     
                    360:                     }
                    361:                     break;
                    362: 
                    363:                 case ODA_FOCUS:
                    364:                     if (lpdis->itemState & ODS_FOCUS) {
                    365: 
                    366:                            break;
                    367:                        }
                    368: 
                    369:                        break;
                    370: 
                    371:                 default:
                    372: 
                    373:                     break;
                    374: 
                    375:             }  //itemAction
                    376: 
                    377:             break;
                    378:                
                    379:         case WM_INITDIALOG:
                    380:                        
                    381:                        /* load bitmaps and get area of text rectangle for owner-draw button */        
                    382:             
                    383:             hButtonUpDef = LoadBitmap(hInst,"BUTTONUPDEF"); // regular state
                    384:             hButtonUpDep   = LoadBitmap(hInst,"BUTTONUPDEP");   // pushed  state
                    385:             
                    386:             
                    387:             hButtonDownDef = LoadBitmap(hInst,"BUTTONDOWNDEF"); // regular state
                    388:             hButtonDownDep = LoadBitmap(hInst,"BUTTONDOWNDEP");   // pushed  state
                    389:             
                    390:             hCurrentFocus = NULL;
                    391:             hHour = GetDlgItem( hWnd, IDC_HOUR );
                    392:             hMin  = GetDlgItem( hWnd, IDC_MIN );
                    393:             hAmPm = GetDlgItem( hWnd, IDC_AMPM );
                    394:             
                    395:                        SendDlgItemMessage( hWnd, IDC_NEWCOMMAND, WM_SETFONT, (WPARAM)hFont, 1L );    
                    396:                        SendDlgItemMessage( hWnd, IDC_DAYS, WM_SETFONT, (WPARAM)hFont, 1L );
                    397:                        SendDlgItemMessage( hWnd, IDC_HOUR, WM_SETFONT, (WPARAM)hFont, 1L );
                    398:                        SendDlgItemMessage( hWnd, IDC_MIN, WM_SETFONT,  (WPARAM)hFont, 1L );
                    399:                        SendDlgItemMessage( hWnd, IDC_AMPM, WM_SETFONT, (WPARAM)hFont, 1L );
                    400:                                                
                    401:             // fill in Days
                    402:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Monday");
                    403:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Tuesday");
                    404:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Wednesday");
                    405:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Thursday");
                    406:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Friday");
                    407:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Saturday");
                    408:             SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)"Sunday");
                    409:                           
                    410:             for ( i=1; i<=9; ++i ) {
                    411: 
                    412:                 UCHAR szDateAbbr[2];
                    413: 
                    414:                 szDateAbbr[0] = i + '0';
                    415:                 szDateAbbr[1] = '\0';
                    416: 
                    417:                 SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)szDateAbbr );
                    418: 
                    419:             }
                    420:       
                    421:                for ( i=10; i<=31; ++i ) {
                    422: 
                    423:                 UCHAR szDateAbbr[3];
                    424: 
                    425:                 szDateAbbr[0] = i/10 + '0';
                    426:                 szDateAbbr[1] = i%10 + '0';
                    427:                 szDateAbbr[2] = '\0';
                    428: 
                    429:                 SendDlgItemMessage(hWnd, IDC_DAYS, LB_ADDSTRING, 0, (LPARAM)szDateAbbr );
                    430: 
                    431:             }
                    432: 
                    433:                if ( lParam == IDC_ADD ) {
                    434:                            
                    435:                    SendDlgItemMessage(hWnd, IDC_DAYS, LB_SETCURSEL, 0, 0);
                    436:                    
                    437:                    // fill in Time
                    438:                    
                    439:                        SetDlgItemInt( hWnd, IDC_HOUR, DEFAULT_HOUR, FALSE );
                    440:                        
                    441:                        if ( DEFAULT_MIN > 9 ) {
                    442:                                                
                    443:                                        SetDlgItemInt( hWnd, IDC_MIN, DEFAULT_MIN, FALSE );
                    444:                                                
                    445:                                } else {
                    446:                                                        
                    447:                                        szTemp[0] = '0';
                    448:                                        szTemp[1] = '0' + DEFAULT_MIN;
                    449:                                        szTemp[2] = '\0';
                    450:                                                
                    451:                                SetDlgItemText( hWnd, IDC_MIN, szTemp );
                    452:                            }                                
                    453:                                                
                    454:                        SetDlgItemText( hWnd, IDC_AMPM, (LPCTSTR)DEFAULT_AMPM );
                    455:                           
                    456:                    // set the Every radio button
                    457:                 
                    458:                    SendDlgItemMessage(hWnd, IDC_EVERY, BM_SETCHECK, TRUE, 0);
                    459:                    
                    460:                    fChange = FALSE;
                    461:                            
                    462:                        lstrcpy( szTemp, "Add Command" );
                    463:                
                    464:                SetWindowText( hWnd, szTemp );
                    465:                                        
                    466:                } else {
                    467:                    
                    468:                    fChange = TRUE;
                    469:                    
                    470:                                lstrcpy( szTemp, "Change Command" );
                    471:                                
                    472:                                SetWindowText( hWnd, szTemp );
                    473:                                
                    474:                                // fill in current command info
                    475: 
                    476:                                SendDlgItemMessage( 
                    477:                        hGlobalhWnd, 
                    478:                        IDC_ATCOMMANDS, 
                    479:                        LB_GETTEXT, 
                    480:                        SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_GETCURSEL, 0, 0 ), 
                    481:                        (LPARAM)szAtCommand 
                    482:                        );
                    483:                        
                    484:                        // get job id
                    485:                                
                    486:                    JobId = 0;
                    487:                            
                    488:                    ptr   = szAtCommand;
                    489:                
                    490:                    while( *ptr >= '0' && *ptr <= '9' ) {
                    491:                
                    492:                        JobId *= 10;
                    493:                        JobId += (UINT)*ptr - '0';
                    494:                
                    495:                        ptr++;
                    496:                
                    497:                    }   
                    498:                            
                    499:                    // get info on this job
                    500:                            
                    501:                    status = NetScheduleJobGetInfo(
                    502:                     GlobalComputerName,
                    503:                        JobId,
                    504:                        (LPBYTE *)&pAtInfo
                    505:                        );                              
                    506:                                
                    507:                    if ( status != NERR_Success ) {
                    508:                                
                    509:                        //MessageBox( hWnd, "Problem getting Job Info.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                    510:                        
                    511:                        MessagePrint( status );
                    512:                                
                    513:                        EndDialog( hWnd, 0 );
                    514:                                
                    515:                    }
                    516:                            
                    517:                    // fill in command
                    518:                            
                    519:                    WideCharToMultiByte( 
                    520:                        (UINT)CP_ACP,  
                    521:                        (DWORD)0, 
                    522:                        (LPWSTR)pAtInfo->Command, 
                    523:                        MAX_ATCMD_LEN,
                    524:                     (LPSTR)szCommandM, 
                    525:                     MAX_ATCMD_LEN, 
                    526:                     (LPSTR)NULL, (LPBOOL)NULL
                    527:                     );          
                    528:                         
                    529:                 SetDlgItemText( hWnd, IDC_NEWCOMMAND, szCommandM );
                    530:                                                        
                    531:                // set days this command runs
                    532:                        
                    533:                if ( pAtInfo->DaysOfWeek != 0) {
                    534:                        
                    535:                        for ( i=0; i<7; ++i ) {
                    536:                        
                    537:                                if ( ( pAtInfo->DaysOfWeek & (1 << i) ) != 0 ) {
                    538:                                        
                    539:                                        SendDlgItemMessage( hWnd, IDC_DAYS, LB_SETSEL, TRUE, i );
                    540:                                                
                    541:                                }
                    542:                                        
                    543:                        }
                    544:                                
                    545:                }
                    546:                     
                    547:                 if ( pAtInfo->DaysOfMonth != 0) {
                    548:                        
                    549:                        for ( i=0; i<31; ++i ) {
                    550:                        
                    551:                                if ( ( pAtInfo->DaysOfMonth & (1L << i) ) != 0 ) {
                    552:                                        
                    553:                                        SendDlgItemMessage( hWnd, IDC_DAYS, LB_SETSEL, TRUE, i+7 );
                    554:                                                
                    555:                                }
                    556:                                        
                    557:                        }
                    558:                                
                    559:                } 
                    560:                        
                    561:                // fill in every/today/tomorrow/next flag
                    562:                        
                    563:                if ( pAtInfo->Flags & JOB_RUN_PERIODICALLY ) {
                    564:                        
                    565:                        SendDlgItemMessage( hWnd, IDC_EVERY, BM_SETCHECK, TRUE, 0 );
                    566:                        
                    567:                        SendMessage( hWnd, WM_COMMAND, IDC_EVERY, 0 );
                    568:                                
                    569:                } else if ( (pAtInfo->DaysOfWeek != 0) || (pAtInfo->DaysOfMonth != 0) ) {
                    570:  
                    571:                        SendDlgItemMessage( hWnd, IDC_NEXT, BM_SETCHECK, TRUE, 0 );
                    572:                        
                    573:                        SendMessage( hWnd, WM_COMMAND, IDC_NEXT, 0 );
                    574:                                        
                    575:                                } else if ( pAtInfo->Flags & JOB_RUNS_TODAY ) {
                    576:                                                                
                    577:                        SendDlgItemMessage( hWnd, IDC_TODAY, BM_SETCHECK, TRUE, 0 );
                    578:                        
                    579:                        SendMessage( hWnd, WM_COMMAND, IDC_TODAY, 0 );
                    580:                                
                    581:                                } else {
                    582:                                                                
                    583:                        SendDlgItemMessage( hWnd, IDC_TOMORROW, BM_SETCHECK, TRUE, 0 );
                    584:                        
                    585:                        SendMessage( hWnd, WM_COMMAND, IDC_TOMORROW, 0 );
                    586:                                
                    587:                                }
                    588:                            
                    589:                    // set time for this command
                    590:                                                   
                    591:                 {
                    592: 
                    593:                     UINT  uJobTime = (UINT)(pAtInfo->JobTime / 1000 / 60 / 60);
                    594:                        UINT  uAM = TRUE;
                    595:                        
                    596:                        if ( uJobTime == 0 ) {
                    597:                                
                    598:                                uJobTime = 12;
                    599:                                
                    600:                        } else if ( uJobTime == 12 ) {
                    601:                            
                    602:                            uAM = FALSE;
                    603:                            
                    604:                        } else if ( uJobTime > 12 ) {
                    605:                        
                    606:                            uJobTime -= 12; 
                    607:                            
                    608:                            uAM = FALSE;
                    609:                                        
                    610:                                }                       
                    611: 
                    612:                        SetDlgItemInt( hWnd, IDC_HOUR, uJobTime, FALSE );
                    613:                        
                    614:                        uAM ? SetDlgItemText( hWnd, IDC_AMPM, "AM" ) : SetDlgItemText( hWnd, IDC_AMPM, "PM" );
                    615:                                                
                    616:                                        if ( (UINT)(pAtInfo->JobTime / 1000 / 60 % 60) > 9 ) {
                    617:                                                        
                    618:                                                SetDlgItemInt( hWnd, IDC_MIN, (UINT)(pAtInfo->JobTime / 1000 / 60 % 60), FALSE );
                    619:                                                        
                    620:                                        } else {
                    621:                                                                
                    622:                                                szTemp[0] = '0';
                    623:                                                szTemp[1] = '0' + (UINT)(pAtInfo->JobTime / 1000 / 60 % 60);
                    624:                                                szTemp[2] = '\0';
                    625:                                                        
                    626:                                        SetDlgItemText( hWnd, IDC_MIN, szTemp );
                    627:                                    }                   
                    628:                            
                    629:                            }
                    630:                            
                    631:                 // free buffer
                    632:                     
                    633:                                NetApiBufferFree( (LPVOID)pAtInfo );
                    634:                
                    635:                }
                    636:             
                    637:             // set up subclass functions
                    638:             
                    639:                        lpAmPmProc = MakeProcInstance( (FARPROC)AmPmProc, hInst );
                    640:                        lpAmPmDefProc = (FARPROC) SetWindowLong( GetDlgItem( hWnd, IDC_AMPM ), GWL_WNDPROC, (LONG)lpAmPmProc );
                    641:                        lpDownButtonProc = MakeProcInstance( (FARPROC)DownButtonProc, hInst );
                    642:                        lpDownButtonDefProc = (FARPROC) SetWindowLong( GetDlgItem( hWnd, IDD_DOWNBUT ), GWL_WNDPROC, (LONG)lpDownButtonProc );
                    643:                        lpUpButtonProc = MakeProcInstance( (FARPROC)UpButtonProc, hInst );
                    644:                        lpUpButtonDefProc = (FARPROC) SetWindowLong( GetDlgItem( hWnd, IDD_UPBUT ), GWL_WNDPROC, (LONG)lpUpButtonProc );
                    645:                        lpHourProc = MakeProcInstance( (FARPROC)HourProc, hInst );
                    646:                        lpHourDefProc = (FARPROC) SetWindowLong( GetDlgItem( hWnd, IDC_HOUR ), GWL_WNDPROC, (LONG)lpHourProc );
                    647:                        lpMinProc = MakeProcInstance( (FARPROC)MinProc, hInst );
                    648:                        lpMinDefProc = (FARPROC) SetWindowLong( GetDlgItem( hWnd, IDC_MIN ), GWL_WNDPROC, (LONG)lpMinProc );
                    649:                        
                    650:                        // will default to two chars
                    651:                                       
                    652:                        uHourChars = 2;
                    653:                        uMinChars = 2;                  
                    654:                        
                    655:                        
                    656:                        hGlobalAddChg = hWnd;
                    657:                        
                    658:                break;
                    659:         
                    660:         case WM_COMMAND:    // message: command from application menu
                    661: 
                    662:                        wmId    = LOWORD(uParam);
                    663:                        wmEvent = HIWORD(uParam);
                    664: 
                    665:                        switch (wmId) {
                    666:                                
                    667:                 case IDC_TODAY:
                    668:                 case IDC_TOMORROW:
                    669:                     
                    670:                     GetLocalTime( &SystemTime );
                    671:                     
                    672:                     if ( SystemTime.wDayOfWeek == 0 ) {
                    673:                     
                    674:                        SystemTime.wDayOfWeek = 7;
                    675:                        
                    676:                     }
                    677:                     
                    678:                        for( i=0; i<NUMDAYITEMS; ++i ) {
                    679:                        
                    680:                                SendDlgItemMessage( hWnd, IDC_DAYS, LB_SETSEL, FALSE, i );
                    681:                        
                    682:                        }
                    683:                        
                    684:                        SendDlgItemMessage( 
                    685:                                hWnd, 
                    686:                                IDC_DAYS, 
                    687:                                LB_SETSEL, 
                    688:                                TRUE, 
                    689:                                wmId == IDC_TOMORROW ? SystemTime.wDayOfWeek : SystemTime.wDayOfWeek - 1 ); 
                    690:                        
                    691:                     EnableWindow(GetDlgItem(hWnd, IDC_DAYS), FALSE);
                    692: 
                    693:                     break;
                    694: 
                    695:                 case IDC_EVERY:
                    696: 
                    697:                     EnableWindow(GetDlgItem(hWnd, IDC_DAYS), TRUE);
                    698: 
                    699:                     break;
                    700: 
                    701:                 case IDC_NEXT:
                    702: 
                    703:                     EnableWindow(GetDlgItem(hWnd, IDC_DAYS), TRUE);
                    704: 
                    705:                     break;
                    706: 
                    707:                                case IDCANCEL:
                    708:                                    
                    709:                                    hCurrentFocus = NULL; 
                    710:                                    DeleteObject( hButtonUpDef );
                    711:                                    DeleteObject( hButtonUpDep );
                    712:                                    DeleteObject( hButtonDownDep );
                    713:                                    DeleteObject( hButtonDownDef );
                    714: 
                    715:                                        EndDialog( hWnd, IDCANCEL );
                    716:                                        
                    717:                                        break;
                    718:                                        
                    719:                 case IDOK:
                    720:                                
                    721:                     if ( ValidateAddChangeArguments( hWnd ) == TRUE ) {
                    722:                         
                    723:                         if( fChange == TRUE) {
                    724:                         
                    725:                                status = JobDel( DEL_ID_CHANGE, hGlobalhWnd);
                    726:                                
                    727:                         }
                    728:                         
                    729:                        status = JobAdd();
                    730:        
                    731:                            if ( status == NERR_Success ) {
                    732:        
                    733:                                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_BOTTOM );
                    734:                                                        
                    735:                                                        hCurrentFocus = NULL;
                    736:                                                        DeleteObject( hButtonUpDef );
                    737:                                                    DeleteObject( hButtonUpDep );
                    738:                                                    DeleteObject( hButtonDownDep );
                    739:                                                    DeleteObject( hButtonDownDef );                                       
                    740:                                                    
                    741:                                                    EndDialog( hWnd, IDOK );    
                    742:                                                        
                    743:                            } else {
                    744:                            
                    745:                                //MessageBox( hWnd, "Problem adding command.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                    746:                                
                    747:                                MessagePrint( status );
                    748:                                
                    749:                            }
                    750:                     
                    751:                     }
                    752:                         
                    753:                     break;
                    754:                                 
                    755:                 case IDC_ADDCHANGEHELP:
                    756: 
                    757:                     if (!WinHelp (hWnd, "WINAT.HLP", HELP_KEY,(DWORD)(LPSTR)"CONTENTS")) {
                    758:                                                MessageBox (GetFocus(),
                    759:                                                        "Unable to activate help",
                    760:                                                        SZWINDOWTITLE, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
                    761:                     }
                    762: 
                    763:                     break;
                    764: 
                    765:             }
                    766: 
                    767:             break;
                    768: 
                    769:     }
                    770: 
                    771:     return (0);
                    772: 
                    773: }
                    774: 
                    775: 
                    776: 
                    777: //===========================================================================
                    778: // FUNCTION: AmPmProc()
                    779: //===========================================================================
                    780: LRESULT APIENTRY AmPmProc( HWND hWnd, UINT message, UINT uParam, LONG lParam )
                    781: {
                    782:     UCHAR szCurVal[3];
                    783:     
                    784:     switch ( message ) {
                    785: 
                    786:            case WM_COPY:
                    787:            case WM_PASTE:
                    788:            case WM_CUT:
                    789:        
                    790:                        // cut and paste dont seem to work...
                    791:                
                    792:                break;
                    793:     
                    794:        case WM_CHAR:
                    795:     
                    796:                        if ( uParam == VK_BACK ) {
                    797:                        
                    798:                                if ( uAmPmChars > 0 ) {
                    799:                                        
                    800:                                        --uAmPmChars;
                    801:                                        
                    802:                                }
                    803:                                
                    804:                                return CallWindowProc( (WNDPROC)lpAmPmDefProc, hWnd, message, uParam, lParam ) ;
                    805:                                
                    806:                        } else {
                    807:                        
                    808:                                uAmPmChars = (UINT) SendMessage( hWnd, WM_GETTEXT, 2, (LPARAM)szCurVal );
                    809:                                
                    810:                                if ( uAmPmChars == 0 ) {
                    811:                                
                    812:                                    switch( uParam ) {
                    813:                                    
                    814:                                        case 'a':
                    815:                                        case 'A':
                    816:                                            
                    817:                                            szCurVal[0] = 'A';
                    818: 
                    819:                                                break;
                    820:                                        
                    821:                                        case 'p':
                    822:                                        case 'P':
                    823:                                                  
                    824:                                            szCurVal[0] = 'P';
                    825:                                            
                    826:                                            break;
                    827:                                            
                    828:                                        default:
                    829:                                        
                    830:                                                MessageBeep( MB_OK );
                    831:                                                
                    832:                                                return( 0 );
                    833:                                            
                    834:                                    }
                    835:                                    
                    836:                                    szCurVal[1] = 'M';
                    837:                                    szCurVal[2] = '\0';
                    838:                                    uAmPmChars  = 2;
                    839:                                     
                    840:                                    SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)szCurVal );
                    841:                                    
                    842:                                    return( 0 );
                    843:                                    
                    844:                            } else if ( uAmPmChars == 1 ) {
                    845:                            
                    846:                                if ( (szCurVal[0] != 'a' && szCurVal[0] != 'A' &&
                    847:                                      szCurVal[0] != 'p' && szCurVal[0] != 'P'    ) ||
                    848:                                     (uParam != 'm' && uParam != 'M')                  ) {
                    849:                                     
                    850:                                     MessageBeep( MB_OK );
                    851:                                     
                    852:                                     return( 0 );
                    853:                                     
                    854:                                }
                    855:                                
                    856:                            } else if ( uAmPmChars == 2 ) {
                    857:                            
                    858:                                if ( (szCurVal[0] != 'a' && szCurVal[0] != 'A' && 
                    859:                                      szCurVal[0] != 'p' && szCurVal[0] != 'P'    ) ) {
                    860:                                     
                    861:                                     MessageBeep( MB_OK );
                    862:                                     
                    863:                                     SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)"" );
                    864:                                     
                    865:                                     return( 0 );
                    866:                                     
                    867:                                } else if ( szCurVal[1] != 'm' && szCurVal[1] != 'M' ) {
                    868:                                
                    869:                                        szCurVal[1] = '\0';                               
                    870:                                        
                    871:                                        MessageBeep( MB_OK );
                    872:                                        
                    873:                                        SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)szCurVal );
                    874:                                        
                    875:                                        return( 0 );
                    876:                                        
                    877:                                }
                    878:                                
                    879:                            } else if ( uAmPmChars > 2 ) {
                    880:                                
                    881:                                uAmPmChars = 0;
                    882:                                
                    883:                                MessageBeep( MB_OK );
                    884:                                
                    885:                                SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)"" );
                    886:                             
                    887:                                return( 0 );
                    888:                                
                    889:                            }
                    890:                        
                    891:                        }
                    892:                        
                    893:                break;
                    894:        
                    895:        } // switch
                    896:        
                    897:        return CallWindowProc( (WNDPROC)lpAmPmDefProc, hWnd, message, uParam, lParam ) ;
                    898:        
                    899: }
                    900: 
                    901: 
                    902: 
                    903: //===========================================================================
                    904: // FUNCTION: AreYouSure()
                    905: //
                    906: // Arguments:
                    907: //
                    908: //   Uses globals.
                    909: //
                    910: // Return Value:
                    911: //
                    912: //   ID_YES if the yes button pressed
                    913: //   ID_NO  if the  no button pressed
                    914: //
                    915: //===========================================================================
                    916: UINT
                    917: AreYouSure(
                    918:     HWND hWnd
                    919:     )
                    920: {
                    921: 
                    922:     return ( MessageBox(
                    923:                  hWnd,
                    924:                  "Remove the selected command?",
                    925:                  "Confirm Remove",
                    926:                  MB_YESNO | MB_ICONEXCLAMATION
                    927:                  )
                    928:            );
                    929: 
                    930: }
                    931: 
                    932: 
                    933: 
                    934: //===========================================================================
                    935: // FUNCTION: DownButtonProc()
                    936: //===========================================================================
                    937: LRESULT APIENTRY DownButtonProc( HWND hWnd, UINT message, UINT uParam, LONG lParam )
                    938: {
                    939:     
                    940:     switch ( message ) {
                    941:         
                    942:         case WM_SETFOCUS:
                    943:                        
                    944:                        if ( (uParam == (UINT)hHour) || (uParam == (UINT)hMin) || (uParam == (UINT)hAmPm) ) {
                    945:                                
                    946:                                hCurrentFocus = (HWND)uParam;
                    947:                 
                    948:                 PostMessage( hGlobalAddChg, WM_SPINBUTTON, uParam, (LONG)DOWN );
                    949:                 
                    950:                        } else {
                    951: 
                    952:                                hCurrentFocus = (HWND)uParam;
                    953:                                        
                    954:                        }
                    955:                        
                    956:                        break;      
                    957:        
                    958:        } // switch
                    959:        
                    960:        return CallWindowProc( (WNDPROC)lpDownButtonDefProc, hWnd, message, uParam, lParam ) ;
                    961:        
                    962: }
                    963: 
                    964: 
                    965: 
                    966: /****************************************************************************
                    967: 
                    968:     FUNCTION: DrawBitmap
                    969: 
                    970:     PURPOSE:  Draw default or pushed button bitmap
                    971: 
                    972: ****************************************************************************/
                    973: 
                    974: void DrawBitmap(
                    975:        HDC     hDC,
                    976:        LONG    xStart, 
                    977:        LONG    yStart,
                    978:        HBITMAP hBitmap,
                    979:        DWORD   rop)
                    980: {
                    981:   BITMAP        bm;
                    982:   HDC           hMemDC;
                    983:   POINT                        pt;
                    984: 
                    985:   hMemDC = CreateCompatibleDC (hDC);
                    986:   SelectObject (hMemDC, hBitmap);
                    987:   GetObject (hBitmap, sizeof (BITMAP), (LPSTR) &bm);
                    988:   pt.x = bm.bmWidth;
                    989:   pt.y = bm.bmHeight;
                    990:   BitBlt (hDC, xStart, yStart, pt.x, pt.y, hMemDC, 0, 0, rop);
                    991:   DeleteDC (hMemDC);
                    992: }
                    993: 
                    994: 
                    995: 
                    996: //===========================================================================
                    997: // FUNCTION: HourProc()
                    998: //===========================================================================
                    999: LRESULT APIENTRY HourProc( HWND hWnd, UINT message, UINT uParam, LONG lParam )
                   1000: {
                   1001:     UINT  uCurVal;        
                   1002:     UCHAR szCurVal[3];
                   1003:     
                   1004:     switch ( message ) {
                   1005:            
                   1006:            case WM_COPY:
                   1007:            case WM_PASTE:
                   1008:            case WM_CUT:
                   1009:        
                   1010:                        // cut and paste dont seem to work...
                   1011:                
                   1012:                break;
                   1013:     
                   1014:        case WM_CHAR:
                   1015:     
                   1016:                        if ( uParam == VK_BACK ) {
                   1017:                        
                   1018:                                if ( uHourChars > 0 ) {
                   1019:                                        
                   1020:                                        --uHourChars;
                   1021:                                        
                   1022:                                }
                   1023:                                
                   1024:                                return CallWindowProc( (WNDPROC)lpHourDefProc, hWnd, message, uParam, lParam ) ;
                   1025:                                
                   1026:                        } else {
                   1027:                        
                   1028:                                uHourChars = (UINT) SendMessage( hWnd, WM_GETTEXT, 2, (LPARAM)szCurVal );
                   1029:                                
                   1030:                                if ( uHourChars == 0 ) {
                   1031:                            
                   1032:                                uCurVal = 0;
                   1033:                                
                   1034:                            } else if ( uHourChars == 1 ) {
                   1035:                            
                   1036:                                uCurVal = szCurVal[0] - '0';
                   1037:                                
                   1038:                            } else if ( uHourChars == 2 ) {
                   1039:                            
                   1040:                                uCurVal  = szCurVal[0] - '0';
                   1041:                                uCurVal *= 10;
                   1042:                                uCurVal  = szCurVal[1] - '0';
                   1043:                            
                   1044:                            } else if ( uHourChars > 2 ) {
                   1045:                                
                   1046:                                uHourChars = 0;
                   1047:                                
                   1048:                                SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)"" );
                   1049:                             
                   1050:                                return( 0 );
                   1051:                                
                   1052:                            }
                   1053:                        
                   1054:                        }
                   1055:                        
                   1056:                        if ( ( uParam == ' ' )                                     ||  // space
                   1057:                             ( uParam < '0' || uParam > '9')                       ||  // not a number
                   1058:                             ( uParam == '0' && uCurVal == 0 )                     ||  // trying to enter 0 as first char
                   1059:                             ( (uParam > '2' && uCurVal >= 1) && uHourChars >= 1)  ||  // greater than 12
                   1060:                             ( uParam <= '2' && uCurVal > 1)                           // greater than 12
                   1061:                           ) {
                   1062:                        
                   1063:                                 MessageBeep( MB_OK );
                   1064:                                 
                   1065:                                 return( 0 );
                   1066:                                 
                   1067:                        } else if ( uHourChars < 2 ) {
                   1068:                        
                   1069:                                ++uHourChars;
                   1070:                                
                   1071:                        } else {
                   1072:         
                   1073:                    MessageBeep( MB_OK );
                   1074:                                 
                   1075:                            return( 0 );
                   1076:                         
                   1077:                        }
                   1078:                
                   1079:                break;
                   1080:        
                   1081:        } // switch
                   1082:        
                   1083:        return CallWindowProc( (WNDPROC)lpHourDefProc, hWnd, message, uParam, lParam ) ;
                   1084:        
                   1085: }
                   1086: 
                   1087: 
                   1088: 
                   1089: //===========================================================================
                   1090: // FUNCTION: JobAdd()
                   1091: //
                   1092: // Routine Description:
                   1093: //
                   1094: //     Adds a new item to schedule.
                   1095: //
                   1096: // Arguments:
                   1097: //
                   1098: //     None.  Uses globals.
                   1099: //
                   1100: // Return Value:
                   1101: //
                   1102: //     NET_API_STATUS return value of remote api call
                   1103: //
                   1104: //===========================================================================
                   1105: NET_API_STATUS
                   1106: JobAdd(
                   1107:     VOID
                   1108:     )
                   1109: {
                   1110: 
                   1111:     NET_API_STATUS          status;
                   1112: 
                   1113:     status = NetScheduleJobAdd(
                   1114:                 GlobalComputerName,
                   1115:                 (LPBYTE)&GlobalAtInfo,
                   1116:                 &GlobalJobId
                   1117:                 );
                   1118: 
                   1119:     if ( status != NERR_Success ) {
                   1120: 
                   1121:         /*MessageBox(
                   1122:             hGlobalhWnd,
                   1123:             ( status == NERR_ServiceNotInstalled ? "The service has not been started" : "Message could not be added." ),
                   1124:             SZWINDOWTITLE,
                   1125:             MB_OK | MB_ICONEXCLAMATION
                   1126:             );
                   1127:         */
                   1128:         
                   1129:         MessagePrint( status );
                   1130:     }               
                   1131:     
                   1132:     return ( status );
                   1133: 
                   1134: }
                   1135: 
                   1136: 
                   1137: 
                   1138: //===========================================================================
                   1139: //
                   1140: // FUNCTION: JobDel()
                   1141: //
                   1142: //
                   1143: // Routine Description:
                   1144: //
                   1145: //     This does all of the processing necessary to dump out the entire
                   1146: //     schedule file.  It loops through on each record and formats its
                   1147: //     information for printing and then goes to the next.
                   1148: //
                   1149: // Arguments:
                   1150: //
                   1151: //     DEL_ALL if to delete all jobs, DEL_ID otherwise.
                   1152: //     Uses globals.
                   1153: //
                   1154: // Return Value:
                   1155: //
                   1156: //     ERROR_SUCCESS                       if everything enumerated OK
                   1157: //     error returned by remote api        otherwise
                   1158: //
                   1159: //===========================================================================
                   1160: NET_API_STATUS
                   1161: JobDel(
                   1162:     UINT Method,
                   1163:     HWND hWnd
                   1164:     )
                   1165: {
                   1166: 
                   1167:     DWORD                      dwSelection;
                   1168:     NET_API_STATUS  status;
                   1169:     UCHAR           szAtCommand[MAX_ATCMD_LEN];
                   1170:     UINT            JobId;
                   1171:     UINT                       uSelection;
                   1172:     UINT                       uCount;
                   1173:     char *          ptr;
                   1174: 
                   1175: 
                   1176:     if ( Method != DEL_ID_CHANGE ) {
                   1177:        
                   1178:        if ( AreYouSure(hWnd) == IDNO ) {
                   1179: 
                   1180:                return( ERROR_SUCCESS );
                   1181:         
                   1182:         }
                   1183: 
                   1184:     }
                   1185: 
                   1186:     switch( Method ) {
                   1187: 
                   1188:         case DEL_ALL:
                   1189: 
                   1190:             status = NetScheduleJobDel(
                   1191:                     GlobalComputerName,
                   1192:                     0,
                   1193:                     (DWORD)-1
                   1194:                     );
                   1195: 
                   1196:             if ( status == NERR_Success ) {
                   1197: 
                   1198:                 SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_NONE );
                   1199:                 break;
                   1200: 
                   1201:             }
                   1202: 
                   1203:             break;
                   1204: 
                   1205:         case DEL_ID:
                   1206:         case DEL_ID_CHANGE:
                   1207: 
                   1208:             // compute id
                   1209:             
                   1210:             uSelection = SendDlgItemMessage( hWnd, IDC_ATCOMMANDS, LB_GETCURSEL, 0, 0 );
                   1211:             uCount     = SendDlgItemMessage( hWnd, IDC_ATCOMMANDS, LB_GETCOUNT,  0, 0 );
                   1212:             
                   1213:             SendDlgItemMessage( 
                   1214:                hWnd, 
                   1215:                IDC_ATCOMMANDS, 
                   1216:                LB_GETTEXT, 
                   1217:                uSelection,
                   1218:                (LPARAM)szAtCommand 
                   1219:                );
                   1220: 
                   1221:             JobId = 0;
                   1222:             ptr   = szAtCommand;
                   1223: 
                   1224:             while( *ptr >= '0' && *ptr <= '9' ) {
                   1225: 
                   1226:                 JobId *= 10;
                   1227:                 JobId += (UINT)*ptr - '0';
                   1228: 
                   1229:                 ptr++;
                   1230: 
                   1231:             }
                   1232: 
                   1233:             status = NetScheduleJobDel(
                   1234:                     GlobalComputerName,
                   1235:                     JobId,
                   1236:                     JobId
                   1237:                     );
                   1238: 
                   1239:             if ( status != NERR_Success) {
                   1240: 
                   1241:                 //MessageBox( hWnd, "Problem deleteing a job.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   1242:                 
                   1243:                 MessagePrint( status );
                   1244: 
                   1245:                 break;
                   1246: 
                   1247:             }
                   1248:             
                   1249:             if ( uCount == 1 ) {
                   1250:                                                    
                   1251:                                // this was the only job
                   1252:                                
                   1253:                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_NONE );
                   1254:                
                   1255:             } else if ( uSelection == 0 ) {
                   1256:             
                   1257:                // the first/top job was selected and there is more than 1 job
                   1258:                
                   1259:                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_TOP );
                   1260:             
                   1261:             } else if ( ( uCount - 1 ) == uSelection ) {
                   1262:                
                   1263:                // the last/bottom job was selected
                   1264:                
                   1265:                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_BOTTOM );
                   1266:             
                   1267:             } else {
                   1268:             
                   1269:                // the 2nd thru last-1 job was selected
                   1270:                
                   1271:                dwSelection  = 0;
                   1272:                dwSelection |= uSelection << 16;
                   1273:                dwSelection |= SCS_SELINHIGHWORD;
                   1274:                
                   1275:                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)dwSelection );
                   1276:             
                   1277:             }
                   1278: 
                   1279:             break;
                   1280: 
                   1281:     }
                   1282: 
                   1283:     return( status );
                   1284: 
                   1285: }
                   1286: 
                   1287: 
                   1288: 
                   1289: //===========================================================================
                   1290: //
                   1291: // FUNCTION: JobEnum()
                   1292: //
                   1293: //
                   1294: // Routine Description:
                   1295: //
                   1296: //     This does all of the processing necessary to dump out the entire
                   1297: //     schedule file.  It loops through on each record and formats its
                   1298: //     information for printing and then goes to the next.
                   1299: //
                   1300: // Arguments:
                   1301: //
                   1302: //     None.  Uses globals.
                   1303: //
                   1304: // Return Value:
                   1305: //
                   1306: //     ERROR_SUCCESS                       if everything enumerated OK
                   1307: //     error returned by remote api        otherwise
                   1308: //
                   1309: //===========================================================================
                   1310: NET_API_STATUS
                   1311: JobEnum(
                   1312:     DWORD SetCurrentSelection
                   1313:     )
                   1314: {
                   1315: 
                   1316:     BOOL            fFlag;
                   1317:     BOOL            first = TRUE;
                   1318:     DWORD           EntriesRead;
                   1319:     DWORD           ResumeJobId = 0;
                   1320:     DWORD           TotalEntries;
                   1321:     LPVOID          EnumBuffer = NULL;
                   1322:     NET_API_STATUS  status = NERR_Success;
                   1323:     PAT_ENUM        pAtEnum;
                   1324:     //UCHAR           szTemp[80];
                   1325:     static UINT                uSelection;
                   1326:     static UINT                uTopIndex;
                   1327:     int             i;
                   1328:     
                   1329:     // initialize to current selection
                   1330:     
                   1331:        uSelection = SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_GETCURSEL,   0, 0 );
                   1332:        uTopIndex  = SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_GETTOPINDEX, 0, 0 );
                   1333:        
                   1334:        if ( uSelection == LB_ERR ) {
                   1335:        
                   1336:                uSelection = 0;
                   1337:                
                   1338:        }
                   1339: 
                   1340:     for ( ; ;) {
                   1341: 
                   1342:         status = NetScheduleJobEnum(
                   1343:                 GlobalComputerName,
                   1344:                 (LPBYTE *)&EnumBuffer,
                   1345:                 (DWORD)-1,
                   1346:                 &EntriesRead,
                   1347:                 &TotalEntries,
                   1348:                 &ResumeJobId
                   1349:                 );
                   1350:          
                   1351:         if ( status != ERROR_SUCCESS  &&  status != ERROR_MORE_DATA) {
                   1352:             
                   1353:             //
                   1354:             // not needded since both the if/else(MessagePrint) will set this text now
                   1355:             //
                   1356:             //SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   1357:             //
                   1358:             //SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)szError );
                   1359:                    
                   1360:             EnableWindow( GetDlgItem( hGlobalhWnd, IDC_ADD    ), FALSE );
                   1361:             EnableWindow( GetDlgItem( hGlobalhWnd, IDC_CHANGE ), FALSE );
                   1362:                EnableWindow( GetDlgItem( hGlobalhWnd, IDC_REMOVE ), FALSE );
                   1363:                
                   1364:                if ( status == NERR_ServiceNotInstalled ) {
                   1365:             
                   1366:                 SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   1367: 
                   1368:                 SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)"Schedule service not started." );
                   1369: 
                   1370:                        if ( ServiceNotStartedHandler() == FALSE ) {
                   1371:                
                   1372:                                return( status );
                   1373:                        
                   1374:                        } else {
                   1375:                                      
                   1376:                            continue;
                   1377:                                
                   1378:                        }
                   1379:                                     
                   1380:                } else  {
                   1381: 
                   1382:                 /*wsprintf( szTemp, "The computer %s cannot be found.\nError %u.", &szComputerM[2], status );
                   1383:                                  
                   1384:                    MessageBox(
                   1385:                         hGlobalhWnd,
                   1386:                                        szTemp,
                   1387:                        SZWINDOWTITLE,
                   1388:                        MB_OK | MB_ICONEXCLAMATION
                   1389:                        );
                   1390:                    */
                   1391:                    
                   1392:                                MessagePrint( status );
                   1393:                                
                   1394:                    return( status );
                   1395: 
                   1396:                }
                   1397:                        
                   1398:         }
                   1399: 
                   1400:         assert( status == ERROR_SUCCESS ? TotalEntries == EntriesRead : TotalEntries > EntriesRead );
                   1401: 
                   1402:         if ( TotalEntries == 0) {
                   1403: 
                   1404:             break;  //  no items found
                   1405: 
                   1406:         }
                   1407: 
                   1408:         if ( first == TRUE) { 
                   1409: 
                   1410:             ResetListboxExtents( GetDlgItem( hGlobalhWnd, IDC_ATCOMMANDS ) );
                   1411:             SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   1412: 
                   1413:             first = FALSE;
                   1414: 
                   1415:         }
                   1416: 
                   1417:         for ( pAtEnum = EnumBuffer;  EntriesRead-- > 0;  pAtEnum++) {
                   1418: 
                   1419:             // not sure what this is doing...
                   1420: 
                   1421:             /*
                   1422:             if ( pAtEnum->Flags & JOB_EXEC_ERROR) {
                   1423: 
                   1424:                 if ( MessageGet( APE2_GEN_ERROR, &smallBuffer, 0 ) == 0) {
                   1425: 
                   1426:                     // error reported already
                   1427:                     exit( -1);
                   1428: 
                   1429:                 }
                   1430: 
                   1431:                 printf( DUMP_FMT1, smallBuffer );
                   1432:                 LocalFree( smallBuffer );
                   1433: 
                   1434:             } else {
                   1435: 
                   1436:                 printf( DUMP_FMT1, L"");
                   1437: 
                   1438:             }
                   1439:             */
                   1440: 
                   1441:             // replate with...
                   1442: 
                   1443:             if ( pAtEnum->Flags & JOB_EXEC_ERROR) {
                   1444: 
                   1445:                 MessagePrint( APE2_GEN_ERROR );
                   1446: 
                   1447:             }
                   1448: 
                   1449:             szWhenDay[0] = '\0';
                   1450: 
                   1451:             if ( pAtEnum->Flags & JOB_RUN_PERIODICALLY ) {
                   1452: 
                   1453:                 lstrcat( szWhenDay, "Each " );
                   1454: 
                   1455:             } else if ( pAtEnum->DaysOfWeek != 0 || pAtEnum->DaysOfMonth != 0 ) {
                   1456: 
                   1457:                 lstrcat( szWhenDay, "Next " );
                   1458: 
                   1459:             } else if ( pAtEnum->Flags & JOB_RUNS_TODAY ) {
                   1460: 
                   1461:                 lstrcat( szWhenDay, "Today " );
                   1462: 
                   1463:             } else {
                   1464: 
                   1465:                 lstrcat( szWhenDay, "Tomorrow " );
                   1466: 
                   1467:             }
                   1468: 
                   1469:             if ( pAtEnum->DaysOfWeek != 0 ) {
                   1470: 
                   1471:                 for ( i=0; i<7; ++i ) {
                   1472: 
                   1473:                     if ( ( pAtEnum->DaysOfWeek & ( 1 << i ) ) != 0 ) {
                   1474: 
                   1475:                         lstrcat( szWhenDay, szDayAbbr[i] );
                   1476: 
                   1477:                     }
                   1478: 
                   1479:                 }
                   1480: 
                   1481:             }
                   1482: 
                   1483:             if ( pAtEnum->DaysOfMonth != 0 ) {
                   1484: 
                   1485:                 for ( i=0; i<31; ++i ) {
                   1486: 
                   1487:                     if ( ( pAtEnum->DaysOfMonth & ( 1L << i ) ) != 0 ) {
                   1488: 
                   1489:                         wsprintf( szDateAbbr, "%d ", i+1 );
                   1490: 
                   1491:                         lstrcat( szWhenDay, szDateAbbr );
                   1492: 
                   1493:                     }
                   1494: 
                   1495:                 }
                   1496: 
                   1497:             }
                   1498: 
                   1499: 
                   1500:             dwTime     = pAtEnum->JobTime / 1000 / 60;       // total minutes
                   1501: 
                   1502:             szTime[0]  = (UCHAR)( dwTime / 600 ) + '0';      // 10s of hours
                   1503:             dwTime    %= 600;
                   1504: 
                   1505:             szTime[1]  = (UCHAR)( dwTime / 60 )  + '0';      // 1s of hours
                   1506:             dwTime    %= 60;
                   1507: 
                   1508:             szTime[2]  = ':';
                   1509: 
                   1510:             szTime[3]  = (UCHAR)( dwTime / 10 )  + '0';      // 10s of minutes
                   1511:             dwTime    %= 10;
                   1512: 
                   1513:             szTime[4]  = (UCHAR)( dwTime )       + '0';      // 1s of minutes
                   1514: 
                   1515:             szTime[5]  = '\0';
                   1516:             
                   1517:             // convert this 24-hour time to AM/PM form
                   1518:             
                   1519:             szTime[5] = 'A';
                   1520:             szTime[6] = 'M';
                   1521:             szTime[7] = '\0';
                   1522:                                                     
                   1523:                        // if it is past 1000 but before 2000 (24-hour time)
                   1524:                                                                            
                   1525:             if ( szTime[0] == '1' ) {
                   1526:                        
                   1527:                        // if it is past 1100
                   1528: 
                   1529:                        if ( szTime[1] >= '2' ) {
                   1530:                        
                   1531:                                szTime[5] = 'P';     
                   1532:                                
                   1533:                        }
                   1534:                        
                   1535:                    if( szTime [1] > '2' ) {
                   1536:            
                   1537:                        szTime[0] -= 1;
                   1538:                        szTime[1] -= 2;
                   1539:                        
                   1540:                    }
                   1541: 
                   1542:             } else if ( szTime[0] == '2' ) {
                   1543:                
                   1544:                // it is 2000 or later 
                   1545:                          
                   1546:                 szTime[5] = 'P';
                   1547: 
                   1548:                    // if it is 2200 or later 
                   1549: 
                   1550:                    if( szTime [1] >= '2' ) {
                   1551:        
                   1552:                        szTime[0] -= 1;
                   1553:                        szTime[1] -= 2;
                   1554:                        
                   1555:                    } else {
                   1556:                        
                   1557:                        szTime[0] -= 2;
                   1558:                        szTime[1] += 8;
                   1559:                        
                   1560:                    }
                   1561:                    
                   1562:                }
                   1563: 
                   1564:                        if ( szTime[0] == '0' ) {
                   1565:                        
                   1566:                                if ( szTime[1] == '0' ) {
                   1567:                                
                   1568:                                        // 12 am or pm
                   1569:                                
                   1570:                                        szTime[0] = '1';
                   1571:                                        szTime[1] = '2';
                   1572:                                        
                   1573:                                } else {
                   1574:                                
                   1575:                                        szTime[0] = ' ';
                   1576:                                        
                   1577:                                }
                   1578:                                
                   1579:                }
                   1580:             
                   1581:             WideCharToMultiByte(
                   1582:                 CP_ACP,
                   1583:                 0,
                   1584:                 pAtEnum->Command,
                   1585:                 -1,
                   1586:                 szCommandM,
                   1587:                 MAXCOMMANDLEN,
                   1588:                 szDefault,
                   1589:                 &fFlag
                   1590:                 );
                   1591: 
                   1592:             wsprintf( szAtCommand, "%d\t", pAtEnum->JobId );
                   1593:             lstrcat( szAtCommand, szWhenDay  );
                   1594:             lstrcat( szAtCommand, "\t"       );
                   1595:             lstrcat( szAtCommand, szTime     );
                   1596:             lstrcat( szAtCommand, "\t"       );
                   1597:             lstrcat( szAtCommand, szCommandM );
                   1598: 
                   1599:             WAddExtentEntry( GetDlgItem( hGlobalhWnd, IDC_ATCOMMANDS ), szAtCommand );
                   1600:             SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)szAtCommand );
                   1601: 
                   1602:         }
                   1603: 
                   1604:         if ( EnumBuffer != NULL ) {
                   1605: 
                   1606:             (VOID)NetApiBufferFree( (LPVOID)EnumBuffer );
                   1607:             EnumBuffer = NULL;
                   1608: 
                   1609:         }
                   1610: 
                   1611:         if ( status == ERROR_SUCCESS ) {
                   1612: 
                   1613:             break;  //  we have read & displayed all the items
                   1614: 
                   1615:         }
                   1616: 
                   1617:     } // for
                   1618: 
                   1619:     if ( first == TRUE) {
                   1620: 
                   1621:         ResetListboxExtents( GetDlgItem( hGlobalhWnd, IDC_ATCOMMANDS ) );
                   1622:         SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   1623:         WAddExtentEntry( GetDlgItem( hGlobalhWnd, IDC_ATCOMMANDS ), szNoEntries );
                   1624:         SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)szNoEntries );
                   1625:         
                   1626:         EnableWindow( GetDlgItem( hGlobalhWnd, IDC_ADD ), TRUE );
                   1627:         EnableWindow( GetDlgItem( hGlobalhWnd, IDC_CHANGE ), FALSE );
                   1628:         EnableWindow( GetDlgItem( hGlobalhWnd, IDC_REMOVE ), FALSE );
                   1629:                
                   1630:     } else {
                   1631:     
                   1632:        switch ( LOWORD( SetCurrentSelection ) ) {
                   1633:        
                   1634:                case SCS_BOTTOM:
                   1635:                        
                   1636:                        uSelection = SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_GETCOUNT, 0, 0 ) - 1;
                   1637:                        
                   1638:                        SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_SETCURSEL,  uSelection,     0 );    
                   1639:                        
                   1640:                        break;
                   1641:                                 
                   1642:                    case SCS_NOCHANGE:
                   1643:                
                   1644:                                // uSelection has already been set
                   1645:                                
                   1646:                    SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_SETCURSEL,  uSelection, 0 );
                   1647:                    
                   1648:                    break;
                   1649:                    
                   1650:                case SCS_TOP:
                   1651:                        
                   1652:                        uSelection = 0;
                   1653:                                
                   1654:                                SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_SETCURSEL,  uSelection,     0 );
                   1655:                                
                   1656:                                break;
                   1657:                                
                   1658:                case SCS_SELINHIGHWORD:
                   1659:                            
                   1660:                            uSelection = HIWORD( SetCurrentSelection );
                   1661:                                
                   1662:                                SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_SETCURSEL,  uSelection,     0 );
                   1663:                                
                   1664:                                break;
                   1665:                                
                   1666:                        case SCS_NONE:
                   1667:                        default:
                   1668:                        
                   1669:                                break;  
                   1670:                        
                   1671:        }       
                   1672:        
                   1673:        SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_SETTOPINDEX,  uTopIndex,    0 );    
                   1674:        
                   1675:        EnableWindow( GetDlgItem( hGlobalhWnd, IDC_ADD ), TRUE );
                   1676:        EnableWindow( GetDlgItem( hGlobalhWnd, IDC_CHANGE ), TRUE );
                   1677:        EnableWindow( GetDlgItem( hGlobalhWnd, IDC_REMOVE ), TRUE );
                   1678:        
                   1679:     }
                   1680: 
                   1681:     return( ERROR_SUCCESS );
                   1682: 
                   1683: }
                   1684: 
                   1685: 
                   1686: 
                   1687: 
                   1688: //===========================================================================
                   1689: // FUNCTION: MessagePrint()
                   1690: //===========================================================================
                   1691: DWORD
                   1692: MessagePrint(
                   1693:     IN      DWORD       MessageId,
                   1694:     ...
                   1695:     )
                   1696: /*++
                   1697: 
                   1698: Routine Description:
                   1699: 
                   1700:     Finds the unicode message corresponding to the supplied message id,
                   1701:     merges it with caller supplied string(s), and prints the resulting
                   1702:     string.  
                   1703: 
                   1704: Arguments:
                   1705: 
                   1706:     MessageId       -   message id
                   1707: 
                   1708: Return Value:
                   1709: 
                   1710:     Count of characters, not counting the terminating null character,
                   1711:     printed by this routine.  Zero return value indicates failure.
                   1712: 
                   1713: --*/
                   1714: {
                   1715:     va_list             arglist;
                   1716:     UCHAR *             buffer = NULL;
                   1717:     UCHAR *                    ptr;
                   1718:     DWORD               length;
                   1719:     LPVOID              lpSource;
                   1720:     DWORD               dwFlags = FORMAT_MESSAGE_ARGUMENT_ARRAY |
                   1721:                                   FORMAT_MESSAGE_ALLOCATE_BUFFER;
                   1722: 
                   1723:  
                   1724:     va_start( arglist, MessageId );
                   1725: 
                   1726:     if ( MessageId < NERR_BASE) {
                   1727:         //
                   1728:         //  Get message from system.
                   1729:         //
                   1730:         lpSource = NULL; // redundant step according to FormatMessage() spec
                   1731:         dwFlags |= FORMAT_MESSAGE_FROM_SYSTEM;
                   1732: 
                   1733:     } else if (  ( MessageId >= APE2_AT_DEL_WARNING
                   1734:                     &&  MessageId <= APE2_AT_DI_COMMAND)
                   1735:               //
                   1736:               // I cannot find these definitions!!!!
                   1737:               //
                   1738:               //|| ( MessageId >= IDS_LOAD_LIBRARY_FAILURE 
                   1739:               //      &&  MessageId <= IDS_USAGE )
                   1740:               ) {
                   1741:         //
                   1742:         //  Get message from this module.
                   1743:         //
                   1744:         lpSource = NULL;
                   1745:         dwFlags |= FORMAT_MESSAGE_FROM_HMODULE;
                   1746: 
                   1747:     } else {
                   1748:         //
                   1749:         //  Get message from netmsg.dll.
                   1750:         //
                   1751:         lpSource = GlobalMessageHandle;
                   1752:         dwFlags |= FORMAT_MESSAGE_FROM_HMODULE;
                   1753:     }
                   1754: 
                   1755:     length = FormatMessage(
                   1756:             dwFlags,                                          //  dwFlags
                   1757:             lpSource,                                         //  lpSource
                   1758:             MessageId,                                        //  MessageId
                   1759:             0L,                                               //  dwLanguageId
                   1760:             (LPTSTR)&buffer,                                 //  lpBuffer
                   1761:             0,                                                //  size
                   1762:             (va_list *) arglist                               //  lpArguments
                   1763:             );
                   1764: 
                   1765:     if ( length != 0) {
                   1766: 
                   1767:         //change to MessageBox
                   1768:         //printf( "%ws", buffer );
                   1769:         
                   1770:         ptr = buffer;
                   1771:         
                   1772:         while ( *ptr ) {
                   1773:             
                   1774:             if ( ( *ptr < ' ' ) || ( *ptr > '~' ) ) {
                   1775:                 
                   1776:                *ptr = ' ';
                   1777:                
                   1778:             }
                   1779: 
                   1780:                ptr++;          
                   1781:                
                   1782:         }
                   1783:                  
                   1784:         SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   1785:                
                   1786:         SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)(LPTSTR)buffer );
                   1787: 
                   1788:         MessageBox( hGlobalhWnd, (LPCTSTR)buffer, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   1789: 
                   1790:         LocalFree( buffer );
                   1791:     
                   1792:     }
                   1793: 
                   1794:     return( length);
                   1795: 
                   1796: } // MessagePrint()
                   1797: 
                   1798: 
                   1799: 
                   1800: //===========================================================================
                   1801: // FUNCTION: MinProc()
                   1802: //===========================================================================
                   1803: LRESULT APIENTRY MinProc( HWND hWnd, UINT message, UINT uParam, LONG lParam )
                   1804: {
                   1805:     UINT  uCurVal;        
                   1806:     UCHAR szCurVal[3];
                   1807:     
                   1808:     switch ( message ) {
                   1809:            
                   1810:            case WM_COPY:
                   1811:            case WM_PASTE:
                   1812:            case WM_CUT:
                   1813:        
                   1814:                        // cut and paste dont seem to work...
                   1815:                
                   1816:                break;
                   1817:     
                   1818:        case WM_CHAR:
                   1819:     
                   1820:                        if ( uParam == VK_BACK ) {
                   1821:                        
                   1822:                                if ( uMinChars > 0 ) {
                   1823:                                        
                   1824:                                        --uMinChars;
                   1825:                                        
                   1826:                                }
                   1827:                                
                   1828:                                return CallWindowProc( (WNDPROC)lpMinDefProc, hWnd, message, uParam, lParam ) ;
                   1829:                                
                   1830:                        } else {
                   1831:                        
                   1832:                                uMinChars = (UINT) SendMessage( hWnd, WM_GETTEXT, 2, (LPARAM)szCurVal );
                   1833:                                
                   1834:                                if ( uMinChars == 0 ) {
                   1835:                            
                   1836:                                uCurVal = 0;
                   1837:                                
                   1838:                            } else if ( uMinChars == 1 ) {
                   1839:                            
                   1840:                                uCurVal = szCurVal[0] - '0';
                   1841:                                
                   1842:                            } else if ( uMinChars == 2 ) {
                   1843:                            
                   1844:                                uCurVal  = szCurVal[0] - '0';
                   1845:                                uCurVal *= 10;
                   1846:                                uCurVal  = szCurVal[1] - '0';
                   1847:                            
                   1848:                            } else if ( uMinChars > 2 ) {
                   1849:                                
                   1850:                                uMinChars = 0;
                   1851:                                
                   1852:                                SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)"" );
                   1853:                             
                   1854:                                return( 0 );
                   1855:                                
                   1856:                            }
                   1857:                        
                   1858:                        }
                   1859:                        
                   1860:                        if ( ( uParam == ' ' )                  ||  // space
                   1861:                             ( uParam < '0' || uParam > '9' )   ||  // not a number
                   1862:                             ( uCurVal >= 6  )                      // greater than 59
                   1863:                           ) {
                   1864:                        
                   1865:                                 MessageBeep( MB_OK );
                   1866:                                 
                   1867:                                 return( 0 );
                   1868:                                 
                   1869:                        } else if ( uMinChars < 2 ) {
                   1870:                        
                   1871:                                ++uMinChars;
                   1872:                                
                   1873:                        } else {
                   1874:         
                   1875:                    MessageBeep( MB_OK );
                   1876:                                 
                   1877:                            return( 0 );
                   1878:                         
                   1879:                        }
                   1880:                
                   1881:                break;
                   1882:        
                   1883:        } // switch
                   1884:        
                   1885:        return CallWindowProc( (WNDPROC)lpMinDefProc, hWnd, message, uParam, lParam ) ;
                   1886:        
                   1887: }
                   1888: 
                   1889: 
                   1890: 
                   1891: //===========================================================================
                   1892: // FUNCTION: Refresh()
                   1893: //===========================================================================
                   1894: UINT                           
                   1895: Refresh(UINT Command)
                   1896: {
                   1897: 
                   1898:     static BOOL fOkayToRefresh;
                   1899:        static BOOL     fOkayToRefreshSave;
                   1900:        
                   1901:        switch( Command ) {
                   1902:        
                   1903:                case REFRESH_FALSE:
                   1904:                    
                   1905:                    fOkayToRefresh = FALSE;
                   1906:                    
                   1907:                        break;
                   1908: 
                   1909:                case REFRESH_TRUE:
                   1910:                    
                   1911:                    fOkayToRefresh = TRUE;
                   1912:                    
                   1913:                        break;
                   1914:                        
                   1915:                case REFRESH_QUERY:
                   1916:                    
                   1917:                        return( fOkayToRefresh );    
                   1918:                    
                   1919:                        break;
                   1920:                        
                   1921:                case REFRESH_SAVE:
                   1922:                    
                   1923:                    fOkayToRefreshSave = fOkayToRefresh;
                   1924:                    
                   1925:                        break;
                   1926:                
                   1927:                case REFRESH_RESTORE:
                   1928:                    
                   1929:                    fOkayToRefresh = fOkayToRefreshSave;
                   1930:                    
                   1931:                        break;                  
                   1932:        }
                   1933:        
                   1934:        return( REFRESH_ERROR );
                   1935:                                                
                   1936: }
                   1937: 
                   1938: 
                   1939: 
                   1940: //===========================================================================
                   1941: // FUNCTION: SelectComputerProc()
                   1942: //===========================================================================
                   1943: BOOL APIENTRY SelectComputerProc(
                   1944:         HWND hWnd,         // window handle
                   1945:         UINT message,      // type of message
                   1946:         UINT uParam,       // additional information
                   1947:                LONG lParam)       // additional information
                   1948: {
                   1949: 
                   1950:     DWORD           dwLen = MAXCOMPUTERNAMELEN + 1;
                   1951:     UCHAR           szSelectComputer[MAXCOMPUTERNAMELEN+1];
                   1952:     int             wmEvent;
                   1953:     int             wmId;
                   1954:         
                   1955:     switch (message) {
                   1956: 
                   1957:         case WM_INITDIALOG:
                   1958:             
                   1959:             SendDlgItemMessage( hWnd, IDC_SELECTCOMPUTER, WM_SETFONT, (WPARAM)hFont, 0 );
                   1960: 
                   1961:             if ( !GetComputerName( szSelectComputer, &dwLen ) ) {
                   1962:                                
                   1963:                                        MessageBox( hWnd, "Problem getting computer name.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   1964:                            
                   1965:                        } else {
                   1966:                            
                   1967:                                SetDlgItemText( hWnd, IDC_SELECTCOMPUTER, szSelectComputer );
                   1968: 
                   1969:                        }
                   1970:                        
                   1971:                break;
                   1972: 
                   1973:         case WM_COMMAND:    // message: command from application menu
                   1974: 
                   1975:             // Message packing of uParam and lParam have changed for Win32, let us
                   1976:             // handle the differences in a conditional compilation:
                   1977: 
                   1978:                        wmId    = LOWORD(uParam);
                   1979:                        wmEvent = HIWORD(uParam);
                   1980: 
                   1981:                        switch (wmId) {
                   1982:             
                   1983:                                case IDCANCEL:
                   1984:                                
                   1985:                                        EndDialog( hWnd, IDCANCEL );
                   1986:                                        
                   1987:                                        break;
                   1988:                                        
                   1989:                 case IDOK:
                   1990:                                     
                   1991:                     GetDlgItemText( hWnd, IDC_SELECTCOMPUTER, &szComputerM[2], MAXCOMPUTERNAMELEN );
                   1992:                     
                   1993:                     if ( lstrlen(&szComputerM[2]) > 15 || lstrlen(&szComputerM[2]) == 0 ) {
                   1994:                     
                   1995:                        MessageBox( hWnd, "Computer names are 1 to 15 characters long.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   1996:                        
                   1997:                     } else {
                   1998:                     
                   1999:                            SetDlgItemText( hGlobalhWnd, IDC_COMPUTER, &szComputerM[2] );
                   2000:                            
                   2001:                            szComputerM[0] = '\\';
                   2002:                                        szComputerM[1] = '\\';
                   2003:                                                
                   2004:                                                MultiByteToWideChar(
                   2005:                                                CP_ACP,
                   2006:                                                MB_PRECOMPOSED,
                   2007:                                                szComputerM,
                   2008:                                                -1,
                   2009:                                                szComputerW,
                   2010:                                                MAXCOMPUTERNAMELEN
                   2011:                                                );               
                   2012:                                    
                   2013:                         GlobalComputerName = szComputerW;
                   2014:                                
                   2015:                                Refresh( REFRESH_TRUE );
                   2016:                                    
                   2017:                            EndDialog( hWnd, IDOK );
                   2018:                               
                   2019:                        }
                   2020:                        
                   2021:                     break;
                   2022:             
                   2023:             }
                   2024: 
                   2025:                        break;
                   2026: 
                   2027:     }
                   2028:  
                   2029:     return (0);
                   2030: 
                   2031: }
                   2032: 
                   2033: 
                   2034: 
                   2035: //===========================================================================
                   2036: // FUNCTION: ServiceNotStartedHandler()
                   2037: //=========================================================================== 
                   2038: BOOL 
                   2039: ServiceNotStartedHandler(VOID)
                   2040: {
                   2041: 
                   2042:     BOOL            Done;
                   2043:     SC_HANDLE       schSCManager;
                   2044:     SC_HANDLE       schService;
                   2045:     SERVICE_STATUS  ssServiceStatus;
                   2046:     UCHAR           szService[] = "Schedule";
                   2047:     UCHAR           szTemp[80];
                   2048:     
                   2049:     wsprintf( szTemp, "Schedule service on %s not started.\nWould you like to start it?", &szComputerM[2] );
                   2050:                                         
                   2051:        if ( MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_YESNO ) == IDYES ) {
                   2052: 
                   2053:            schSCManager = OpenSCManager( szComputerM, NULL, SC_MANAGER_ALL_ACCESS );
                   2054:                                    
                   2055:            if ( schSCManager == NULL ) {
                   2056:                                                        
                   2057:                wsprintf( szTemp, "Problem accessing Service Control Manager.\n\nError %d.", GetLastError() );
                   2058:                
                   2059:                MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2060:                    
                   2061:                    return( FALSE );
                   2062:                                    
                   2063:            } else {
                   2064:                                                        
                   2065:                        schService = OpenService( schSCManager, szService, SERVICE_ALL_ACCESS );
                   2066:                                                                
                   2067:                        if ( schService == NULL ) {
                   2068:                                                                
                   2069:                        wsprintf( szTemp, "Problem opening Schedule service.\n\nError %d.", GetLastError() );
                   2070:                        
                   2071:                        MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2072:                                            
                   2073:                        return( FALSE );
                   2074:                    
                   2075:                    } else {
                   2076:                                                                
                   2077:                                if ( StartService( schService, 0, NULL ) == FALSE ) {
                   2078:                                                                        
                   2079:                                wsprintf( szTemp, "Problem starting Schedule service.\n\nError %d.", GetLastError() );
                   2080:                                
                   2081:                                MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2082: 
                   2083:                                        return( FALSE );
                   2084:                                                                                            
                   2085:                            } else {
                   2086:                            
                   2087:                                // wait for service to start
                   2088:                                
                   2089:                                Done = FALSE;
                   2090:                                
                   2091:                                while( !Done ) {
                   2092:                                    
                   2093:                                        if ( QueryServiceStatus( schService, &ssServiceStatus ) == FALSE ) {
                   2094:                                                                                
                   2095:                                                wsprintf( szTemp, "Problem getting service status.\n\nError %d.", GetLastError() );
                   2096:                                                
                   2097:                                                MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2098:                
                   2099:                                                        return( FALSE );
                   2100:                                                        
                   2101:                                                } else {
                   2102:                                                
                   2103:                                                        switch ( ssServiceStatus.dwCurrentState ) {
                   2104:                                                        
                   2105:                                                                case SERVICE_START_PENDING:
                   2106:                                                                        
                   2107:                                                                        Sleep( ssServiceStatus.dwWaitHint );
                   2108:                                                                        
                   2109:                                                                        break;
                   2110:                                                                        
                   2111:                                                                case SERVICE_RUNNING:
                   2112:                                                                    
                   2113:                                                                    Done = TRUE;
                   2114:                                                                    
                   2115:                                                                        break;
                   2116:                                                                        
                   2117:                                                                default:
                   2118:                                                                        
                   2119:                                                                        wsprintf( szTemp, "Unexpected service state.\n\nState %d.", ssServiceStatus.dwCurrentState );
                   2120:                                                
                   2121:                                                                MessageBox( hGlobalhWnd, szTemp, SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2122:                                                                      
                   2123:                                                                Done = TRUE;
                   2124:                                                                      
                   2125:                                                                break;
                   2126:                                                                
                   2127:                                                        }
                   2128:                                                
                   2129:                                                }
                   2130:                                                
                   2131:                                        }
                   2132:                                        
                   2133:                            }
                   2134:                            
                   2135:                        CloseServiceHandle(schService);
                   2136:                
                   2137:                }
                   2138:                
                   2139:                CloseServiceHandle(schSCManager);      
                   2140:            
                   2141:            }           
                   2142: 
                   2143:                SendDlgItemMessage( hGlobalhWnd, IDC_ATCOMMANDS, LB_RESETCONTENT, 0, 0 );
                   2144:                
                   2145:         SendDlgItemMessage( 
                   2146:                hGlobalhWnd, 
                   2147:                IDC_ATCOMMANDS, 
                   2148:                LB_ADDSTRING, 
                   2149:                0, 
                   2150:                (LPARAM)"The Schedule service was started successfully." );             
                   2151:                
                   2152:                MessageBox( 
                   2153:                        hGlobalhWnd, 
                   2154:                        "The Schedule service was started successfully.", 
                   2155:                        SZWINDOWTITLE, 
                   2156:                        MB_OK );
                   2157:                        
                   2158:                return( TRUE ); 
                   2159:        
                   2160:        } else {
                   2161:            
                   2162:            Refresh( REFRESH_FALSE );
                   2163:            
                   2164:                MessageBox( 
                   2165:                        hGlobalhWnd, 
                   2166:                        "The display will not be refreshed automatically.  Chose File, Select Computer to refresh the display.", 
                   2167:                        SZWINDOWTITLE, 
                   2168:                        MB_OK | MB_ICONEXCLAMATION );
                   2169:                
                   2170:        }
                   2171:        
                   2172:        return( FALSE );
                   2173: 
                   2174: }       
                   2175: 
                   2176: 
                   2177: 
                   2178: //===========================================================================
                   2179: // FUNCTION: UpButtonProc()
                   2180: //===========================================================================
                   2181: LRESULT APIENTRY UpButtonProc( HWND hWnd, UINT message, UINT uParam, LONG lParam )
                   2182: {
                   2183:     switch ( message ) {
                   2184:         
                   2185:         case WM_SETFOCUS:
                   2186:                        
                   2187:                        if ( (uParam == (UINT)hHour) || (uParam == (UINT)hMin) || (uParam == (UINT)hAmPm) ) {
                   2188:                                
                   2189:                                hCurrentFocus = (HWND)uParam;
                   2190:                 
                   2191:                 PostMessage( hGlobalAddChg, WM_SPINBUTTON, uParam, (LONG)UP );
                   2192:                                        
                   2193:                        } else {
                   2194: 
                   2195:                                hCurrentFocus = (HWND)uParam;
                   2196:                                        
                   2197:                        }
                   2198:                        
                   2199:                        break;      
                   2200:        
                   2201:        } // switch
                   2202:        
                   2203:        return CallWindowProc( (WNDPROC)lpUpButtonDefProc, hWnd, message, uParam, lParam ) ;
                   2204:        
                   2205: }
                   2206: 
                   2207: 
                   2208: 
                   2209: //===========================================================================
                   2210: // FUNCTION: ValidateAddChangeArguments()
                   2211: //=========================================================================== 
                   2212: BOOL
                   2213: ValidateAddChangeArguments(
                   2214:        HWND hWnd
                   2215:        )
                   2216: {
                   2217: 
                   2218:     SYSTEMTIME              SysTime;
                   2219:     UCHAR                   szAmPm[3];
                   2220:     UINT                    Items[NUMDAYITEMS];
                   2221:     UINT                    NumSelected;
                   2222:     UINT                    i;
                   2223:                
                   2224:        // initialize
                   2225: 
                   2226:     memset( (PBYTE)&GlobalAtInfo, '\0', sizeof(GlobalAtInfo) );
                   2227: 
                   2228:        // command
                   2229: 
                   2230:     SendDlgItemMessage( hWnd, IDC_NEWCOMMAND, WM_GETTEXT, MAXCOMMANDLEN, (LPARAM)szCommandM );
                   2231: 
                   2232:     if ( szCommandM[0] == 0 ) {
                   2233: 
                   2234:         MessageBox(
                   2235:             hWnd,
                   2236:             "Enter a command.",
                   2237:             SZWINDOWTITLE,
                   2238:             MB_OK | MB_ICONEXCLAMATION
                   2239:             );
                   2240:         
                   2241:         SetFocus( GetDlgItem( hWnd, IDC_NEWCOMMAND ) );
                   2242:         
                   2243:         return ( FALSE );
                   2244: 
                   2245:     }  
                   2246: 
                   2247:        MultiByteToWideChar(
                   2248:         CP_ACP,
                   2249:         MB_PRECOMPOSED,
                   2250:         szCommandM,
                   2251:         -1,
                   2252:         szCommandW,
                   2253:         MAXCOMMANDLEN
                   2254:         );
                   2255: 
                   2256:     GlobalAtInfo.Command = szCommandW;
                   2257:     
                   2258:        // hours
                   2259:                         
                   2260:     GlobalAtInfo.JobTime = GetDlgItemInt( hWnd, IDC_HOUR, NULL, FALSE );
                   2261:     
                   2262:     GetDlgItemText( hWnd, IDC_AMPM, (LPTSTR)&szAmPm, sizeof(szAmPm) );
                   2263:     
                   2264:     if ( szAmPm[0] == 'P' || szAmPm[0] == 'p' ) {
                   2265: 
                   2266:        if( GlobalAtInfo.JobTime != 12 ) {
                   2267:        
                   2268:                GlobalAtInfo.JobTime += 12;
                   2269:                
                   2270:        }
                   2271: 
                   2272:     } else if( GlobalAtInfo.JobTime == 12 ) {
                   2273:        
                   2274:                GlobalAtInfo.JobTime = 0;
                   2275:                
                   2276:     }
                   2277:     
                   2278:     
                   2279:     // convert to minutes
                   2280:     
                   2281:        GlobalAtInfo.JobTime *= 60;
                   2282:        
                   2283:        // add minutes
                   2284:        
                   2285:        GlobalAtInfo.JobTime += GetDlgItemInt( hWnd, IDC_MIN, NULL, FALSE );
                   2286:        
                   2287:        // convert to milliseconds
                   2288:        
                   2289:        GlobalAtInfo.JobTime *= 60 * 1000;
                   2290:        
                   2291:        GetLocalTime( &SysTime );
                   2292:        
                   2293:     if ( SendDlgItemMessage( hWnd, IDC_TODAY, BM_GETCHECK, 0, 0 ) ) {
                   2294:      
                   2295:                if ( (DWORD)( (SysTime.wHour * 60 + SysTime.wMinute) * 60 * 1000) >= GlobalAtInfo.JobTime ) {   
                   2296:                
                   2297:                        MessageBox( 
                   2298:                                hWnd, 
                   2299:                                "The time you have selected has already passed.  The command will run tomorrow.", 
                   2300:                                SZWINDOWTITLE, 
                   2301:                 MB_OK | MB_ICONEXCLAMATION
                   2302:                 );
                   2303:                        
                   2304:                }
                   2305:        
                   2306:        }
                   2307:        
                   2308:        if ( SendDlgItemMessage( hWnd, IDC_EVERY, BM_GETCHECK, 0, 0 ) ||
                   2309:             SendDlgItemMessage( hWnd, IDC_NEXT, BM_GETCHECK, 0, 0 )    ) {     
                   2310:        
                   2311:                // day 
                   2312:                // NOTE: I am assuming that this lisbox will always be correct
                   2313:                //       and if you select Today/Tomorrow the proper day is selected.
                   2314:                
                   2315:                NumSelected = SendDlgItemMessage( hWnd, IDC_DAYS, LB_GETSELCOUNT, 0, 0 );
                   2316:                
                   2317:                if ( NumSelected == 0 ) {
                   2318: 
                   2319:                MessageBox(
                   2320:                    hWnd,
                   2321:                    "Select the day(s) this command will run.",
                   2322:                    SZWINDOWTITLE,
                   2323:                    MB_OK | MB_ICONEXCLAMATION
                   2324:                    );
                   2325:                
                   2326:                SetFocus( GetDlgItem( hWnd, IDC_DAYS ) );
                   2327:                
                   2328:                return ( FALSE );
                   2329: 
                   2330:        }       
                   2331: 
                   2332:                SendDlgItemMessage( hWnd, IDC_DAYS, LB_GETSELITEMS, NUMDAYITEMS, (LPARAM)Items );                                               
                   2333:                                                
                   2334:                for( i=0; i<NumSelected; ++i ) {
                   2335:                
                   2336:                        if ( Items[i] > 6 ) {
                   2337:                        
                   2338:                                // days of month
                   2339:                                //0-based, 7 and up are dates (1-31)
                   2340:                
                   2341:                            GlobalAtInfo.DaysOfMonth |= ( 1 << ( Items[i]-7 ) );
                   2342:                            
                   2343:                        } else {
                   2344:                        
                   2345:                            // days of week
                   2346:                            // 0-based, first 7 are days (M-Su)       
                   2347:                
                   2348:                        GlobalAtInfo.DaysOfWeek |= ( 1 << Items[i] );
                   2349:                        
                   2350:                        }       
                   2351:                
                   2352:                }
                   2353:                 
                   2354:                // flags
                   2355: 
                   2356:         if ( SendDlgItemMessage( hWnd, IDC_EVERY, BM_GETCHECK, 0, 0 ) ) {
                   2357: 
                   2358:             GlobalAtInfo.Flags |= JOB_RUN_PERIODICALLY;
                   2359:     
                   2360:         }  
                   2361:        
                   2362:        } else if ( SendDlgItemMessage( hWnd, IDC_TOMORROW, BM_GETCHECK, 0, 0 ) ) { 
                   2363:        
                   2364:                i = SendDlgItemMessage( hWnd, IDC_DAYS, LB_GETCURSEL, 0, 0 );
                   2365:                
                   2366:                if ( i == 0 ) {
                   2367:                                                         
                   2368:                    // set to Sunday
                   2369:                    
                   2370:                        GlobalAtInfo.DaysOfWeek = ( 1 << 6 );
                   2371:                        
                   2372:                } else {
                   2373:                                                           
                   2374:                    // increment to tomorrow                                       
                   2375:                        
                   2376:                        GlobalAtInfo.DaysOfWeek |= ( 1 << i );
                   2377:                        
                   2378:                }
                   2379:                
                   2380:        }
                   2381:            
                   2382:        return( TRUE );
                   2383: 
                   2384: }
                   2385: 
                   2386: 
                   2387: 
                   2388: //===========================================================================
                   2389: // FUNCTION: WINATDlgProc()
                   2390: //===========================================================================
                   2391: BOOL APIENTRY WINATDlgProc(
                   2392:         HWND hWnd,         // window handle
                   2393:         UINT message,      // type of message
                   2394:         UINT uParam,       // additional information
                   2395:                LONG lParam)       // additional information
                   2396: {
                   2397: 
                   2398:     FARPROC         lpAddChangeDlgProc;  // pointer to the "AddChange" function
                   2399:     FARPROC         lpProcSelect;
                   2400:     NET_API_STATUS  status;
                   2401:     int             wmEvent;
                   2402:     int             wmId;
                   2403:     int                                iDlgRetCode;
                   2404:     
                   2405:     switch (message) {
                   2406: 
                   2407:         case WM_INITDIALOG:
                   2408: 
                   2409:             lf.lfEscapement    = 0;
                   2410:             lf.lfOrientation   = 0;
                   2411:             lf.lfOutPrecision  = OUT_DEFAULT_PRECIS;
                   2412:             lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                   2413:             lf.lfHeight        = 14;
                   2414:             lf.lfWidth         = 0; //6; //5
                   2415:             lf.lfWeight        = 0;
                   2416: 
                   2417:             lf.lfItalic        = 0;
                   2418:             lf.lfUnderline     = 0;
                   2419:             lf.lfStrikeOut     = 0;
                   2420: 
                   2421:             lf.lfPitchAndFamily=VARIABLE_PITCH | FF_SWISS;
                   2422: 
                   2423:             hFont = CreateFontIndirect( &lf );
                   2424: 
                   2425:             if ( hFont != NULL ) {
                   2426: 
                   2427:                 SendDlgItemMessage( hWnd, IDC_ATCOMMANDS, WM_SETFONT, (WPARAM)hFont, 1L );
                   2428:                 
                   2429:             } else {
                   2430: 
                   2431:                 MessageBox( hWnd, "Problem creating font.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2432: 
                   2433:             }
                   2434: 
                   2435:             hCursorWait = LoadCursor( NULL, IDC_WAIT );
                   2436: 
                   2437:             if ( !FInitListboxExtents( GetDlgItem( hWnd, IDC_ATCOMMANDS ) ) ) {
                   2438: 
                   2439:                 MessageBox( hWnd, "Scrolling broken", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2440: 
                   2441:             }
                   2442: 
                   2443:             hGlobalhWnd = hWnd;
                   2444: 
                   2445:             // get values from registry                         
                   2446:             
                   2447:             SendMessage(hWnd, WM_COMMAND, IDM_GET_FROM_REGISTRY, 0);
                   2448: 
                   2449:             // set tabstops for commands
                   2450: 
                   2451:             {
                   2452:                 
                   2453:                 UINT Tabs[3] = { 25, 110, 145 };
                   2454: 
                   2455:                 SendDlgItemMessage( hWnd, IDC_ATCOMMANDS, LB_SETTABSTOPS, 3, (LPARAM)Tabs );
                   2456: 
                   2457:             }
                   2458: 
                   2459:                        // get local computer name                 
                   2460:                        
                   2461:                        {
                   2462:                                
                   2463:                                DWORD dwLen = MAXCOMPUTERNAMELEN;
                   2464:                                
                   2465:                                if ( !GetComputerName( &szComputerM[2], &dwLen ) ) {
                   2466:                                
                   2467:                                        MessageBox( hWnd, "Problem getting computer name", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2468:                            
                   2469:                            } else {
                   2470:                            
                   2471:                                    szComputerM[0] = '\\';
                   2472:                                szComputerM[1] = '\\';
                   2473:                                        
                   2474:                                    MultiByteToWideChar(
                   2475:                                        CP_ACP,
                   2476:                                        MB_PRECOMPOSED,
                   2477:                                        szComputerM,
                   2478:                                        -1,
                   2479:                                        szComputerW,
                   2480:                                        MAXCOMMANDLEN
                   2481:                                        );
                   2482:                                                                        
                   2483:                     // set GlobalComputerName for all functions to use
                   2484:                                        // only Select Computer will ever change this value
                   2485:                                                                                                                
                   2486:                     GlobalComputerName = szComputerW;
                   2487:                        
                   2488:                                SendDlgItemMessage( hWnd, IDC_COMPUTER, WM_SETTEXT, 0, (LPARAM)&szComputerM[2]  );
                   2489:                                
                   2490:                        }
                   2491:                 
                   2492:                        }
                   2493:             
                   2494:             // set initial states of buttons to disabled
                   2495:             
                   2496:             EnableWindow( GetDlgItem( hGlobalhWnd, IDC_ADD    ), FALSE );
                   2497:             EnableWindow( GetDlgItem( hGlobalhWnd, IDC_CHANGE ), FALSE );
                   2498:                EnableWindow( GetDlgItem( hGlobalhWnd, IDC_REMOVE ), FALSE );
                   2499:                
                   2500:                // initialize the commands window
                   2501:                
                   2502:                SendDlgItemMessage( hWnd, IDC_ATCOMMANDS, LB_ADDSTRING, 0, (LPARAM)"Initializing" );
                   2503:                
                   2504:                // set up timer to go off very soon after the dlgbox is created
                   2505:                
                   2506:             uTimer = SetTimer( hWnd, 1, 1000, NULL );
                   2507:             fTimer = FIRST_TIME; 
                   2508:             Refresh( REFRESH_TRUE );
                   2509: 
                   2510: 
                   2511:             GlobalMessageHandle = LoadLibrary( "netmsg.dll" );
                   2512: 
                   2513:             if ( GlobalMessageHandle == NULL ) {
                   2514: 
                   2515: ;//                MessagePrint( IDS_LOAD_LIBRARY_FAILURE, GetLastError() );
                   2516: 
                   2517:             }
                   2518: 
                   2519:             break;
                   2520:             
                   2521:         case WM_TIMER:
                   2522:             
                   2523:                        if ( fTimer == FIRST_TIME ) {
                   2524:                        
                   2525:                                uTimer = SetTimer( hWnd, 1, REFRESH_RATE, NULL );
                   2526:                        
                   2527:                                fTimer = !FIRST_TIME;
                   2528:                                
                   2529:                        }
                   2530:                                                                        
                   2531:             if ( Refresh( REFRESH_QUERY ) == TRUE ) {
                   2532:                
                   2533:                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_NOCHANGE );
                   2534:                
                   2535:             }
                   2536:             
                   2537:             break;
                   2538: 
                   2539:         case WM_COMMAND:    // message: command from application menu
                   2540: 
                   2541:             // Message packing of uParam and lParam have changed for Win32, let us
                   2542:             // handle the differences in a conditional compilation:
                   2543: 
                   2544:                        wmId    = LOWORD(uParam);
                   2545:                        wmEvent = HIWORD(uParam);
                   2546: 
                   2547:                        switch (wmId) {
                   2548: 
                   2549:                                case IDC_ATCOMMANDS:
                   2550: 
                   2551:                            if ( LBN_DBLCLK == wmEvent ) {
                   2552: 
                   2553:                                if ( IsWindowEnabled( GetDlgItem( hWnd, IDC_CHANGE ) ) ) {
                   2554:                                        
                   2555:                                        PostMessage( hWnd, WM_COMMAND, IDC_CHANGE, 0 ); 
                   2556:                                
                   2557:                                }
                   2558:                                                        
                   2559:                            }
                   2560:                                                    
                   2561:                                break;
                   2562: 
                   2563:                 case IDC_REFRESH:
                   2564:                     
                   2565:                     if ( Refresh( REFRESH_QUERY ) == TRUE ) {
                   2566:                                                   
                   2567:                            Refresh( REFRESH_FALSE );
                   2568:                            
                   2569:                            hCursorOld = SetCursor( hCursorWait );
                   2570:                            
                   2571:                            status = JobEnum( lParam );
                   2572:        
                   2573:                            SetCursor( hCursorOld );
                   2574:                            
                   2575:                            if ( status == NERR_Success || status == ERROR_SUCCESS ) {
                   2576:                            
                   2577:                                Refresh( REFRESH_TRUE );
                   2578:                                
                   2579:                            }
                   2580:                            
                   2581:                        }
                   2582: 
                   2583:                     break;
                   2584:                                
                   2585:                                case IDC_ADD:
                   2586:                                    
                   2587:                                    Refresh( REFRESH_FALSE );
                   2588:                                    
                   2589:                                    lpAddChangeDlgProc = MakeProcInstance((FARPROC)AddChangeDlgProc, hInstance);
                   2590:                                
                   2591:                                    iDlgRetCode = DialogBoxParam(
                   2592:                                        hInst,
                   2593:                                        "ADDCHANGEDLG",
                   2594:                                        hWnd,
                   2595:                                        (DLGPROC)lpAddChangeDlgProc,
                   2596:                                        IDC_ADD);
                   2597:                                    
                   2598:                                    hGlobalAddChg = NULL;
                   2599:                                    
                   2600:                                    FreeProcInstance(lpAddChangeDlgProc);
                   2601:                                    FreeProcInstance(lpAmPmProc);
                   2602:                                    FreeProcInstance(lpAmPmDefProc);
                   2603:                                    FreeProcInstance(lpHourProc);
                   2604:                                    FreeProcInstance(lpHourDefProc);
                   2605:                                    FreeProcInstance(lpMinProc);
                   2606:                                    FreeProcInstance(lpMinDefProc);     
                   2607:                                    FreeProcInstance(lpDownButtonProc);
                   2608:                                    FreeProcInstance(lpDownButtonDefProc);
                   2609:                                    FreeProcInstance(lpUpButtonProc);
                   2610:                                    FreeProcInstance(lpUpButtonDefProc);
                   2611: 
                   2612:                                    Refresh( REFRESH_TRUE );
                   2613:                                    
                   2614:                                    if ( iDlgRetCode == IDOK ) {
                   2615:                                        
                   2616:                                        SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_BOTTOM );
                   2617:                                        
                   2618:                                    }
                   2619:                                                                
                   2620:                     break;
                   2621:                     
                   2622:                 case IDC_CHANGE:         
                   2623:                        
                   2624:                        Refresh( REFRESH_FALSE );
                   2625:                                                            
                   2626:                     lpAddChangeDlgProc = MakeProcInstance((FARPROC)AddChangeDlgProc, hInstance);
                   2627:                                
                   2628:                                    iDlgRetCode = DialogBoxParam(
                   2629:                                        hInst,
                   2630:                                        "ADDCHANGEDLG",
                   2631:                                        hWnd,
                   2632:                                        (DLGPROC)lpAddChangeDlgProc,
                   2633:                                        IDC_CHANGE);
                   2634:                                    
                   2635:                                    hGlobalAddChg = NULL;
                   2636:                                    
                   2637:                                    FreeProcInstance(lpAddChangeDlgProc);
                   2638:                                    FreeProcInstance(lpAmPmProc);
                   2639:                                    FreeProcInstance(lpAmPmDefProc);
                   2640:                                    FreeProcInstance(lpHourProc);
                   2641:                                    FreeProcInstance(lpHourDefProc);
                   2642:                                    FreeProcInstance(lpMinProc);
                   2643:                                    FreeProcInstance(lpMinDefProc);
                   2644:                                    FreeProcInstance(lpDownButtonProc);
                   2645:                                    FreeProcInstance(lpDownButtonDefProc);
                   2646:                                    FreeProcInstance(lpUpButtonProc);
                   2647:                                    FreeProcInstance(lpUpButtonDefProc);
                   2648:                                    
                   2649:                                        Refresh( REFRESH_TRUE );
                   2650:                                                                            
                   2651:                                    if ( iDlgRetCode == IDOK ) {
                   2652:                                        
                   2653:                                        SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_BOTTOM );
                   2654:                                        
                   2655:                                    }
                   2656: 
                   2657:                     break;
                   2658:                 
                   2659:                 case IDC_REMOVE:
                   2660:                     
                   2661:                     status = JobDel( DEL_ID, hWnd );   
                   2662:                                        
                   2663:                        break;
                   2664:                        
                   2665:                 case IDM_GET_FROM_REGISTRY:
                   2666: 
                   2667:                     RegCreateKeyEx(REG_HKEY,
                   2668:                                    szRegistryPath,
                   2669:                                    0,
                   2670:                                    "",
                   2671:                                    REG_OPTION_NON_VOLATILE,
                   2672:                                    KEY_ALL_ACCESS,
                   2673:                                    NULL,
                   2674:                                    &hkHandle,
                   2675:                                    &dwDisposition);
                   2676: 
                   2677:                     if ( dwDisposition == REG_CREATED_NEW_KEY ) {
                   2678: 
                   2679:                         RegSetValueEx(hkHandle, "dwX", 0, REG_DWORD, (LPBYTE)DWX, sizeof(DWORD));
                   2680:                         RegSetValueEx(hkHandle, "dwY", 0, REG_DWORD, (LPBYTE)DWY, sizeof(DWORD));
                   2681: 
                   2682:                     }
                   2683: 
                   2684:                     {
                   2685:                         DWORD dwType = REG_DWORD;
                   2686:                         DWORD dwSize = sizeof(DWORD);
                   2687: 
                   2688:                         RegQueryValueEx(hkHandle, "dwX", 0, &dwType, (LPBYTE)&dwX, &dwSize);
                   2689:                         RegQueryValueEx(hkHandle, "dwY", 0, &dwType, (LPBYTE)&dwY, &dwSize);
                   2690: 
                   2691:                     }
                   2692: 
                   2693:                     RegCloseKey(hkHandle);
                   2694: 
                   2695:                     {
                   2696:                         RECT Rect;
                   2697: 
                   2698:                         if(!GetWindowRect(hWnd, &Rect)) {
                   2699: 
                   2700:                             MessageBox(
                   2701:                                 hWnd,
                   2702:                                 "Problem getting window coordinates.",
                   2703:                                 SZWINDOWTITLE,
                   2704:                                 MB_OK | MB_ICONEXCLAMATION
                   2705:                                 );
                   2706: 
                   2707:                         } else {
                   2708: 
                   2709:                             dwW = Rect.right  - Rect.left;
                   2710:                             dwH = Rect.bottom - Rect.top;
                   2711: 
                   2712:                         }
                   2713: 
                   2714:                     }
                   2715: 
                   2716:                     MoveWindow(hWnd, (INT)dwX, (INT)dwY, (INT)dwW, (INT)dwH, TRUE);
                   2717: 
                   2718:                     break;
                   2719: 
                   2720:                  case IDM_SAVE_TO_REGISTRY:
                   2721: 
                   2722:                     RegCreateKeyEx(REG_HKEY,
                   2723:                                    szRegistryPath,
                   2724:                                    0,
                   2725:                                    "",
                   2726:                                    REG_OPTION_NON_VOLATILE,
                   2727:                                    KEY_ALL_ACCESS,
                   2728:                                    NULL,
                   2729:                                    &hkHandle,
                   2730:                                    &dwDisposition
                   2731:                                    );
                   2732: 
                   2733:                     {
                   2734:                         RECT Rect;
                   2735: 
                   2736:                         if(!GetWindowRect(hWnd, &Rect)) {
                   2737: 
                   2738:                             dwX = DWX;
                   2739:                             dwY = DWY;
                   2740: 
                   2741:                             MessageBox(
                   2742:                                 hWnd,
                   2743:                                 "Problem getting coordinates.",
                   2744:                                 SZWINDOWTITLE,
                   2745:                                 MB_OK | MB_ICONEXCLAMATION
                   2746:                                 );
                   2747: 
                   2748:                         } else {
                   2749: 
                   2750:                             dwX = Rect.left;
                   2751:                             dwY = Rect.top;
                   2752: 
                   2753:                         }
                   2754: 
                   2755:                     }
                   2756: 
                   2757:                     RegSetValueEx(hkHandle, "dwX", 0, REG_DWORD, (LPBYTE)&dwX, sizeof(DWORD));
                   2758:                     RegSetValueEx(hkHandle, "dwY", 0, REG_DWORD, (LPBYTE)&dwY, sizeof(DWORD));
                   2759: 
                   2760:                     RegCloseKey(hkHandle);
                   2761: 
                   2762:                     break;
                   2763: 
                   2764:                 case IDM_ABOUT:
                   2765:                                            
                   2766:                                        Refresh( REFRESH_SAVE );
                   2767:                     Refresh( REFRESH_FALSE );
                   2768:                     
                   2769:                     if ( ShellAbout( hGlobalhWnd, SZWINDOWTITLE, SZCREDITS, LoadIcon( hInst, (LPSTR)SZAPPTITLE ) ) == -1 ) {
                   2770:                     
                   2771:                        MessageBox( hGlobalhWnd, "Out of memory error.", SZWINDOWTITLE, MB_OK | MB_ICONEXCLAMATION );
                   2772:                        
                   2773:                     }
                   2774:                                        
                   2775:                                        Refresh( REFRESH_RESTORE );
                   2776:                                        
                   2777:                                        break;
                   2778:                 
                   2779:                 case IDM_SELECTCOMPUTER:
                   2780:                     
                   2781:                     Refresh( REFRESH_SAVE );
                   2782:                     Refresh( REFRESH_FALSE );
                   2783:                     
                   2784:                     lpProcSelect = MakeProcInstance((FARPROC)SelectComputerProc, hInst);
                   2785: 
                   2786:                                        iDlgRetCode = DialogBox(hInst,   
                   2787:                                                "SelectComputer",            
                   2788:                                                hWnd,                  
                   2789:                                                (DLGPROC)lpProcSelect);
                   2790: 
                   2791:                                        FreeProcInstance(lpProcSelect);
                   2792:                                                              
                   2793:                     Refresh( REFRESH_TRUE );
                   2794:                                                              
                   2795:                                        if ( iDlgRetCode == IDOK ) {
                   2796:                                        
                   2797:                                                SendMessage( hWnd, WM_COMMAND, IDC_REFRESH, (LPARAM)SCS_TOP );
                   2798:                                                
                   2799:                                        }
                   2800:                                        
                   2801:                        break;
                   2802:                        
                   2803:                 case IDM_EXIT:
                   2804:                 
                   2805:                     Refresh( REFRESH_FALSE );
                   2806:                     FFreeListboxExtents( GetDlgItem( hWnd, IDC_ATCOMMANDS ) );
                   2807:                     ShowWindow( hWnd, SW_RESTORE );
                   2808:                     SendMessage( hWnd, WM_COMMAND, IDM_SAVE_TO_REGISTRY, 0 );
                   2809:                     DeleteObject( hFont );  
                   2810:                     KillTimer( hWnd, 1 );
                   2811:                     EndDialog( hWnd, 0 );
                   2812:                                        
                   2813:                                        break;
                   2814: 
                   2815:                 case IDC_HELP:
                   2816:                     
                   2817:                     if (!WinHelp (hWnd, "WINAT.HLP", HELP_KEY,(DWORD)(LPSTR)"CONTENTS")) {
                   2818:                                                MessageBox (GetFocus(),
                   2819:                                                        "Unable to activate help",
                   2820:                                                        SZWINDOWTITLE, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
                   2821:                     }                     
                   2822:                                        break;
                   2823: 
                   2824:                 case IDM_HELPCONTENTS:
                   2825:                                           
                   2826:                     if (!WinHelp (hWnd, "WINAT.HLP", HELP_KEY,(DWORD)(LPSTR)"CONTENTS")) {
                   2827:                                                MessageBox (GetFocus(),
                   2828:                                                        "Unable to activate help",
                   2829:                                                        SZWINDOWTITLE, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
                   2830:                     }
                   2831: 
                   2832:                     break;
                   2833: 
                   2834:                                case IDM_HELPSEARCH:
                   2835: 
                   2836:                     if (!WinHelp(hWnd, "WINAT.HLP", HELP_PARTIALKEY, (DWORD)(LPSTR)"")) {
                   2837:                                                MessageBox (GetFocus(),
                   2838:                                                        "Unable to activate help",
                   2839:                                                        SZWINDOWTITLE, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
                   2840:                     }
                   2841: 
                   2842:                     break;
                   2843: 
                   2844:                                case IDM_HELPHELP:
                   2845: 
                   2846:                     if(!WinHelp(hWnd, (LPSTR)NULL, HELP_HELPONHELP, 0)) {
                   2847:                                                MessageBox (GetFocus(),
                   2848:                                                        "Unable to activate help",
                   2849:                                                        SZWINDOWTITLE, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
                   2850:                     }
                   2851: 
                   2852:                     break;
                   2853: 
                   2854:             }
                   2855: 
                   2856:             break;
                   2857: 
                   2858:         case WM_CLOSE:
                   2859:         case WM_ENDSESSION:
                   2860: 
                   2861:             SendMessage(hWnd, WM_COMMAND, IDM_EXIT, 0);
                   2862: 
                   2863:             break;
                   2864: 
                   2865:     }
                   2866: 
                   2867:     return (0);
                   2868: 
                   2869: }
                   2870: 
                   2871: 
                   2872: 
                   2873: //===========================================================================
                   2874: // FUNCTION: WinMain()
                   2875: //===========================================================================
                   2876: int APIENTRY WinMain(
                   2877:        HANDLE hInstance,
                   2878:        HANDLE hPrevInstance,
                   2879:        LPSTR lpCmdLine,
                   2880:        int nCmdShow)
                   2881: {
                   2882: 
                   2883:     FARPROC   lpWINATDlgProc;
                   2884:     WNDCLASS  wc;
                   2885: 
                   2886:     hInst       = hInstance;
                   2887: 
                   2888:        // Fill in window class structure with parameters that describe the
                   2889:        // main window.
                   2890: 
                   2891:     wc.style         = CS_HREDRAW | CS_VREDRAW;
                   2892:     wc.lpfnWndProc   = (WNDPROC)DefDlgProc;
                   2893:     wc.cbClsExtra    = 0;
                   2894:     wc.cbWndExtra    = DLGWINDOWEXTRA;
                   2895:     wc.hInstance     = hInstance;
                   2896:     wc.hIcon         = LoadIcon (hInstance, szAppName);
                   2897:     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
                   2898:     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
                   2899:     wc.lpszMenuName  = szAppName;
                   2900:     wc.lpszClassName = szAppName;
                   2901: 
                   2902:     // Register the window class
                   2903: 
                   2904:     RegisterClass(&wc);
                   2905: 
                   2906: 
                   2907:     //
                   2908:     // this program is only a single dialog box
                   2909:     //
                   2910: 
                   2911:     lpWINATDlgProc = MakeProcInstance((FARPROC)WINATDlgProc, hInstance);
                   2912: 
                   2913:     DialogBox(hInstance,
                   2914:         "WINATDLG",
                   2915:         0,
                   2916:         (DLGPROC)lpWINATDlgProc
                   2917:         );
                   2918: 
                   2919:     FreeProcInstance(lpWINATDlgProc);
                   2920:                                    
                   2921:     return 0;
                   2922: 
                   2923: }
                   2924: 

unix.superglobalmegacorp.com

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