I tried with this but it does not work.[xx(]
Code: Select all
private void btnConvert_Click(object sender, System.EventArgs e)
{
float AbsWidht=0, AbsHeight=0;
CADDraw CrDraw= new CADDraw();
FRect CrDraw1= new FRect();
long r=0;
double K= 0;
DLLWin32Import.GetBoxCAD(DLLWin32Import.CADFile, AbsWidht, AbsHeight);
DLLWin32Import.GetClientRect(DLLWin32Import.CADFile, ref CrDraw.R);
if (AbsWidht==0)
K= 1;
else
K= AbsHeight/ AbsWidht;
//DLLWin32Import.GetExtentsCAD(DLLWin32Import.CADFile, ref CrDraw1);
CrDraw.Size= Marshal.SizeOf(CrDraw);
CrDraw.R.Top= 0;
CrDraw.R.Left= 0;
CrDraw.R.Right= CrDraw.R.Right * 100 / 100;
CrDraw.R.Bottom= Convert.ToInt32(((double)(CrDraw.R.Right * K)));
CrDraw.R.Bottom= CrDraw.R.Bottom * 100 / 100;
CrDraw.DrawMode= 0;
IntPtr hImagen= DLLWin32Import.DrawCADtoBitmap(DLLWin32Import.CADFile, ref CrDraw);
long Size = DLLWin32Import.GlobalSize(hImagen);
IntPtr P = DLLWin32Import.GlobalLock(hImagen);
IntPtr FHnd = DLLWin32Import.CreateFile("c:\\ejemplo.bmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
DLLWin32Import.WriteFile (FHnd,ref P, Size,ref r, 0);
DLLWin32Import.CloseHandle( FHnd);
DLLWin32Import.GlobalUnlock( hImagen);
DLLWin32Import.GlobalFree( hImagen);
}
public class DLLWin32Import
{
public static IntPtr CADFile = new IntPtr();
public static float fAbsHeight, fAbsWidth;
public static int fScale = 100;
public static int FX, FY;
public static FPoint fScaleRect = new FPoint();
public static Point fStart = new Point();
public static Point fOld = new Point();
[DllImport("kernel32.dll")]
public static extern IntPtr WriteFile (IntPtr hFile, ref IntPtr lpBuffer , long nNumberOfBytesToWrite, ref long lpNumberOfBytesWritten, int lpOverlapped);
[DllImport("kernel32.dll")]
public static extern IntPtr CreateFile(string lpFileName, long dwDesiredAccess, long dwShareMode, int lpSecurityAttributes, long dwCreationDisposition , long dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32.dll")] public static extern long CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalAlloc(long wFlags, long dwBytes);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalFree(IntPtr hMem);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalLock (IntPtr hMem);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalUnlock(IntPtr hMem);
[DllImport("kernel32.dll")]
public static extern long GlobalSize(IntPtr hMem);
[DllImport("User32.dll")]
public static extern bool GetClientRect (IntPtr hWnd, ref Rect fRect);
[DllImport("CADImage.dll")]
public static extern IntPtr CreateCAD(IntPtr hWindow, string lpFileName);
[DllImport("CADImage.dll")]
public static extern int CloseCAD(IntPtr hObject);
[DllImport("CADImage.dll")]
public static extern int DrawCAD(IntPtr hObject, IntPtr hDC, ref Rect lprc); //??
[DllImport("CADImage.dll")]
public static extern int GetExtentsCAD(IntPtr handle, ref FRect fRect);
[DllImport("CADImage.dll")]
public static extern int CADLayerCount(IntPtr hObject);
[DllImport("CADImage.dll")]
public static extern IntPtr CADLayer(IntPtr hObject, int nIndex, ref DXFData lpData);
[DllImport("CADImage.dll")]
public static extern int GetLastErrorCAD([MarshalAs(UnmanagedType.LPStr)]string lbBuf);
[DllImport("CADImage.dll")]
public static extern int DrawCADEx(IntPtr hObject, ref CADDraw lpcd);
[DllImport("CADImage.dll")]
public static extern int CADLayerVisible(IntPtr hObject, int visible);
[DllImport("CADImage.dll")]
public static extern int CADVisible(IntPtr hObject, [MarshalAs(UnmanagedType.LPStr)] string lpLayerName);
[DllImport("CADImage.dll")]
public static extern IntPtr DrawCADtoBitmap(IntPtr hObject, ref CADDraw lpcd);
[DllImport("CADImage.dll")]
public static extern IntPtr DrawCADtoGif(IntPtr hObject, ref CADDraw lpcd);
[DllImport("CADImage.dll")]
public static extern IntPtr DrawCADtoJpeg(IntPtr hObject, ref CADDraw lpcd);
[DllImport("CADImage.dll")]
public static extern int GetBoxCAD(IntPtr hObject, float AbsWidht, float AbsHeight);
}