home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / winsock / fingd100 / src / dialogs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  15.2 KB  |  683 lines

  1. // Contents ---------------------------------------------------------------
  2. //
  3. //   dialogs.c -- Dialog functions
  4. //
  5. //   Version 1.0, a Windows Socket Finger Daemon
  6. //
  7. //   Copyright (C) Frederick W. Bent 1994
  8. //   All rights reserved.
  9. //
  10. //
  11. // Description
  12. //
  13. //
  14. // Ends -------------------------------------------------------------------
  15.  
  16. // History ----------------------------------------------------------------
  17. //
  18. // 6/28/94  1.0  Fred Bent    Wrote this thing
  19. //
  20. // Ends -------------------------------------------------------------------
  21.  
  22. // Interface Dependencies -------------------------------------------------
  23.  
  24. #define STRICT
  25.  
  26. #include <windows.h>
  27. #include <windowsx.h>
  28. #include <commdlg.h>
  29. #include <ctl3d.h>
  30. #include "fingerd.h"
  31. #include "strlib.h"
  32. #include "file.h"
  33.  
  34. #pragma warn -par
  35. // End Interface Dependencies ---------------------------------------------
  36.  
  37. char szFileSpec[MAX_PATH];
  38. char szFileName[MAX_PATH];
  39. int  wFileAttr = DDL_DIRECTORY;
  40.  
  41. // External Declarations --------------------------------------------------
  42.  
  43. extern    SOCKET      sListen;    // awaits connection requests
  44. extern    char szNetworkClass[];        // class name of network window
  45. extern      char szAppName[];
  46. extern    char szLocalHostName[];
  47.  
  48. extern    HWND    hwndMain;      // handle of main window
  49. extern    HWND    hwndNetwork;   // our invisible network "window"
  50. extern    HINSTANCE    hInst;         // our main instance
  51.  
  52. extern    char szLocalFile[MAX_PATH];            // filename
  53. extern       char szFileDir[MAX_PATH];
  54. extern      char szHelpFileName[MAX_PATH];
  55. extern    int  iDebugLevel;
  56. extern      BOOL bOnlySnark;
  57.  
  58.  
  59. // End External Declarations ----------------------------------------------
  60.  
  61.  
  62. // Server Implementation --------------------------------------------------
  63.  
  64. // Window Function
  65.  
  66.     LRESULT DoMenuAbout(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  67.  
  68. // Summary ----------------------------------------------------------------
  69. //
  70. //     Respond to "About..." menu selection by invoking the "About"
  71. //    dialog box.
  72. //
  73. // Parameters
  74. //
  75. //    hWnd    Handle of the window.
  76. //
  77. //    Msg    Message.
  78. //
  79. //    wParam    First message paramter.
  80. //
  81. //    lParam    Second message parameter.
  82. //
  83. // Ends -------------------------------------------------------------------
  84.  
  85.     {
  86.         DLGPROC lpProcAbout;
  87.  
  88.         lpProcAbout = (DLGPROC) MakeProcInstance((FARPROC)AboutDlgProc, hInst);
  89.         DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  90.         FreeProcInstance((FARPROC)lpProcAbout);
  91.  
  92.         return(FALSE);
  93.     }
  94.  
  95.  
  96. // Windows Function
  97.  
  98.     LRESULT DoMenuHelp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  99.  
  100. // Summary ----------------------------------------------------------------
  101. //
  102. //     Respond to "Help" menu selection by invoking the error dialog box
  103. //    dialog box.
  104. //
  105. // Parameters
  106. //
  107. //    hWnd    Handle of the window.
  108. //
  109. //    Msg    Message.
  110. //
  111. //    wParam    First message paramter.
  112. //
  113. //    lParam    Second message parameter.
  114. //
  115. // Ends -------------------------------------------------------------------
  116.  
  117.     {
  118.  
  119.        WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  120.  
  121. //        MessageBox(hWnd, "Help not yet implemented.", szAppName, MB_ICONINFORMATION | MB_OK );
  122.  
  123.         return(FALSE);
  124.     }
  125.  
  126. // Windows Function
  127.  
  128.     LRESULT DoMenuExit(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  129.  
  130. // Summary ----------------------------------------------------------------
  131. //
  132. //     Respond to "Help" menu selection by invoking the error dialog box
  133. //    dialog box.
  134. //
  135. // Parameters
  136. //
  137. //    hWnd    Handle of the window.
  138. //
  139. //    Msg    Message.
  140. //
  141. //    wParam    First message paramter.
  142. //
  143. //    lParam    Second message parameter.
  144. //
  145. // Ends -------------------------------------------------------------------
  146.  
  147.     {
  148.         SendMessage(hWnd, WM_CLOSE, 0, 0L);
  149.  
  150.         return(FALSE);
  151.     }
  152.  
  153.  
  154. // Dialog Box Function
  155.  
  156.     BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  157.  
  158. // Summary ----------------------------------------------------------------
  159. //
  160. //    The callback function for the "About" dialog box.
  161. //
  162. // Parameters
  163. //
  164. //    hWnd    Handle of the window.
  165. //
  166. //    Msg    Message.
  167. //
  168. //    wParam    First message paramter.
  169. //
  170. //    lParam    Second message parameter.
  171. //
  172. // Returns
  173. //
  174. //    BOOL    TRUE if the message was processed, otherwise FALSE (zero)
  175. //        if the message was not processed.
  176. //
  177. // Ends -------------------------------------------------------------------
  178.  
  179.     {
  180.         switch(Msg)
  181.         {
  182.             default: return FALSE;
  183.  
  184.             case WM_INITDIALOG:
  185.                             return TRUE;
  186.  
  187.             case WM_SYSCOLORCHANGE:
  188. #ifdef USE_CTL3D
  189.                 Ctl3dColorChange();
  190. #endif
  191.                 break;
  192.  
  193.             case WM_COMMAND:
  194.             {
  195.                 switch(wParam)
  196.                 {
  197.                 case IDOK:
  198.                 case IDCANCEL:
  199.                     EndDialog(hDlg, TRUE);
  200.                     break;
  201.  
  202.                 default : return FALSE;
  203.                 }
  204.             } // WM_COMMAND
  205.         }
  206.         return TRUE;
  207.     }
  208.  
  209. // Window Function
  210.  
  211.     LRESULT DoMenuOptions(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  212.  
  213. // Summary ----------------------------------------------------------------
  214. //
  215. //     Respond to "About..." menu selection by invoking the "About"
  216. //    dialog box.
  217. //
  218. // Parameters
  219. //
  220. //    hWnd    Handle of the window.
  221. //
  222. //    Msg    Message.
  223. //
  224. //    wParam    First message paramter.
  225. //
  226. //    lParam    Second message parameter.
  227. //
  228. // Ends -------------------------------------------------------------------
  229.  
  230.     {
  231.         DLGPROC lpProcOptions;
  232.  
  233.         lpProcOptions = (DLGPROC) MakeProcInstance((FARPROC)DlgProc, hInst);
  234.         DialogBox(hInst, "DLGFINGERSRV", hWnd, lpProcOptions);
  235.         FreeProcInstance((FARPROC)lpProcOptions);
  236.  
  237.         return(FALSE);
  238.     }
  239.  
  240.  
  241. // Dialog Box Function
  242.  
  243.     BOOL CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  244.  
  245. // Summary ----------------------------------------------------------------
  246. //
  247. //     Respond to "Options..." menu selection by invoking the "Options"
  248. //    dialog box.
  249. //
  250. // Parameters
  251. //
  252. //    hWnd    Handle of the window.
  253. //
  254. //    Msg    Message.
  255. //
  256. //    wParam    First message paramter.
  257. //
  258. //    lParam    Second message parameter.
  259. //
  260. // Returns
  261. //
  262. //    BOOL    TRUE if the message was processed, otherwise FALSE (zero)
  263. //        if the message was not processed.
  264. //
  265. // Ends -------------------------------------------------------------------
  266.  
  267.     {
  268.         switch (Msg)
  269.         {
  270.         default:
  271.             return FALSE;
  272.  
  273.         case WM_SYSCOLORCHANGE:
  274. #ifdef USE_CTL3D
  275.             Ctl3dColorChange();
  276. #endif
  277.             break;
  278.  
  279.         case WM_INITDIALOG:
  280.         {
  281.             iDebugLevel = GetPrivateProfileInt( SECTION_MAIN
  282.                     , ENTRY_DEBUG
  283.                     , DEBUG_OFF
  284.                     , (LPCSTR) INI_FILE);
  285.  
  286.             if ( iDebugLevel == 0 )
  287.                 CheckRadioButton(hDlg,IDR_NORMAL, IDR_DEBUG, IDR_NORMAL);
  288.             else
  289.                 CheckRadioButton(hDlg,IDR_NORMAL, IDR_DEBUG, IDR_DEBUG);
  290.  
  291.             SetDlgItemText(hDlg, IDE_PATH, (LPSTR) szLocalFile);
  292. //            SetDlgItemText(hDlg, IDE_HOSTNAME, (LPSTR) "localhost");
  293.                         SetDlgItemText(hDlg, IDE_HOSTNAME, (LPSTR) szLocalHostName);
  294.             SetDlgItemText(hDlg, IDE_DIR, (LPSTR) szFileDir);
  295.             DlgGetLogStrings(hDlg, IDL_LOG, MAXITEMS);
  296.             bOnlySnark = GetPrivateProfileInt( SECTION_MAIN
  297.                     , ENTRY_ONLYSNARK
  298.                     , FALSE
  299.                     , (LPCSTR) INI_FILE);
  300.  
  301.             CheckDlgButton(hDlg, IDR_ONLYSNARK, bOnlySnark);
  302.  
  303.             EnableWindow(GetDlgItem(hDlg, IDB_DIR), FALSE);
  304.             break;
  305.         } // WM_INITDIALOG
  306.  
  307.         case WM_COMMAND:
  308.         {
  309.             switch(wParam)
  310.             {
  311.             case IDOK:
  312.                 if (iDebugLevel == 0)
  313.                 {
  314.                     WritePrivateProfileString(SECTION_MAIN
  315.                         , ENTRY_DEBUG
  316.                         , (LPSTR) "0"
  317.                         , (LPSTR) INI_FILE);
  318.                 } else {
  319.                     WritePrivateProfileString(SECTION_MAIN
  320.                         , ENTRY_DEBUG
  321.                         , (LPSTR) "1"
  322.                         , (LPSTR) INI_FILE);
  323.                 }
  324.  
  325.                 bOnlySnark = IsDlgButtonChecked(hDlg, IDR_ONLYSNARK);
  326.                 if ( bOnlySnark )
  327.                 {
  328.                     WritePrivateProfileString(SECTION_MAIN
  329.                         , ENTRY_ONLYSNARK
  330.                         , (LPSTR) "1"
  331.                         , (LPSTR) INI_FILE);
  332.                 } else {
  333.                     WritePrivateProfileString(SECTION_MAIN
  334.                         , ENTRY_ONLYSNARK
  335.                         , (LPSTR) "0"
  336.                         , (LPSTR) INI_FILE);
  337.                 }
  338.  
  339.                 WritePrivateProfileString(SECTION_MAIN
  340.                     , ENTRY_DEFAULTFILE
  341.                     , (LPSTR) szLocalFile
  342.                     , (LPSTR) INI_FILE);
  343.  
  344.  
  345.                 WritePrivateProfileString(SECTION_MAIN
  346.                     , ENTRY_DIR
  347.                     , (LPSTR) szFileDir
  348.                     , (LPSTR) INI_FILE);
  349.  
  350.                 EndDialog(hDlg,TRUE);
  351.                 break;
  352.  
  353.             case IDCANCEL:
  354.                 EndDialog(hDlg,TRUE);
  355.                 break;
  356.  
  357.             case IDR_NORMAL:
  358.                 iDebugLevel = 0;
  359.                 break;
  360.  
  361.             case IDR_DEBUG:
  362.                 iDebugLevel = 1;
  363.                 break;
  364.  
  365.             case IDB_PATH:
  366.                             FileOpen(hDlg);
  367.                 SetDlgItemText(hDlg, IDE_PATH, (LPSTR) szLocalFile);
  368.                 break;
  369.  
  370.             case IDE_DIR:
  371.             {
  372.                 switch(HIWORD(lParam))
  373.                 {
  374.                                 case EN_CHANGE:
  375.                     GetDlgItemText(hDlg, IDE_DIR, szFileDir, MAX_PATH);
  376.                     break;
  377.                 case EN_KILLFOCUS:
  378.                     if ( VerifyDir(szFileDir) )
  379.                                             Whine(hDlg, szFileDir);
  380. //                        OkMsgBox("Finger Dir", "Invalid Directory\n\n%s", (LPSTR)szFileDir);
  381.                     break;
  382.                                 }
  383.                         }
  384.             break;
  385.  
  386. /*            case IDB_DIR:
  387.                 DoFindDirDlg(hDlg, Msg, wParam, lParam);
  388. //                DlgDirList(hDlg, szFileDir, NULL, IDE_DIR,  DDL_DIRECTORY);
  389. //                SetDlgItemText(hDlg, IDE_DIR, (LPSTR) szFileDir);
  390.                 break;
  391. */
  392.  
  393. /*            case IDL_LOG:
  394.                 {
  395.                 HWND    hwndList;
  396.  
  397.                 hwndList = (HWND) LOWORD(lParam);
  398.                 switch(HIWORD(lParam))
  399.                 {
  400.                 case LBN_ERRSPACE:
  401.                 case LBN_SELCHANGE:
  402.                 case LBN_DBLCLK:
  403.                 case LBN_SELCANCEL:
  404.                 case LBN_SETFOCUS:
  405.                 case LBN_KILLFOCUS: break;
  406.                 }
  407.                 break;
  408.                 }    // IDL_LOG
  409. */
  410.             default: return FALSE;
  411.             }
  412.         } // WM_COMMAND
  413.         }
  414.  
  415.         return TRUE;
  416.     }
  417.  
  418.  
  419. // Debugging Function
  420.  
  421.     void OkMsgBox(PSTR szCaption, PSTR szFormat, ...)
  422.  
  423. // Summary ----------------------------------------------------------------
  424. //
  425. //    Generates a message box with an OK button.
  426. //
  427. // Parameters
  428. //
  429. //    szCaption    Pointer to a title for the message box
  430. //
  431. //    szFormat    A format string for the message
  432. //
  433. //    ...        A variable number of arguments
  434. //
  435. // Returns
  436. //
  437. //    nothing
  438. //
  439. // Ends -------------------------------------------------------------------
  440.  
  441.  
  442.     {
  443.         char    szBuffer[256];
  444.         char    *pArgument;
  445.         va_list    vaArgs;
  446.  
  447.  
  448.         va_start(vaArgs, szFormat);
  449.         wvsprintf((LPSTR)szBuffer, (LPSTR)szFormat, vaArgs);
  450. //                MessageBeep(MB_OK);
  451.         MessageBox(NULL, szBuffer, szCaption, MB_OK);
  452.         
  453.         va_end(vaArgs);
  454.     }
  455.  
  456.  
  457.  
  458.  
  459. // Debugging Function
  460.  
  461.     void Whine(HWND hWnd, PSTR szCaption)
  462.  
  463. // Summary ----------------------------------------------------------------
  464. //
  465. //    Generates a message box with an OK button.
  466. //
  467. // Parameters
  468. //
  469. //    szCaption    Pointer to a title for the message box
  470. //
  471. // Returns
  472. //
  473. //    nothing
  474. //
  475. // Ends -------------------------------------------------------------------
  476.  
  477.  
  478.     {
  479.         char    szBuffer[256];
  480.         char    *pArgument;
  481.         va_list    vaArgs;
  482.  
  483.  
  484.         wsprintf((LPSTR)szBuffer, (LPSTR)"Invalid Directory:\n\n%s", (LPSTR)szCaption);
  485.         MessageBeep(MB_ICONEXCLAMATION);
  486.         MessageBox(hWnd, szBuffer, "Finger Users Directory", MB_ICONEXCLAMATION | MB_OK);
  487.         
  488.     }
  489.  
  490. // Callback function
  491.  
  492.     BOOL CALLBACK GetStrCallback(LPSTR lpString, LPARAM lParam)
  493.  
  494. // Summary ----------------------------------------------------------------
  495. //
  496. //    Called by the string library to add each string to the list box
  497. //
  498. // Parameters
  499. //
  500. //    lpString    A far pointer to the string.
  501. //
  502. //    lParam        Argument to the function.
  503. //
  504. // Returns
  505. //
  506. //    BOOL        True if the string was added to the list box
  507. //
  508. // Ends -------------------------------------------------------------------
  509.  
  510.  
  511.     {
  512.         HWND    hDlg;
  513.         UINT    nButton;
  514.         LONG    lResult;
  515.  
  516.         hDlg = (HWND) HIWORD(lParam);
  517.         nButton = LOWORD(lParam);
  518.         lResult = SendDlgItemMessage(hDlg, nButton, LB_ADDSTRING, 0, (LPARAM) lpString);
  519.  
  520.         return TRUE;
  521.     }
  522.  
  523.  
  524. // Function
  525.  
  526.     void DlgGetLogStrings(HWND hDlg, UINT nButton, int iMax)
  527.  
  528. // Summary ----------------------------------------------------------------
  529. //
  530. //    Initializes the list box by using string library to add all of the
  531. //    strings to the list box.
  532. //
  533. // Parameters
  534. //
  535. //    hDlg    Handle of the dialog window.
  536. //
  537. //    nButton    The ID of the list box
  538. //
  539. // Returns
  540. //
  541. //    nothing
  542. //
  543. // Ends -------------------------------------------------------------------
  544.  
  545.  
  546.     {
  547.         LPARAM    lParam;
  548.         FARPROC lpfnGetStrCallback;
  549.  
  550.         lParam = MAKELPARAM(nButton,hDlg);
  551.         lpfnGetStrCallback = MakeProcInstance((FARPROC)GetStrCallback, hInst);
  552.  
  553.         GetStrings(lpfnGetStrCallback, lParam);
  554.  
  555.     }
  556.  
  557.  
  558.  
  559. // Window Function
  560.  
  561.     LRESULT DoFindDirDlg(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  562.  
  563. // Summary ----------------------------------------------------------------
  564. //
  565. //     Respond to "About..." menu selection by invoking the "About"
  566. //    dialog box.
  567. //
  568. // Parameters
  569. //
  570. //    hWnd    Handle of the window.
  571. //
  572. //    Msg    Message.
  573. //
  574. //    wParam    First message paramter.
  575. //
  576. //    lParam    Second message parameter.
  577. //
  578. // Ends -------------------------------------------------------------------
  579.  
  580.     {
  581.         DLGPROC lpProcAbout;
  582.  
  583.         lpProcAbout = (DLGPROC) MakeProcInstance((FARPROC)FindDirDlgProc, hInst);
  584.         DialogBox(hInst, "FindDir", hWnd, lpProcAbout);
  585.         FreeProcInstance((FARPROC)lpProcAbout);
  586.  
  587.         return(FALSE);
  588.     }
  589.  
  590.  
  591. BOOL CALLBACK FindDirDlgProc(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
  592. {
  593.     switch (nMsg)
  594.     {
  595.     case WM_INITDIALOG:
  596.         SendDlgItemMessage(hDlg, IDD_FNAME, EM_LIMITTEXT, 120, 0L);
  597.         DlgDirList(hDlg, szFileSpec, IDD_FLIST, IDD_FPATH, wFileAttr );
  598.         SetDlgItemText(hDlg, IDD_FNAME, szFileSpec);
  599.         break;
  600.  
  601.     case WM_COMMAND:
  602.         switch(wParam)
  603.         {
  604.         case IDD_FLIST:
  605.             switch(HIWORD(lParam))
  606.                         {
  607.             case LBN_SELCHANGE:
  608.                 if (DlgDirSelect(hDlg, szFileName, IDD_FLIST))
  609.                     lstrcat(szFileName, szFileSpec);
  610.                 SetDlgItemText(hDlg,IDD_FNAME, szFileName);
  611.                 return TRUE;
  612.  
  613.             case LBN_DBLCLK:
  614.                 if (DlgDirSelect(hDlg, szFileName, IDD_FLIST))
  615.                 {
  616.                     lstrcat(szFileName, szFileSpec);
  617.                     DlgDirList(hDlg, szFileName, IDD_FLIST, IDD_FPATH, wFileAttr);
  618.                     SetDlgItemText(hDlg,IDD_FNAME,szFileSpec);
  619.                 }
  620.                 else
  621.                 {
  622.                     SetDlgItemText(hDlg,IDD_FNAME, szFileName);
  623.                                         SendMessage(hDlg,WM_COMMAND, IDOK, 0L);
  624.                 }
  625.                 return TRUE;
  626.             }
  627.             break;
  628.  
  629.  
  630.         case IDD_FNAME:
  631.             if (HIWORD(lParam) == EN_CHANGE)
  632.                 EnableWindow(GetDlgItem(hDlg, IDOK),
  633.                     (BOOL) SendMessage((HWND)LOWORD(lParam), WM_GETTEXTLENGTH, 0, 0L) );
  634.             return TRUE;
  635.  
  636.         case IDOK:
  637.         {
  638.             int nEditLen;
  639.             char cLastChar;
  640.  
  641.             GetDlgItemText(hDlg, IDD_FNAME, szFileName, 120);
  642.  
  643.             nEditLen = lstrlen(szFileName);
  644.             cLastChar = *AnsiPrev(szFileName, szFileName + nEditLen);
  645.  
  646.             if (cLastChar == '\\' || cLastChar == ':')
  647.                 lstrcat(szFileName, szFileSpec);
  648.  
  649.             if (lstrchr(szFileName, '*') || lstrchr(szFileName, '?'))
  650.             {
  651.                 if (DlgDirList(hDlg,szFileName, IDD_FLIST, IDD_FPATH, wFileAttr))
  652.                 {
  653.                     lstrcpy(szFileSpec, szFileName);
  654.                     SetDlgItemText(hDlg, IDD_FNAME, szFileSpec);
  655.                 }
  656.                 return TRUE;
  657.             }
  658.  
  659.             lstrcat(lstrcat(szFileName, "\\"), szFileSpec);
  660.  
  661.             if (DlgDirList(hDlg,szFileName,IDD_FLIST,IDD_FPATH,wFileAttr))
  662.             {
  663.                 lstrcpy(szFileSpec,szFileName);
  664.                 SetDlgItemText(hDlg,IDD_FNAME,szFileSpec);
  665.                                 return TRUE;
  666.             }
  667.  
  668.             szFileName[nEditLen] = '\0';
  669.  
  670.  
  671.             EndDialog(hDlg, TRUE);
  672.             return TRUE;
  673.         }
  674.  
  675.         case IDCANCEL:
  676.             EndDialog(hDlg, FALSE);
  677.                         return TRUE;
  678.  
  679.         } // WM_COMMAND
  680.         }
  681.     return FALSE;
  682. }
  683.