home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Html / Server / Samples / WebRun / runcpl.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-04  |  34.4 KB  |  1,271 lines

  1. /****************************************************************************
  2. *
  3. *
  4. *    PROGRAM: WebRunCpl.c
  5. *
  6. *    PURPOSE: Configuration Control Panel Applet for Web Runner Sample
  7. *
  8. *  Exports:
  9. *
  10. *  LONG CALLBACK CPlApplet(HWND, UINT, LONG, LONG)
  11. *
  12. *   This is the entry point that Control Panel requires so that it can
  13. *   interact with our applet.
  14. *
  15. ****************************************************************************/
  16.  
  17. // Registry Keys and Values for Web Runner parameters
  18. #define RUNNER_REG_KEY            "Software\\WebRunner\\Commands"
  19. #define RUNNER_REG_COMMAND_VALUE  "HTMLListBoxLines"
  20. #define RUNNER_REG_PARAM_KEY      "Software\\WebRunner\\Parameters"
  21. #define RUNNER_REG_MODE_VALUE     "Mode"   // 1 = Admin, 2 = Normal
  22. #define RUNNER_REG_FILEPATH_VALUE "FilePath"
  23. #define DEFAULT_FILEPATH          "C:\\HTTP\\RUNNER.HTM"
  24.  
  25. // HTML
  26. #define PRESTRING                 "<option>"
  27. #define POSTSTRING                "</option>"
  28.  
  29. // Standard Includes
  30. #include <windows.h>
  31. #include <cpl.h>
  32. #include <commdlg.h>
  33. #include "runcpl.h"
  34. #include "resource.h"
  35.  
  36. // Function Defines
  37. void FillListBox(HWND, HKEY);
  38.  
  39. // Control Panel Applet Information
  40. typedef struct tagApplets
  41. {
  42.     int icon;           // icon resource identifier
  43.     int namestring;     // name-string resource identifier
  44.     int descstring;     // description-string resource identifier
  45.     int dlgtemplate;    // dialog box template resource identifier
  46.     DLGPROC dlgfn;      // dialog box procedure
  47. } APPLETS;
  48.  
  49. APPLETS RunApplet =
  50. {
  51.     RUN_ICON, RUN_NAME, RUN_DESC, RUN_DLG, RunDlgProc,
  52. };
  53.  
  54. HANDLE  hModule = NULL;
  55. char    lpFilePath[MAX_PATH];
  56. DWORD   cbFilePathLength = sizeof(lpFilePath);
  57. char    szCtlPanel[30];
  58. HKEY    hKey;
  59.  
  60. /****************************************************************************
  61. *
  62. *    FUNCTION: DllMain(PVOID, ULONG, PCONTEXT)
  63. *
  64. *    PURPOSE: Win 32 Initialization DLL
  65. *
  66. *    COMMENTS:
  67. *
  68. *
  69. ****************************************************************************/
  70.  
  71. BOOL WINAPI DllMain(
  72. IN PVOID hmod,
  73. IN ULONG ulReason,
  74. IN PCONTEXT pctx OPTIONAL)
  75. {
  76.     if (ulReason != DLL_PROCESS_ATTACH)
  77.     {
  78.         return TRUE;
  79.     }
  80.     else
  81.     {
  82.         hModule = hmod;
  83.     }
  84.  
  85.     return TRUE;
  86.  
  87.     UNREFERENCED_PARAMETER(pctx);
  88. }
  89.  
  90.  
  91. /****************************************************************************
  92. *
  93. *    FUNCTION: InitRuncplApplet(HWND)
  94. *
  95. *    PURPOSE: loads the caption string for the Control Panel
  96. *
  97. *    COMMENTS:
  98. *
  99. *
  100. ****************************************************************************/
  101.  
  102. BOOL InitRuncplApplet (HWND hwndParent)
  103. {
  104.     LoadString (hModule, CPCAPTION, szCtlPanel, sizeof(szCtlPanel));
  105.  
  106.     return TRUE;
  107.  
  108.     UNREFERENCED_PARAMETER(hwndParent);
  109. }
  110.  
  111.  
  112. /****************************************************************************
  113. *
  114. *    FUNCTION: TermRunApplet()
  115. *
  116. *    PURPOSE: termination procedure for the stereo applets
  117. *
  118. *    COMMENTS:
  119. *
  120. *
  121. ****************************************************************************/
  122.  
  123. void TermRunApplet()
  124. {
  125.     return;
  126. }
  127.  
  128.  
  129. /****************************************************************************
  130. *
  131. *    FUNCTION: CPlApplet(HWND, UINT, LONG, LONG)
  132. *
  133. *    PURPOSE: Processes messages for control panel applets
  134. *
  135. *    COMMENTS:
  136. *
  137. *
  138. ****************************************************************************/
  139. LONG CALLBACK CPlApplet (hwndCPL, uMsg, lParam1, lParam2)
  140. HWND hwndCPL;       // handle of Control Panel window
  141. UINT uMsg;          // message
  142. LONG lParam1;       // first message parameter
  143. LONG lParam2;       // second message parameter
  144. {
  145.     LPNEWCPLINFO lpNewCPlInfo;
  146.     static iInitCount = 0;
  147.             
  148.     switch (uMsg) {
  149.         case CPL_INIT:              // first message
  150.             if (!iInitCount)
  151.             {
  152.                 if (!InitRuncplApplet(hwndCPL))
  153.                     return FALSE;
  154.             }
  155.             iInitCount++;
  156.             return TRUE;
  157.  
  158.         case CPL_GETCOUNT:          // second message
  159.             return (LONG)1;
  160.             break;
  161.  
  162.         case CPL_NEWINQUIRE:        // third message
  163.             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
  164.  
  165.             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
  166.             lpNewCPlInfo->dwFlags = 0;
  167.             lpNewCPlInfo->dwHelpContext = 0;
  168.             lpNewCPlInfo->lData = 0;
  169.             lpNewCPlInfo->hIcon = LoadIcon (hModule,
  170.                 (LPCTSTR) MAKEINTRESOURCE(RunApplet.icon));
  171.             lpNewCPlInfo->szHelpFile[0] = '\0';
  172.  
  173.             LoadString (hModule, RunApplet.namestring,
  174.                         lpNewCPlInfo->szName, 32);
  175.  
  176.             LoadString (hModule, RunApplet.descstring,
  177.                         lpNewCPlInfo->szInfo, 64);
  178.             break;
  179.  
  180.         case CPL_SELECT:            // application icon selected
  181.             break;
  182.  
  183.  
  184.         case CPL_DBLCLK:            // application icon double-clicked
  185.             
  186.             // Start our dialog box
  187.             DialogBox (hModule,
  188.                        MAKEINTRESOURCE(RunApplet.dlgtemplate),
  189.                        hwndCPL,
  190.                        RunApplet.dlgfn);
  191.             break;
  192.  
  193.          case CPL_STOP:              // sent once per app. before CPL_EXIT
  194.             break;
  195.  
  196.          case CPL_EXIT:              // sent once before FreeLibrary called
  197.             iInitCount--;
  198.             if (!iInitCount)
  199.                 TermRunApplet();
  200.             break;
  201.  
  202.          default:
  203.             break;
  204.     }
  205.     return 0;
  206. }
  207.  
  208. /****************************************************************************
  209. *
  210. *    FUNCTION: RunDlgProc
  211. *
  212. *    PURPOSE: Processes messages sent to our dialog box.
  213. *
  214. *    COMMENTS:
  215. *
  216. *
  217. ****************************************************************************/
  218. BOOL APIENTRY RunDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
  219. {
  220.     DWORD OpenType;
  221.     DWORD cbCommandSize = 0;
  222.     char lpNewCommand[256];
  223.     DWORD cbCommandString = 0;
  224.     LPSTR lpCommandString = NULL;
  225.     HKEY hParamKey;
  226.     BOOL AdminEnabled;
  227.     DWORD cbBuffSize = sizeof(AdminEnabled);
  228.  
  229.     switch (message)
  230.     {
  231.  
  232.         case WM_INITDIALOG:
  233.             // Disable Remove Button until something is selected
  234.             // in our listbox.
  235.             EnableWindow(GetDlgItem(hDlg, ID_REMOVE), FALSE);
  236.             
  237.             // Open our registry key (or create it if it
  238.             // doesn't already exist)
  239.             if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
  240.                            RUNNER_REG_KEY, 
  241.                            0, 
  242.                            "WEBRUNNER",
  243.                            REG_OPTION_NON_VOLATILE,
  244.                            KEY_READ | KEY_WRITE, 
  245.                            NULL,
  246.                            &hKey,
  247.                            &OpenType) != ERROR_SUCCESS)
  248.             {
  249.                 MessageBox(hDlg, "Could not open or create Web Runner \
  250.                                   Registry entries", "Error", MB_OK);
  251.                 EndDialog(hDlg, FALSE);
  252.                 return TRUE;
  253.             }
  254.  
  255.             // Fill listbox with command already entered
  256.             FillListBox(hDlg, hKey);
  257.  
  258.             // Are we in Admin mode?  Check Registry
  259.             if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
  260.                            RUNNER_REG_PARAM_KEY, 
  261.                            0, 
  262.                            "WEBRUNNER",
  263.                            REG_OPTION_NON_VOLATILE,
  264.                            KEY_READ | KEY_WRITE, 
  265.                            NULL,
  266.                            &hParamKey,
  267.                            &OpenType) != ERROR_SUCCESS)
  268.             {
  269.                 MessageBox(hDlg, 
  270.                     "Could not open or create Web Runner Registry Key", 
  271.                     "Web Runner", 
  272.                     MB_OK);
  273.                 return TRUE;
  274.             }
  275.  
  276.             if (RegQueryValueEx(hParamKey,
  277.                                 RUNNER_REG_MODE_VALUE,
  278.                                 NULL,
  279.                                 NULL,
  280.                                 (LPBYTE)&AdminEnabled,
  281.                                 &cbBuffSize) != ERROR_SUCCESS)
  282.             {
  283.                 // We are not in Admin mode
  284.                 AdminEnabled = FALSE;
  285.  
  286.                 if (RegSetValueEx(hParamKey,
  287.                                   RUNNER_REG_MODE_VALUE,
  288.                                   0,
  289.                                   REG_BINARY,
  290.                                   (LPBYTE)&AdminEnabled,
  291.                                   sizeof(AdminEnabled)) != ERROR_SUCCESS)
  292.                 {
  293.                     MessageBox(hDlg, 
  294.                                "Could not open or create \
  295.                                 Web Runner Registry Balue", 
  296.                                "Web Runner", 
  297.                                MB_OK);
  298.                     return TRUE;
  299.                 }
  300.             }
  301.             if (AdminEnabled)
  302.             {
  303.                 // We are in Admin mode, grey everything
  304.                 EnableWindow(GetDlgItem(hDlg, ID_COMMANDLIST), FALSE);
  305.                 EnableWindow(GetDlgItem(hDlg, ID_NEWCOMMAND), FALSE);
  306.                 EnableWindow(GetDlgItem(hDlg, ID_ADD), FALSE);
  307.                 EnableWindow(GetDlgItem(hDlg, ID_BROWSE), FALSE);
  308.                 CheckDlgButton(hDlg, ID_ADMIN, 1);
  309.             }
  310.             else
  311.             {
  312.                 // We are not in Admin mode setup everything
  313.                 EnableWindow(GetDlgItem(hDlg, ID_COMMANDLIST), TRUE);
  314.                 EnableWindow(GetDlgItem(hDlg, ID_NEWCOMMAND), TRUE);
  315.                 EnableWindow(GetDlgItem(hDlg, ID_ADD), TRUE);
  316.                 EnableWindow(GetDlgItem(hDlg, ID_BROWSE), TRUE);
  317.                 CheckDlgButton(hDlg, ID_ADMIN, 0);
  318.             }
  319.             
  320.             // Get Filepath of HTML file
  321.             if (RegQueryValueEx(hParamKey,
  322.                                 RUNNER_REG_FILEPATH_VALUE,
  323.                                 NULL,
  324.                                 NULL,
  325.                                 (LPBYTE)lpFilePath,
  326.                                 &cbFilePathLength) != ERROR_SUCCESS)
  327.             {
  328.                 // Registry value doesn't exist, create it
  329.                 lstrcpy(lpFilePath, DEFAULT_FILEPATH);
  330.                 cbFilePathLength = lstrlen(lpFilePath) + 1;
  331.  
  332.                 if (RegSetValueEx(hParamKey,
  333.                                   RUNNER_REG_FILEPATH_VALUE,
  334.                                   0,
  335.                                   REG_BINARY,
  336.                                   (LPBYTE)lpFilePath,
  337.                                   cbFilePathLength) != ERROR_SUCCESS)
  338.                 {
  339.                     MessageBox(hDlg, 
  340.                         "Could not open or create Web Runner \
  341.                          Registry Value", "Web Runner", MB_OK);
  342.                     return TRUE;
  343.                 }
  344.  
  345.                 // Prompt them for initial path
  346.                 PostMessage(hDlg, WM_COMMAND, ID_CHANGE, 0);
  347.             }
  348.  
  349.             // Display the HTML file path
  350.             SetDlgItemText(hDlg, ID_FILEPATH, lpFilePath);
  351.             return (TRUE);
  352.  
  353.         case WM_CLOSE:
  354.             // Bye bye
  355.             EndDialog(hDlg, TRUE);
  356.             return TRUE;
  357.  
  358.         case WM_COMMAND:      
  359.             switch(LOWORD(wParam))
  360.             {
  361.             case ID_DONE:
  362.                 // Bye bye
  363.                 EndDialog(hDlg, TRUE);
  364.                 return TRUE;
  365.  
  366.             case ID_CHANGE:
  367.                 // They want to change the html file path
  368.                 DialogBox (hModule,
  369.                            MAKEINTRESOURCE(FILE_DIALOG),
  370.                            hDlg,
  371.                            FileDlgProc);
  372.                 SetDlgItemText(hDlg, ID_FILEPATH, lpFilePath);
  373.                 return TRUE;
  374.                 
  375.             case ID_BROWSE:
  376.                 if (HIWORD(wParam) == BN_CLICKED)
  377.                 {
  378.                     // Browse for new command to add to list
  379.                     char lpFileName[256];
  380.  
  381.                     GetDlgItemText(hDlg, 
  382.                                    ID_NEWCOMMAND, 
  383.                                    lpNewCommand, 
  384.                                    sizeof(lpNewCommand));
  385.                     if (!Browse(hDlg,           // Parent Window
  386.                                 lpNewCommand,   // Start at specified location
  387.                                 lpFileName,     // Actual file selected
  388.                                 TRUE))          // Indicates Command Browse
  389.                         return FALSE;
  390.                     SetDlgItemText(hDlg, ID_NEWCOMMAND, lpNewCommand);
  391.                     return FALSE;
  392.                 }
  393.                 break;
  394.  
  395.             case ID_ADMIN:
  396.                 if (HIWORD(wParam) == BN_CLICKED)
  397.                 {
  398.                     // Request to switch admin mode, open Registry key
  399.                     if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
  400.                                    RUNNER_REG_PARAM_KEY, 
  401.                                    0, 
  402.                                    "WEBRUNNER",
  403.                                    REG_OPTION_NON_VOLATILE,
  404.                                    KEY_READ | KEY_WRITE, 
  405.                                    NULL,
  406.                                    &hParamKey,
  407.                                    &OpenType) != ERROR_SUCCESS)
  408.                     {
  409.                         MessageBox(hDlg, 
  410.                             "Could not open or create Web \
  411.                              Runner Registry entries", "Error", MB_OK);
  412.                         return TRUE;
  413.                     }
  414.  
  415.                     if (SendDlgItemMessage(hDlg, 
  416.                                            ID_ADMIN, 
  417.                                            BM_GETCHECK, 
  418.                                            0, 0) == 1)
  419.                     {
  420.                         // Entered Admin mode...grey out everything
  421.                         EnableWindow(GetDlgItem(hDlg, ID_COMMANDLIST), FALSE);
  422.                         EnableWindow(GetDlgItem(hDlg, ID_NEWCOMMAND), FALSE);
  423.                         EnableWindow(GetDlgItem(hDlg, ID_ADD), FALSE);
  424.                         EnableWindow(GetDlgItem(hDlg, ID_BROWSE), FALSE);
  425.  
  426.                         AdminEnabled = TRUE;
  427.  
  428.  
  429.                     }
  430.                     else
  431.                     {
  432.                         // Changed to normal mode...turn controls back on
  433.                         EnableWindow(GetDlgItem(hDlg, ID_COMMANDLIST), TRUE);
  434.                         EnableWindow(GetDlgItem(hDlg, ID_NEWCOMMAND), TRUE);
  435.                         EnableWindow(GetDlgItem(hDlg, ID_ADD), TRUE);
  436.                         EnableWindow(GetDlgItem(hDlg, ID_BROWSE), TRUE);
  437.  
  438.                         AdminEnabled = FALSE;
  439.                     }
  440.                     // Set registry value appropriately
  441.                     if (RegSetValueEx(hParamKey,
  442.                                       RUNNER_REG_MODE_VALUE,
  443.                                       0,
  444.                                       REG_BINARY,
  445.                                       (BYTE *)&AdminEnabled,
  446.                                       sizeof(AdminEnabled)) != ERROR_SUCCESS)
  447.                     {
  448.                         MessageBox(hDlg, 
  449.                             "Error writing to Registry", 
  450.                             "Web Runner", 
  451.                             MB_OK);
  452.                     }
  453.                     RegCloseKey(hParamKey);
  454.  
  455.                     // Change the html page to reflect current mode
  456.                     
  457.                     // Function requires formatted command list...read it
  458.                     // from the registry
  459.                     RegQueryValueEx(hKey,
  460.                                     RUNNER_REG_COMMAND_VALUE,
  461.                                     NULL,
  462.                                     NULL,
  463.                                     NULL,
  464.                                     &cbCommandString); // Get the size first.
  465.  
  466.                     lpCommandString = LocalAlloc(LPTR, cbCommandString);
  467.                     
  468.                     RegQueryValueEx(hKey,
  469.                                     RUNNER_REG_COMMAND_VALUE,
  470.                                     NULL,
  471.                                     NULL,
  472.                                     lpCommandString,
  473.                                     &cbCommandString);
  474.  
  475.                     // Write the html file
  476.                     if (!PageCreate(AdminEnabled,        // Admin Mode?
  477.                                     lpFilePath,            // path of file
  478.                                     lpCommandString))   // List of commands
  479.                     {
  480.                         MessageBox(hDlg, 
  481.                             "HTML File could not be written", 
  482.                             "Web Runner", 
  483.                             MB_OK);
  484.                         PostMessage(hDlg, WM_COMMAND, ID_CHANGE, 0);
  485.                     }
  486.                     LocalFree(lpCommandString);
  487.  
  488.                     return FALSE;
  489.                 }
  490.             case ID_COMMANDLIST:
  491.                 switch(HIWORD(wParam))
  492.                 {
  493.                 case LBN_SELCHANGE:
  494.                     {
  495.                         // When an item is highlighted, enable the Remove
  496.                         // button and put the command in the New Command
  497.                         // edit control
  498.                         DWORD iIndex;
  499.  
  500.                         // Enable Remove button
  501.                         EnableWindow(GetDlgItem(hDlg, ID_REMOVE), TRUE);
  502.                         
  503.                         // Set New Command text to listbox selection
  504.                         iIndex = SendDlgItemMessage(hDlg, 
  505.                                                     ID_COMMANDLIST, 
  506.                                                     LB_GETCURSEL, 
  507.                                                     0,0);
  508.  
  509.                         SendDlgItemMessage(hDlg, 
  510.                                            ID_COMMANDLIST, 
  511.                                            LB_GETTEXT, 
  512.                                            (WPARAM)iIndex, 
  513.                                            (LPARAM)lpNewCommand);
  514.                         SetDlgItemText(hDlg, ID_NEWCOMMAND, lpNewCommand);
  515.                         return FALSE;
  516.                     }
  517.                 case LBN_SELCANCEL:
  518.                     // If nothing is selected grey out Remove button
  519.                     EnableWindow(GetDlgItem(hDlg, ID_REMOVE), FALSE);
  520.                     return FALSE;
  521.                 }
  522.                 return FALSE;
  523.  
  524.             case ID_ADD:
  525.                 // Add New Command to list
  526.  
  527.                 // Get the New Command
  528.                 cbCommandSize = GetDlgItemText(hDlg, 
  529.                                                ID_NEWCOMMAND, 
  530.                                                lpNewCommand, 
  531.                                                sizeof(lpNewCommand));
  532.                 
  533.                 // If nothing is entered, don't do anything
  534.                 if (cbCommandSize == 0) break;
  535.  
  536.                 // Get the current list from the registry
  537.                 if (RegQueryValueEx(hKey,
  538.                                 RUNNER_REG_COMMAND_VALUE,
  539.                                 NULL,
  540.                                 NULL,
  541.                                 NULL,
  542.                                 &cbCommandString) != ERROR_SUCCESS)
  543.                 {
  544.                     MessageBox(hDlg, 
  545.                         "Error Reading Memory", 
  546.                         "Web Runner", 
  547.                         MB_OK);
  548.                     return (FALSE);
  549.                 }
  550.  
  551.                 // We need enough memory for current command 
  552.                 // string + command prefix + new command + command
  553.                 // suffix
  554.                 cbCommandString = cbCommandString 
  555.                                   + cbCommandSize 
  556.                                   + lstrlen(PRESTRING) 
  557.                                   + lstrlen(POSTSTRING);
  558.  
  559.                 lpCommandString = LocalAlloc(LPTR, cbCommandString);
  560.                 
  561.                 if (lpCommandString == NULL)
  562.                 {
  563.                     MessageBox(hDlg, 
  564.                         "Error allocating memory", 
  565.                         "Web Runner", 
  566.                         MB_OK);
  567.                     return (FALSE);
  568.                 }
  569.                 
  570.                 // Get the current command list
  571.                 if (RegQueryValueEx(hKey,
  572.                     RUNNER_REG_COMMAND_VALUE,
  573.                     NULL,
  574.                     NULL,
  575.                     lpCommandString,
  576.                     &cbCommandString) != ERROR_SUCCESS)
  577.                 {
  578.                     MessageBox(hDlg, 
  579.                         "Error reading registry", 
  580.                         "Web Runner", 
  581.                         MB_OK);
  582.                     LocalFree(lpCommandString);
  583.                     return (FALSE);
  584.                 }
  585.                 
  586.                 // Add prefix, new command, and suffix to current
  587.                 // command string
  588.                 lstrcat(lpCommandString, PRESTRING);
  589.                 lstrcat(lpCommandString, lpNewCommand);
  590.                 lstrcat(lpCommandString, POSTSTRING);
  591.                 cbCommandString = lstrlen(lpCommandString) 
  592.                                   + 1; // Don't forget ending NULL!
  593.  
  594.                 // Set Registry Value
  595.                 if (RegSetValueEx(hKey,
  596.                                   RUNNER_REG_COMMAND_VALUE,
  597.                                   0,
  598.                                   REG_SZ,
  599.                                   lpCommandString,
  600.                                   cbCommandString) != ERROR_SUCCESS)
  601.                 {
  602.                     MessageBox(hDlg, 
  603.                         "Error writing to registry", 
  604.                         "Web Runner", 
  605.                         MB_OK);
  606.                     LocalFree(lpCommandString);
  607.                     return (FALSE);
  608.                 }
  609.                 
  610.                 // Add the new command to the listbox
  611.                 SendDlgItemMessage(hDlg, 
  612.                                    ID_COMMANDLIST,
  613.                                    LB_ADDSTRING,
  614.                                    0,
  615.                                    (LPARAM)lpNewCommand);
  616.  
  617.                 // Clear the New Command Edit Control
  618.                 SetDlgItemText(hDlg, ID_NEWCOMMAND, "");
  619.  
  620.                 // Update the html file
  621.                 if (!PageCreate(FALSE,                  // User Mode
  622.                                 lpFilePath,            // path of file
  623.                                 lpCommandString))   // List of commands
  624.                 {
  625.                     MessageBox(hDlg, 
  626.                         "HTML File could not be written", 
  627.                         "Web Runner", 
  628.                         MB_OK);
  629.                     PostMessage(hDlg, WM_COMMAND, ID_CHANGE, 0);
  630.                 }
  631.  
  632.                 return (TRUE);
  633.  
  634.             case ID_REMOVE:
  635.                 {
  636.                     // Remove the currently selected item from 
  637.                     // the command list
  638.  
  639.                     DWORD iIndex;
  640.                     char lpRemoveCommand[257];
  641.                     char *lpBeginPtr, *lpEndPtr;
  642.  
  643.                     // Get the index of the current selection
  644.                     iIndex = SendDlgItemMessage(hDlg, 
  645.                                                 ID_COMMANDLIST, 
  646.                                                 LB_GETCURSEL, 
  647.                                                 0,0);
  648.                     if (iIndex == LB_ERR)
  649.                     {
  650.                         // Nothing selected...just act like nothing happened
  651.                         return (FALSE);
  652.                     }
  653.                     
  654.                     // Get the text of the item we are removing
  655.                     SendDlgItemMessage(hDlg, 
  656.                                        ID_COMMANDLIST, 
  657.                                        LB_GETTEXT, 
  658.                                        (WPARAM)iIndex, 
  659.                                        (LPARAM)lpRemoveCommand);
  660.                     
  661.                     // Go ahead and delete the item from the listbox now
  662.                     SendDlgItemMessage(hDlg,
  663.                                        ID_COMMANDLIST,
  664.                                        LB_DELETESTRING,
  665.                                        (WPARAM)iIndex,
  666.                                        0);
  667.  
  668.                     // Also grey out the Remove button until something
  669.                     // else is selected
  670.                     EnableWindow(GetDlgItem(hDlg, ID_REMOVE), FALSE);
  671.  
  672.                     // Get size of current command string
  673.                     if (RegQueryValueEx(hKey,
  674.                                         RUNNER_REG_COMMAND_VALUE,
  675.                                         NULL,
  676.                                         NULL,
  677.                                         NULL,
  678.                                         &cbCommandString) != ERROR_SUCCESS)
  679.                     {
  680.                         MessageBox(hDlg, 
  681.                             "Error Reading Registry", 
  682.                             "Web Runner", 
  683.                             MB_OK);
  684.                         return (FALSE);
  685.                     }
  686.                     
  687.                     // Allocate memory to read current command string
  688.                     lpCommandString = LocalAlloc(LPTR, cbCommandString);
  689.                     if (lpCommandString == NULL)
  690.                     {
  691.                         MessageBox(hDlg, 
  692.                             "Error Allocating Memory", 
  693.                             "Web Runner", 
  694.                             MB_OK);
  695.                         return (FALSE);
  696.                     }
  697.  
  698.                     // Read current command string from registry
  699.                     if (RegQueryValueEx(hKey,
  700.                                         RUNNER_REG_COMMAND_VALUE,
  701.                                         NULL,
  702.                                         NULL,
  703.                                         lpCommandString,
  704.                                         &cbCommandString) != ERROR_SUCCESS)
  705.                     {
  706.                         MessageBox(hDlg, 
  707.                                    "Error Reading Registry", 
  708.                                    "Web Runner", 
  709.                                    MB_OK);
  710.                         LocalFree(lpCommandString);
  711.                         return (FALSE);
  712.                     }
  713.  
  714.                     // Set lpBeginPtr to beginning of command in command list
  715.                     lpBeginPtr = strstr(lpCommandString, lpRemoveCommand);
  716.                     // Reset lpBeginPtr to start of command's prefix
  717.                     lpBeginPtr -= lstrlen(PRESTRING);
  718.                     // Set lpEndPtr to prefix of next command
  719.                     lpEndPtr = lpBeginPtr 
  720.                                + lstrlen(PRESTRING) 
  721.                                + lstrlen(lpRemoveCommand) 
  722.                                + lstrlen(POSTSTRING);
  723.                     // Copy remainder of command list over command
  724.                     lstrcpy(lpBeginPtr, lpEndPtr);
  725.                     // Get length of what's left (plus terminating NULL)
  726.                     cbCommandString = lstrlen(lpCommandString) + 1;
  727.                     // Write new list to the registry
  728.                     if (RegSetValueEx(hKey,
  729.                                       RUNNER_REG_COMMAND_VALUE,
  730.                                       0,
  731.                                       REG_SZ,
  732.                                       lpCommandString,
  733.                                       cbCommandString) != ERROR_SUCCESS)
  734.                     {
  735.                         MessageBox(hDlg, 
  736.                             "Error writing to Registry", 
  737.                             "Web Runner", 
  738.                             MB_OK);
  739.                         LocalFree(lpCommandString);
  740.                         return (FALSE);
  741.                     }
  742.                     // Update the html file
  743.                     if (!PageCreate(FALSE,                  // User Mode
  744.                                     lpFilePath,            // path of file
  745.                                     lpCommandString))   // List of commands
  746.                     {
  747.                         MessageBox(hDlg, 
  748.                             "HTML File could not be written", 
  749.                             "Web Runner", 
  750.                             MB_OK);
  751.                         PostMessage(hDlg, WM_COMMAND, ID_CHANGE, 0);
  752.                     }
  753.                     LocalFree(lpCommandString);
  754.                     break;
  755.                 }
  756.             }
  757.             break;
  758.     }
  759.     return (FALSE);
  760. }
  761.  
  762. /****************************************************************************
  763. *
  764. *    FUNCTION: FillListBox
  765. *
  766. *    PURPOSE: Reads command list from the registry, parses it, and then
  767. *             fills the listbox control with the entries
  768. *
  769. *    COMMENTS: The way HTML fills a listbox is by passing a string of the
  770. *              form <output> listboxstring </output> for each item to be 
  771. *               displayed in the listbox.  In order to minimize registry
  772. *               queries we store the entire command in a single registry
  773. *               value.  This takes some parsing when modifying it, but
  774. *               modification is a relatively infrequent event compared to
  775. *               reading the string which happens every time somehow queries
  776. *               our page.
  777. *
  778. *
  779. ****************************************************************************/
  780. void FillListBox(HWND hDlg, // Handle to our dialog
  781.                  HKEY hKey) // Open handle to the commandlist registry key
  782. {
  783.     DWORD cbCommandString = 0;
  784.     char * lpCommandString = NULL;
  785.     char *lpCmdBegin, *lpCmdEnd;
  786.  
  787.     // Get size of command list
  788.     if (RegQueryValueEx(hKey,
  789.                     RUNNER_REG_COMMAND_VALUE,
  790.                     NULL,
  791.                     NULL,
  792.                     NULL,
  793.                     &cbCommandString) != ERROR_SUCCESS)
  794.     {
  795.         // Could not read Registry key...set it
  796.         if(RegSetValueEx(hKey,
  797.                       RUNNER_REG_COMMAND_VALUE,
  798.                       0,
  799.                       REG_SZ,
  800.                       "",
  801.                       1) != ERROR_SUCCESS)
  802.         {
  803.             MessageBox(NULL, 
  804.                        "Error setting registry key", 
  805.                        "Web Runner", 
  806.                        MB_OK);
  807.             return;
  808.         }
  809.     }
  810.  
  811.     if (cbCommandString == 0)
  812.     {
  813.         MessageBox(hDlg, 
  814.                    "There are currently no commands configured", 
  815.                    "Web Runner", 
  816.                    MB_OK);
  817.         return;
  818.     }
  819.  
  820.     // Allocate memory to read command list
  821.     lpCommandString = LocalAlloc(LPTR, cbCommandString);
  822.     if (lpCommandString == NULL)
  823.     {
  824.         MessageBox(hDlg, "Error Allocating Memory", "Web Runner", MB_OK);
  825.         return;
  826.     }
  827.     // Read command list
  828.     if (RegQueryValueEx(hKey,
  829.                         RUNNER_REG_COMMAND_VALUE,
  830.                         NULL,
  831.                         NULL,
  832.                         lpCommandString,
  833.                         &cbCommandString) != ERROR_SUCCESS)
  834.     {
  835.         // Could not read Registry key...set it
  836.         if(RegSetValueEx(hKey,
  837.                       RUNNER_REG_COMMAND_VALUE,
  838.                       0,
  839.                       REG_SZ,
  840.                       "",
  841.                       1) != ERROR_SUCCESS)
  842.         {
  843.             MessageBox(NULL, 
  844.                        "Error setting registry key", 
  845.                        "Web Runner", 
  846.                        MB_OK);
  847.         }
  848.         LocalFree(lpCommandString);
  849.         return;
  850.     }
  851.     
  852.     // Set lpCmdBegin to the first prefix in the command list
  853.     lpCmdBegin = strstr(lpCommandString, PRESTRING);
  854.     
  855.     // Loop while we can still find a prefix (which means
  856.     // we have more commands).
  857.     while (lpCmdBegin)
  858.     {
  859.         // Move lpCmdBegin to actual beginning of current command
  860.         lpCmdBegin += lstrlen(PRESTRING);
  861.         // Move lpCmdEnd to end of the current command
  862.         lpCmdEnd = strstr(lpCmdBegin, POSTSTRING);
  863.         if (lpCmdEnd == NULL)
  864.         {
  865.             // Registry is misconfigured...clear it out
  866.             if(RegSetValueEx(hKey,
  867.                           RUNNER_REG_COMMAND_VALUE,
  868.                           0,
  869.                           REG_SZ,
  870.                           "",
  871.                           1) != ERROR_SUCCESS)
  872.             {
  873.                 MessageBox(hDlg, 
  874.                            "Error setting registry key", 
  875.                            "Web Runner", 
  876.                            MB_OK);
  877.                 LocalFree(lpCommandString);
  878.                 return;
  879.             }
  880.         }
  881.         // Put NULL at begginning of command suffix
  882.         // so that our string terminates at the end
  883.         // of the actual command.
  884.         *lpCmdEnd = '\0';
  885.         // Add it to the listbox
  886.         SendDlgItemMessage(hDlg, 
  887.                            ID_COMMANDLIST, 
  888.                            LB_ADDSTRING, 
  889.                            0, 
  890.                            (LPARAM)lpCmdBegin);
  891.         // Find next command prefix
  892.         lpCmdBegin = strstr(++lpCmdEnd, PRESTRING);
  893.     }  // end of while more commands to list
  894.  
  895.     LocalFree(lpCommandString);
  896. }
  897.                 
  898. /****************************************************************************
  899. *
  900. *    FUNCTION: FileDlgProc
  901. *
  902. *    PURPOSE: Processes messages sent File Dialog
  903. *
  904. *    COMMENTS:
  905. *
  906. *    Prompts the user for the full path of the HTML file that we will
  907. *    be creating.
  908. *
  909. ****************************************************************************/
  910. BOOL APIENTRY FileDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
  911. {
  912.     HKEY hParamKey;
  913.     BOOL AdminEnabled;
  914.     DWORD cbBuffSize = sizeof(AdminEnabled);
  915.     DWORD cbCommandString;
  916.     LPSTR lpCommandString;
  917.  
  918.     
  919.     switch (message)
  920.     {
  921.  
  922.     case WM_INITDIALOG:
  923.         // Put current path in the edit control
  924.         SetDlgItemText(hDlg, ID_FILEPATH, lpFilePath);
  925.         return (TRUE);
  926.  
  927.     case WM_COMMAND:      
  928.         switch(LOWORD(wParam))
  929.         {
  930.         case IDOK:
  931.             // Get the string
  932.             GetDlgItemText(hDlg, ID_FILEPATH, lpFilePath, sizeof(lpFilePath));
  933.             // Open (or create if necessary) the parameters registry key
  934.             if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
  935.                            RUNNER_REG_PARAM_KEY, 
  936.                            0, 
  937.                            "WEBRUNNER",
  938.                            REG_OPTION_NON_VOLATILE,
  939.                            KEY_READ | KEY_WRITE, 
  940.                            NULL,
  941.                            &hParamKey,
  942.                            NULL) != ERROR_SUCCESS)
  943.             {
  944.                 MessageBox(hDlg, 
  945.                     "Could not open or create Web Runner Registry Key", 
  946.                     "Error", 
  947.                     MB_OK);
  948.                 return TRUE;
  949.             }
  950.             
  951.             // See if we are in Admin mode
  952.             if (RegQueryValueEx(hParamKey,
  953.                                 RUNNER_REG_MODE_VALUE,
  954.                                 NULL,
  955.                                 NULL,
  956.                                 (LPBYTE)&AdminEnabled,
  957.                                 &cbBuffSize) != ERROR_SUCCESS)
  958.             {
  959.                 AdminEnabled = FALSE;
  960.  
  961.                 if (RegSetValueEx(hParamKey,
  962.                                   RUNNER_REG_MODE_VALUE,
  963.                                   0,
  964.                                   REG_BINARY,
  965.                                   (LPBYTE)&AdminEnabled,
  966.                                   sizeof(AdminEnabled)) != ERROR_SUCCESS)
  967.                 {
  968.                     MessageBox(hDlg, 
  969.                         "Could not open or create Web Runner Registry Balue", 
  970.                         "Web Runner", 
  971.                         MB_OK);
  972.                     return TRUE;
  973.                 }
  974.             }
  975.             
  976.             // Get size of command list
  977.             RegQueryValueEx(hKey,
  978.                             RUNNER_REG_COMMAND_VALUE,
  979.                             NULL,
  980.                             NULL,
  981.                             NULL,
  982.                             &cbCommandString);
  983.  
  984.             lpCommandString = LocalAlloc(LPTR, cbCommandString);
  985.             // Read command list
  986.             RegQueryValueEx(hKey,
  987.                             RUNNER_REG_COMMAND_VALUE,
  988.                             NULL,
  989.                             NULL,
  990.                             lpCommandString,
  991.                             &cbCommandString);
  992.  
  993.             // Create the html page file
  994.             if (!PageCreate(AdminEnabled,     // Admin mode?
  995.                             lpFilePath,       // Path of html file
  996.                             lpCommandString)) // Command List
  997.             {
  998.                 MessageBox(hDlg, 
  999.                            "File could not be written", 
  1000.                            "Web Runner", 
  1001.                            MB_OK);
  1002.                 return FALSE;
  1003.             }
  1004.  
  1005.             LocalFree(lpCommandString);
  1006.  
  1007.             // Set the html file path in registry
  1008.             if (RegSetValueEx(hParamKey,
  1009.                                 RUNNER_REG_FILEPATH_VALUE,
  1010.                                 0,
  1011.                                 REG_SZ,
  1012.                                 (LPBYTE)lpFilePath,
  1013.                                 lstrlen(lpFilePath) + 1) != ERROR_SUCCESS)
  1014.             {
  1015.                 MessageBox(hDlg, 
  1016.                            "Could not set Web Runner Registry Value", 
  1017.                            "Web Runner", 
  1018.                            MB_OK);
  1019.                 return TRUE;
  1020.             }
  1021.  
  1022.             EndDialog(hDlg, TRUE);
  1023.             return TRUE;
  1024.  
  1025.         case IDCANCEL:
  1026.             // Normally we don't care if you cancel here, but
  1027.             // if we don't have a location for the html file
  1028.             // then we won't let you leave until you give us one.
  1029.  
  1030.             // Open the parameters key
  1031.             if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
  1032.                            RUNNER_REG_PARAM_KEY, 
  1033.                            0, 
  1034.                            "WEBRUNNER",
  1035.                            REG_OPTION_NON_VOLATILE,
  1036.                            KEY_READ | KEY_WRITE, 
  1037.                            NULL,
  1038.                            &hParamKey,
  1039.                            NULL) != ERROR_SUCCESS)
  1040.             {
  1041.                 MessageBox(hDlg, 
  1042.                            "Could not open or create Web Runner Registry Key", 
  1043.                            "Error", 
  1044.                            MB_OK);
  1045.                 EndDialog(hDlg, FALSE);
  1046.                 return TRUE;
  1047.             }
  1048.  
  1049.             // See if there is a filepath yet
  1050.             if (RegQueryValueEx(hParamKey,
  1051.                                 RUNNER_REG_FILEPATH_VALUE,
  1052.                                 NULL,
  1053.                                 NULL,
  1054.                                 (LPBYTE)lpFilePath,
  1055.                                 &cbFilePathLength) != ERROR_SUCCESS)
  1056.             {
  1057.                 // No filepath...you can't leave! HA HA HA!
  1058.                 MessageBox(hDlg, 
  1059.                            "You must specify an HTML filepath for Web Runner", 
  1060.                            "Web Runner", 
  1061.                            MB_OK);
  1062.                 return (FALSE);
  1063.             }
  1064.             EndDialog(hDlg, TRUE);
  1065.             return TRUE;
  1066.  
  1067.         case ID_BROWSE:
  1068.             {
  1069.                 // Let them browse for where they want to put the file
  1070.                 char lpFileName[MAX_PATH];
  1071.  
  1072.                 // Initializes commond browse dialog with current value
  1073.                 GetDlgItemText(hDlg, 
  1074.                                ID_FILEPATH, 
  1075.                                lpFilePath, 
  1076.                                sizeof(lpFilePath));
  1077.                 if (Browse(hDlg,        // Parent Window
  1078.                            lpFilePath,  // Initial path
  1079.                            lpFileName,  // returns actual File
  1080.                            FALSE))      // Indicates browsing for HTML file
  1081.                     // Set the path edit control with result
  1082.                     SetDlgItemText(hDlg, ID_FILEPATH, lpFilePath);
  1083.  
  1084.             }
  1085.  
  1086.             break;
  1087.         }
  1088.     }
  1089.     return FALSE;
  1090. }
  1091.  
  1092. /****************************************************************************
  1093. *
  1094. *    FUNCTION: PageCreate
  1095. *
  1096. *    PURPOSE: Creates the HTML page file
  1097. *
  1098. *     PARAMETERS:
  1099. *         BOOL bMode       - TRUE indicates we are in Admin mode and the
  1100. *                              page provides client with an edit box to type
  1101. *                               in the command they want to execute
  1102. *                             FALSE indicates we are in Normal mode which means
  1103. *                               the client gets a listbox of commands that they
  1104. *                               can select to execute.  They cannot execute any
  1105. *                               other commands
  1106. *         CHAR * szFileName - This is the full path of the HTML file we are
  1107. *                             going to create.
  1108. *         CHAR * ListBox    - This is the command list in preformatted HTML
  1109. *                             listbox format
  1110. *
  1111. *    COMMENTS:
  1112. *
  1113. *
  1114. ****************************************************************************/
  1115. BOOL PageCreate (BOOL bMode,     CHAR * szFileName, CHAR * ListBox)
  1116. {
  1117.     // Mode is TRUE for admin, FALSE for user.
  1118.     HANDLE hFile;
  1119.     CHAR Buffer[4096] = "";
  1120.     DWORD dSize, dWritten;
  1121.     SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, FALSE};
  1122.  
  1123.     if  ( !(hFile = CreateFile (szFileName, 
  1124.                                 GENERIC_WRITE, 
  1125.                                 FILE_SHARE_READ, 
  1126.                                 &sa, 
  1127.                                 CREATE_ALWAYS, 
  1128.                                 FILE_ATTRIBUTE_NORMAL, NULL) ))
  1129.             return FALSE;
  1130.  
  1131.  
  1132.     lstrcpy (Buffer, "<head><title>WebRunner</title></head>\n<body>\
  1133.                 <h1>Welcome to WebRunner.</h1><hr><h4>Mode:    ");
  1134.  
  1135.     if (  bMode  ) 
  1136.     {
  1137.         // We are in Admin mode...right the admin mode htmp file
  1138.         lstrcat (Buffer, "administrator</h4><br><h2>To run your command \
  1139.                           please enter it here:</h2><p> \
  1140.                           <form action=\"runner.dll\" method=get> \
  1141.                           <INPUT NAME=\"COMMAND\" VALUE=\"\" > \
  1142.                           <BR><input type=\"submit\" value=\"Submit Entry\"> \
  1143.                           <input type=\"reset\" value=\"Reset Form\"> \
  1144.                           </form><p><h2>Output:</h2><p><hr><pre>");
  1145.         dSize=lstrlen(Buffer);
  1146.         if (!WriteFile(hFile, 
  1147.                       (LPCVOID) Buffer, 
  1148.                       dSize,  
  1149.                       &dWritten, 
  1150.                       NULL)) return FALSE;
  1151.     }
  1152.     else
  1153.     { 
  1154.          // List Box User mode.
  1155.         lstrcat (Buffer, "user</h4><br><h2>Please choose command to run:</h2>\
  1156.                           <p><form action=\"runner.dll\" method=get> \
  1157.                           <SELECT NAME=\"COMMAND\" SIZE=3>");
  1158.          dSize=lstrlen(Buffer);
  1159.         if (!WriteFile(hFile, 
  1160.                        (LPCVOID)Buffer, 
  1161.                        dSize,  
  1162.                        &dWritten, 
  1163.                        NULL)) return FALSE;
  1164.  
  1165.         // We don't know size of string for registry.
  1166.         // just print it without coping to the buffer.
  1167.          dSize=lstrlen(ListBox);
  1168.         if (!WriteFile(hFile, 
  1169.                        (LPCVOID)ListBox, 
  1170.                        dSize,  
  1171.                        &dWritten, 
  1172.                        NULL)) return FALSE;
  1173.         
  1174.         lstrcpy(Buffer, "<p></SELECT><input type=\"submit\" \
  1175.                          value=\"Submit Entry\"> \
  1176.                          <input type=\"reset\" value=\"Reset Form\"> \
  1177.                          </form><p><h2>Output:</h2><p><hr>");
  1178.  
  1179.         dSize=lstrlen(Buffer);
  1180.         if ( ! WriteFile(hFile, 
  1181.                          (LPCVOID)Buffer, 
  1182.                          dSize,  
  1183.                          &dWritten, 
  1184.                          NULL)) return FALSE;
  1185.     }
  1186.      
  1187.     if (!FlushFileBuffers(hFile))   return FALSE;
  1188.     if (!CloseHandle(hFile))  return FALSE;
  1189.  
  1190.     return TRUE;
  1191. }
  1192.  
  1193. /****************************************************************************
  1194. *
  1195. *    FUNCTION: Browse
  1196. *
  1197. *    PURPOSE: Uses Common File Open Dialog to specify htmp file or file
  1198. *             for our command list
  1199. *
  1200. *     PARAMETERS:
  1201. *         HWND Gee          - Parent Window
  1202. *         CHAR * szFuleName - This is the full path of the HTML file we are
  1203. *                             going to create.
  1204. *         CHAR * szFileName - This is the command list in preformatted HTML
  1205. *                             listbox format
  1206. *         BOOL bMode        - TRUE: Look for commands to fill command list
  1207. *                             FALSE: Look for HTMP file location
  1208. *
  1209. *    COMMENTS:
  1210. *
  1211. *
  1212. ****************************************************************************/
  1213. BOOL Browse (HWND Gee, CHAR * szFullName, CHAR * szFileName, BOOL bMode)
  1214. {
  1215.  
  1216.    // Mode will specify if we are browesing when we do one
  1217.    // of following:
  1218.    // 1. Look for commands:      bMode = TRUE
  1219.    // 2. Create *.htm file bMode = FALSE;
  1220.  
  1221.     OPENFILENAME   ofn= {0};
  1222.     CHAR szFile[256]="";       // filename string
  1223.     CHAR szFileTitle[256];  // file-title string
  1224.     CHAR szFilter [256];        // filter string
  1225.     CHAR chReplace;         // strparator for szFilter
  1226.     UINT uResourceID; 
  1227.     int i, cbString;        // integer count variables
  1228.  
  1229.     
  1230.  
  1231.     if ( bMode ) 
  1232.          // We are looking for commands.
  1233.          uResourceID =  IDS_FILTERSTRING;
  1234.     else
  1235.         // We are looking for   html file
  1236.         uResourceID =  IDS_FILTERSTRING_HTML;
  1237.  
  1238.  
  1239.     // Get file filter string
  1240.     cbString = LoadString(hModule, uResourceID, szFilter, sizeof(szFilter));
  1241.     chReplace = szFilter[cbString - 1];
  1242.     for (i = 0; szFilter[i] != '\0'; i++)
  1243.     {
  1244.         if (szFilter[i] == chReplace)
  1245.             szFilter[i] = '\0';
  1246.     }
  1247.  
  1248.     // fill common dialog structure
  1249.     ofn.lpstrTitle = "Browse";
  1250.     ofn.lStructSize = sizeof(OPENFILENAME);
  1251.     ofn.hwndOwner = Gee;           
  1252.     ofn.lpstrFilter = szFilter;
  1253.     ofn.nFilterIndex = 1;
  1254.     ofn.lpstrFile = szFile;
  1255.     ofn.nMaxFile = sizeof(szFile);
  1256.     ofn.lpstrFileTitle = szFileTitle;
  1257.     ofn.nMaxFileTitle = sizeof(szFileTitle);
  1258.     ofn.lpstrInitialDir = szFullName;
  1259.     ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NONETWORKBUTTON;
  1260.  
  1261.  
  1262.     if (!GetOpenFileName (&ofn)) 
  1263.         return FALSE;
  1264.     else
  1265.     {
  1266.         lstrcpy (szFullName, ofn.lpstrFile);
  1267.         lstrcpy (szFileName, ofn.lpstrFileTitle);
  1268.         return TRUE;
  1269.     }
  1270. }
  1271.