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

  1. // Contents ---------------------------------------------------------------
  2. //
  3. //   cm.c -- Common 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. //    The comman dialog functions to allow the user to select the
  14. //    file that they wish to use as the "snark" file.
  15. //
  16. // Ends -------------------------------------------------------------------
  17.  
  18. // History ----------------------------------------------------------------
  19. //
  20. // 6/28/94  1.0  Fred Bent         Started implementation
  21. //
  22. // Ends -------------------------------------------------------------------
  23.  
  24. // Interface Dependencies -------------------------------------------------
  25.  
  26. #define STRICT
  27.  
  28. #include <windows.h>
  29. #include <windowsx.h>
  30. #include <commdlg.h>
  31. #include <ctl3d.h>
  32. #include "fingerd.h"
  33.  
  34. // End Interface Dependencies ---------------------------------------------
  35.  
  36. // External Declarations --------------------------------------------------
  37.  
  38. extern const HINSTANCE hInst;
  39.  
  40. char szFilterSpec [128] =                       // file type filters
  41.          "Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0\0";
  42.  
  43. extern char szLocalFile[MAX_PATH];
  44. extern char szFileDir[MAX_PATH];
  45.  
  46.  
  47.  
  48. // Common Dialog Hook Function
  49.  
  50.     BOOL CALLBACK OpenHook(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam)
  51.  
  52. // Summary ----------------------------------------------------------------
  53. //
  54. //    This hook is needed to fix a bug in the common dialog box
  55. //
  56. // Parameters
  57. //
  58. //
  59. // Return
  60. //
  61. //    BOOL    Returns FALSE if processed
  62. //
  63. // Ends -------------------------------------------------------------------
  64.  
  65.     {
  66.         switch (wm)
  67.         {
  68.         case WM_INITDIALOG:
  69.             // We must call this to subclass the directory listbox even
  70.             // if the app calls Ctl3dAutoSubclass (commdlg bug)
  71. #ifdef    USE_CTL3D
  72.             Ctl3dSubclassDlg(hwnd, CTL3D_ALL);
  73. #endif
  74.             break;
  75.          }
  76.         return FALSE;
  77.     }
  78.  
  79.  
  80. // Function
  81.  
  82.     void FileOpen(HWND hwndOwner)
  83.  
  84. // Summary ----------------------------------------------------------------
  85. //
  86. //    Uses the common dialog box to select a file name.
  87. //
  88. // Parameters
  89. //
  90. //      hwndOwner    The window handle of the owner of this dialog//
  91. //
  92. // Return
  93. //
  94. //    nothing
  95. //
  96. // Ends -------------------------------------------------------------------
  97.  
  98.     {
  99.         OPENFILENAME ofn;
  100.  
  101.         /* fill in non-variant fields of OPENFILENAME struct. */
  102.  
  103.         if ( !LoadString(hInst, IDS_FILTER, (LPSTR) szFilterSpec, sizeof(szFilterSpec)))
  104.             return;
  105.  
  106.         ofn.lStructSize     = sizeof(OPENFILENAME);
  107.             ofn.hwndOwner        = hwndOwner;
  108.             ofn.lpstrFilter        = szFilterSpec;
  109.             ofn.lpstrCustomFilter = NULL;
  110.             ofn.nMaxCustFilter  = 0;
  111.         ofn.nFilterIndex    = 1;
  112.             ofn.lpstrFile       = szLocalFile;
  113.             ofn.nMaxFile        = 120;
  114.             ofn.lpstrInitialDir = NULL;
  115.             ofn.lpstrFileTitle  = NULL;
  116.         ofn.nMaxFileTitle   = 120;
  117.         ofn.lpstrTitle      = "Browser";
  118.         ofn.lpstrDefExt     = "TXT";
  119.         ofn.Flags         = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_NOCHANGEDIR;
  120.         ofn.lpfnHook         = (UINT (CALLBACK *)(HWND,UINT,WPARAM,LPARAM)) MakeProcInstance((FARPROC)OpenHook, hInst);
  121.             ofn.lCustData         = 0;
  122.             ofn.lpTemplateName  = 0;
  123.  
  124.             GetOpenFileName ((LPOPENFILENAME)&ofn);
  125.         FreeProcInstance((FARPROC)ofn.lpfnHook);
  126.  
  127.         return;
  128.     }
  129.  
  130.