kopia lustrzana https://github.com/njcrawford/EmbroideryReader
Added possibly working thumbnail shell integration
rodzic
7e317eae6d
commit
507292fe89
|
@ -1,23 +1,167 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace embroideryThumbs
|
||||
{
|
||||
public class PESThumbnail
|
||||
//[Guid("69EA0D51-1BD4-4c6e-9AE0-B13C915A59E3")]
|
||||
//public interface EmbThumbnailInterface
|
||||
//{
|
||||
// //COM visible function go here
|
||||
//}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SIZE
|
||||
{
|
||||
//public HRESULT QueryInterface()
|
||||
//{
|
||||
public int cx;
|
||||
public int cy;
|
||||
|
||||
//}
|
||||
//public UInt64 AddRef()
|
||||
//{
|
||||
public SIZE(int cx, int cy)
|
||||
{
|
||||
this.cx = cx;
|
||||
this.cy = cy;
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
//public UInt64 Release()
|
||||
//{
|
||||
[ComImport, Guid("0000010c-0000-0000-c000-000000000046"),
|
||||
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IPersist
|
||||
{
|
||||
[PreserveSig]
|
||||
void GetClassID(out Guid pClassID);
|
||||
}
|
||||
|
||||
//}
|
||||
//public HRESULT Extract(HBITMAP
|
||||
[ComImport, Guid("0000010b-0000-0000-C000-000000000046"),
|
||||
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IPersistFile : IPersist
|
||||
{
|
||||
//new void GetClassID(out Guid pClassID);
|
||||
[PreserveSig]
|
||||
int IsDirty();
|
||||
|
||||
[PreserveSig]
|
||||
void Load([In, MarshalAs(UnmanagedType.LPWStr)]
|
||||
string pszFileName, uint dwMode);
|
||||
|
||||
[PreserveSig]
|
||||
void Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName,
|
||||
[In, MarshalAs(UnmanagedType.Bool)] bool fRemember);
|
||||
|
||||
[PreserveSig]
|
||||
void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName);
|
||||
|
||||
[PreserveSig]
|
||||
void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName);
|
||||
}
|
||||
|
||||
[ComImportAttribute()]
|
||||
[GuidAttribute("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")]
|
||||
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IExtractImage
|
||||
{
|
||||
void GetLocation(
|
||||
[Out, MarshalAs(UnmanagedType.LPWStr)]
|
||||
StringBuilder pszPathBuffer,
|
||||
int cch,
|
||||
ref int pdwPriority,
|
||||
ref SIZE prgSize,
|
||||
int dwRecClrDepth,
|
||||
ref int pdwFlags);
|
||||
|
||||
void Extract(out IntPtr phBmpThumbnail);
|
||||
}
|
||||
|
||||
//[Guid("xxxx"),
|
||||
//InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
//public interface IExtractImage2
|
||||
//{
|
||||
// // from IExtractImage
|
||||
// void Extract();
|
||||
// void GetLocation();
|
||||
|
||||
// HRESULT GetDateStamp([Out] System.Runtime.InteropServices.ComTypes.FILETIME* pDateStamp);
|
||||
//}
|
||||
|
||||
[Guid("EA7D5329-E9D7-49fb-9F55-A12D1A2ADB5D"),
|
||||
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
|
||||
public interface EmbThumbnailEvents
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Guid("7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E"),
|
||||
ClassInterface(ClassInterfaceType.None),
|
||||
ComSourceInterfaces(typeof(EmbThumbnailEvents))]
|
||||
public class EmbThumbnail : IPersistFile, IExtractImage
|
||||
{
|
||||
PesFile.PesFile designFile;
|
||||
|
||||
public void GetClassID(out Guid pClassID)
|
||||
{
|
||||
// not implemented, but won't compile without this
|
||||
pClassID = new Guid("7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E");
|
||||
}
|
||||
|
||||
public int IsDirty()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Load([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName, uint dwMode)
|
||||
{
|
||||
if(pszFileName.Substring(pszFileName.Length - 4).ToLower() == ".pes")
|
||||
{
|
||||
designFile = new PesFile.PesFile(pszFileName);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName, [In, MarshalAs(UnmanagedType.Bool)] bool fRemember)
|
||||
{
|
||||
//not implemented
|
||||
}
|
||||
|
||||
public void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName)
|
||||
{
|
||||
//not implemented
|
||||
}
|
||||
|
||||
public void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName)
|
||||
{
|
||||
//not implemented
|
||||
}
|
||||
|
||||
public void GetLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPathBuffer, int cch, ref int pdwPriority, ref SIZE prgSize, int dwRecClrDepth, ref int pdwFlags)
|
||||
{
|
||||
//not implemented
|
||||
}
|
||||
|
||||
public unsafe void Extract(out IntPtr phBmpThumbnail)
|
||||
{
|
||||
System.Drawing.Bitmap designBitmap = designFile.designToBitmap(3, false, 0);
|
||||
|
||||
IntPtr hBmp = designBitmap.GetHbitmap();
|
||||
|
||||
phBmpThumbnail = new IntPtr();
|
||||
|
||||
// Assuming you already have hBmp as the handle to your Bitmap object...
|
||||
if (IntPtr.Size == 4)
|
||||
{
|
||||
int* pBuffer = (int*)phBmpThumbnail.ToPointer();
|
||||
*pBuffer = hBmp.ToInt32();
|
||||
|
||||
// IMO, casting back to (void*) is not necessary.
|
||||
// I guess just for formality, that pBuffer points
|
||||
// to an object, not an int. :)
|
||||
phBmpThumbnail = new IntPtr((void*)pBuffer);
|
||||
}
|
||||
else // 8-bytes, or 64-bit
|
||||
{
|
||||
long* pBuffer = (long*)phBmpThumbnail.ToPointer();
|
||||
*pBuffer = hBmp.ToInt64();
|
||||
phBmpThumbnail = new IntPtr((void*)pBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ using System.Runtime.InteropServices;
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ComVisible(true)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("36115830-3226-4c7d-9abc-937cc8932cf6")]
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<RegisterForComInterop>true</RegisterForComInterop>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -37,6 +39,12 @@
|
|||
<Compile Include="PESThumbnail.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PesFile\PesFile.csproj">
|
||||
<Project>{66EF662E-F52C-4104-9C15-A14266D8F3B8}</Project>
|
||||
<Name>PesFile</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -84,6 +84,7 @@ Section "Associate with .PES files"
|
|||
WriteRegStr HKCR ".pes" "backup_val" $1
|
||||
"${Index}-NoBackup:"
|
||||
WriteRegStr HKCR ".pes" "" "EmbroideryDesign"
|
||||
WriteRegStr HKCR ".pes" "PerceivedType" "image"
|
||||
ReadRegStr $0 HKCR "EmbroideryDesign" ""
|
||||
StrCmp $0 "" 0 "${Index}-Skip"
|
||||
WriteRegStr HKCR "EmbroideryDesign" "" "Embroidery Design File"
|
||||
|
@ -91,6 +92,33 @@ Section "Associate with .PES files"
|
|||
WriteRegStr HKCR "EmbroideryDesign\DefaultIcon" "" "$INSTDIR\embroideryReader.exe,0"
|
||||
"${Index}-Skip:"
|
||||
WriteRegStr HKCR "EmbroideryDesign\shell\open\command" "" '$INSTDIR\embroideryReader.exe "%1"'
|
||||
|
||||
|
||||
|
||||
# Tell shell to use this for thumbnails
|
||||
//StrCmp $DoThumbs 0 +3
|
||||
WriteRegStr HKCR ".pes\ShellEx" "" ""
|
||||
WriteRegStr HKCR ".pes\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}" "" "{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}"
|
||||
|
||||
# Add thumbnail extractor classes
|
||||
WriteRegStr HKCR "PESIcon.Extractor" "" "Embroidery Design Thumbnail Extractor"
|
||||
WriteRegStr HKCR "PESIcon.Extractor\CLSID" "" "{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}"
|
||||
WriteRegStr HKCR "PESIcon.Extractor\CurVer" "" "PESIcon.Extractor.1"
|
||||
WriteRegStr HKCR "PESIcon.Extractor.1" "" "Embroidery Design Thumbnail Extractor"
|
||||
WriteRegStr HKCR "PESIcon.Extractor.1\CLSID" "" "{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}"
|
||||
|
||||
# Add CLSID
|
||||
WriteRegStr HKCR "CLSID\{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}" "" "Embroidery Design Thumbnail Extractor"
|
||||
WriteRegStr HKCR "CLSID\{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}\InProcServer32" "" "$INSTDIR\embroideryThumbs.dll"
|
||||
WriteRegStr HKCR "CLSID\{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}\InProcServer32" "ThreadingModel" "Apartment"
|
||||
WriteRegStr HKCR "CLSID\{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}\ProgId" "" "PESIcon.Extractor.1"
|
||||
WriteRegStr HKCR "CLSID\{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}\VersionIndependantProgId" "" "PESIcon.Extractor"
|
||||
|
||||
# Add to shell approved extensions list
|
||||
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" "{7E3EF3E8-39D4-4150-9EFF-58C71A1F4F9E}" "Embroidery Design Thumbnail Extractor"
|
||||
|
||||
# Cause explorer shell to reload settings
|
||||
#System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"
|
||||
|
||||
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
|
||||
!undef Index
|
||||
|
|
Ładowanie…
Reference in New Issue