home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_OpenFileDlg_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-27  |  3.0 KB  |  118 lines

  1. // Copyright
  2. // Microsoft Corporation
  3. // All rights reserved
  4.  
  5. // OpenFileDlg.cs
  6.  
  7. using System;
  8. using System.Text;
  9. using System.Runtime.InteropServices;
  10.  
  11. /*
  12. typedef struct tagOFN { 
  13.   DWORD         lStructSize; 
  14.   HWND          hwndOwner; 
  15.   HINSTANCE     hInstance; 
  16.   LPCTSTR       lpstrFilter; 
  17.   LPTSTR        lpstrCustomFilter; 
  18.   DWORD         nMaxCustFilter; 
  19.   DWORD         nFilterIndex; 
  20.   LPTSTR        lpstrFile; 
  21.   DWORD         nMaxFile; 
  22.   LPTSTR        lpstrFileTitle; 
  23.   DWORD         nMaxFileTitle; 
  24.   LPCTSTR       lpstrInitialDir; 
  25.   LPCTSTR       lpstrTitle; 
  26.   DWORD         Flags; 
  27.   WORD          nFileOffset; 
  28.   WORD          nFileExtension; 
  29.   LPCTSTR       lpstrDefExt; 
  30.   LPARAM        lCustData; 
  31.   LPOFNHOOKPROC lpfnHook; 
  32.   LPCTSTR       lpTemplateName; 
  33. #if (_WIN32_WINNT >= 0x0500)
  34.   void *        pvReserved;
  35.   DWORD         dwReserved;
  36.   DWORD         FlagsEx;
  37. #endif // (_WIN32_WINNT >= 0x0500)
  38. } OPENFILENAME, *LPOPENFILENAME; 
  39. */
  40.  
  41. [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]  
  42. public class OpenFileName 
  43. {
  44.     public int        structSize = 0;
  45.     public IntPtr    dlgOwner = IntPtr.Zero; 
  46.     public IntPtr    instance = IntPtr.Zero;
  47.     
  48.     public String    filter = null;
  49.     public String    customFilter = null;
  50.     public int        maxCustFilter = 0;
  51.     public int        filterIndex = 0;
  52.     
  53.     public String    file = null;
  54.     public int        maxFile = 0;
  55.     
  56.     public String    fileTitle = null;
  57.     public int        maxFileTitle = 0;
  58.     
  59.     public String    initialDir = null;
  60.     
  61.     public String    title = null;   
  62.     
  63.     public int        flags = 0; 
  64.     public short    fileOffset = 0;
  65.     public short    fileExtension = 0;
  66.     
  67.     public String    defExt = null; 
  68.     
  69.     public IntPtr    custData = IntPtr.Zero;  
  70.     public IntPtr    hook = IntPtr.Zero;  
  71.     
  72.     public String    templateName = null; 
  73.     
  74.     public IntPtr    reservedPtr = IntPtr.Zero; 
  75.     public int        reservedInt = 0;
  76.     public int        flagsEx = 0;
  77. }
  78.  
  79. public class LibWrap
  80. {
  81.     //BOOL GetOpenFileName(LPOPENFILENAME lpofn);
  82.     
  83.     [ DllImport( "Comdlg32.dll", CharSet=CharSet.Auto )]                
  84.     public static extern bool GetOpenFileName([ In, Out ] OpenFileName ofn );    
  85. }
  86.  
  87. public class App
  88. {
  89.     public static void Main()
  90.     {
  91.         OpenFileName ofn = new OpenFileName();
  92.         
  93.         ofn.structSize = Marshal.SizeOf( ofn );
  94.         
  95.         ofn.filter = "Log files\0*.log\0Batch files\0*.bat\0";
  96.         
  97.         ofn.file = new String( new char[ 256 ]);
  98.         ofn.maxFile = ofn.file.Length;
  99.         
  100.         ofn.fileTitle = new String( new char[ 64 ]);
  101.         ofn.maxFileTitle = ofn.fileTitle.Length;    
  102.             
  103.         ofn.initialDir = "C:\\";
  104.         ofn.title = "Open file called using platform invoke...";
  105.         ofn.defExt = "txt";
  106.         
  107.         if( LibWrap.GetOpenFileName( ofn ))
  108.         {
  109.             Console.WriteLine( "Selected file with full path: {0}", ofn.file );
  110.             Console.WriteLine( "Selected file name: {0}", ofn.fileTitle );
  111.             Console.WriteLine( "Offset from file name: {0}", ofn.fileOffset );
  112.             Console.WriteLine( "Offset from file extension: {0}", ofn.fileExtension );
  113.         }
  114.     }
  115. }
  116.  
  117.  
  118.