Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: tricky sql & data set question Pin
A.Wegierski20-Aug-03 19:20
A.Wegierski20-Aug-03 19:20 
GeneralRe: tricky sql & data set question Pin
Ista21-Aug-03 3:22
Ista21-Aug-03 3:22 
GeneralRe: tricky sql & data set question Pin
Ista21-Aug-03 3:50
Ista21-Aug-03 3:50 
GeneralRe: tricky sql & data set question Pin
A.Wegierski24-Aug-03 22:29
A.Wegierski24-Aug-03 22:29 
GeneralI formated my drive along with my project Pin
mdolby19-Aug-03 10:11
mdolby19-Aug-03 10:11 
GeneralRe: I formated my drive along with my project Pin
J. Dunlap19-Aug-03 10:18
J. Dunlap19-Aug-03 10:18 
QuestionHow do I find a file associated icon? Pin
Lars Fisker19-Aug-03 9:17
Lars Fisker19-Aug-03 9:17 
AnswerRe: How do I find a file associated icon? Pin
Heath Stewart19-Aug-03 9:46
protectorHeath Stewart19-Aug-03 9:46 
Actually, this is about the only wait to do it if you want the information for a file that doesn't exist (without doing all the registry and icon handling yourself). It's easy to make work, though - I've used this alot. Below is an example:
public class FileInfo
{
  private int const FILE_ATTRIBUTE_NORMAL = 0x80;

  [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  private static extern IntPtr SHGetFileInfo(
    string path,
    int fileAttributes,
    [MarshalAs(UnmanagedType.Struct), Out]out SHFileInfo info,
    int fileInfoSize,
    [MarshalAs(UnmanagedType.U4)]SHGFI flags);

  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
  private struct SHFileInfo
  {
    public IntPtr IconHandle;
    public int IconIndex;
    public int Attributes;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
      public string DisplayName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
      public string FileType;
  }

  [Flags]
  private enum SHGFI
  {
    LargeIcon = 0x0,
    SmallIcon = 0x1,
    OpenIcon = 0x2,
    ShallIconSize = 0x4,
    PIDL = 0x08,
    UseFileAttribute = 0x10,
    AddOverlays = 0x20,
    OverlayIndex = 0x40,
    Icon = 0x0100,
    DisplayName = 0x200,
    TypeName = 0x400,
    Attributes = 0x800,
    IconLocation = 0x1000,
    EXEType = 0x2000,
    SysIconIndex = 0x4000,
    LinkOverlay = 0x8000,
    Selected = 0x10000,
    AttrSpecified = 0x20000
  }

  public static bool GetFileInformation(string filename,
    out string fileType, out Image fileImage)
  {
    SHFileInfo info = new SHFileInfo();
    IntPtr retVal = SHGetFileInfo(filename, FILE_ATTRIBUTE_NORMAL,
      out info, Marshal.SizeOf(typeof(SHFileInfo),
      SHGFI.AddOverlays | SHGFI.DisplayName | SHGFI.Icon | SHGFI.SmallIcon
        | SHGFI.TypeName | SHGFI.UseFileAttributes);
    if (retVal != IntPtr.Zero)
    {
      // Set the file type as the user would see it.
      fileType = info.FileType;

      // Get an Image from the Icon, as they're easier to deal with.
      fileImage = Bitmap.FromHicon(info.IconHandle);
      return true;
    }
    else return false;
  }
}
I just threw that together quick, so don't just copy and paste. You won't learn anything that way anyway. You had the right idea, but you must've been prototyping something wrong or forgetting about the marshaling stuff, whichis necessary is several cases in this example (such as pass-by-value strings).

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: How do I find a file associated icon? Pin
Lars Fisker19-Aug-03 10:48
Lars Fisker19-Aug-03 10:48 
QuestionTrapping the enter key? Pin
BoozeBomb19-Aug-03 8:57
BoozeBomb19-Aug-03 8:57 
AnswerRe: Trapping the enter key? Pin
Heath Stewart19-Aug-03 9:14
protectorHeath Stewart19-Aug-03 9:14 
GeneralRe: Trapping the enter key? Pin
BoozeBomb19-Aug-03 9:25
BoozeBomb19-Aug-03 9:25 
Generalasync delegates Pin
devvvy19-Aug-03 8:32
devvvy19-Aug-03 8:32 
GeneralRe: async delegates Pin
Heath Stewart19-Aug-03 9:26
protectorHeath Stewart19-Aug-03 9:26 
Generalsending mail with attachments Pin
Sprinkle19-Aug-03 7:57
Sprinkle19-Aug-03 7:57 
GeneralRe: sending mail with attachments Pin
Heath Stewart19-Aug-03 9:53
protectorHeath Stewart19-Aug-03 9:53 
QuestionDetermining radio button choice...??? Pin
vlusardi19-Aug-03 7:33
vlusardi19-Aug-03 7:33 
AnswerRe: Determining radio button choice...??? Pin
Heath Stewart19-Aug-03 9:56
protectorHeath Stewart19-Aug-03 9:56 
GeneralGIS in C# Pin
laphijia19-Aug-03 7:07
laphijia19-Aug-03 7:07 
GeneralUsing ActiveX control in C# Pin
Big Trev19-Aug-03 6:43
Big Trev19-Aug-03 6:43 
GeneralRe: Using ActiveX control in C# Pin
Stephane Rodriguez.19-Aug-03 8:45
Stephane Rodriguez.19-Aug-03 8:45 
GeneralRe: Using ActiveX control in C# Pin
Heath Stewart19-Aug-03 10:03
protectorHeath Stewart19-Aug-03 10:03 
GeneralRe: Using ActiveX control in C# Pin
Big Trev19-Aug-03 21:32
Big Trev19-Aug-03 21:32 
GeneralRe: Using ActiveX control in C# Pin
Heath Stewart20-Aug-03 2:26
protectorHeath Stewart20-Aug-03 2:26 
GeneralRe: Using ActiveX control in C# Pin
Big Trev20-Aug-03 2:44
Big Trev20-Aug-03 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.