I did some VFP-AutoCAD programming years ago. The bèta of VFP 9 was just
released then. The code Greg posted yesterday is very familiar te me...
The code below can be used to strip the preview-bitmap from a dwg file.
The comments are in Dutch but i think the code is easy enough to read.
A few months ago I discoverd that the AutoCAD 2010 fileformat has a slightly
larger bitmap. So the code may need some tweeking.
Start with an image baseclass en put the code in a new Preview method.
When calling the Preview method send the path+filename as parameter.
LPARAMETERS tcFileName
LOCAL lcFileName
LOCAL lnFileHandle
lcFileName = ALLTRIM(tcFileName)
lnFileHandle = 0
IF !FILE(lcFileName)
THIS.cFileName = ""
THIS.nACVersion = 0
THIS.cACVersion = ""
THIS.PictureVal = FILETOSTR(goApp.cHomeDir + "framework\grafisch\geenvoorbeeld.bmp")
RETURN
ENDIF
THIS.cFileName = lcFileName
lnFileHandle = FOPEN(THIS.cFileName, 0)
= FREAD(lnFileHandle, 2)
THIS.nACVersion = VAL(FREAD(lnFileHandle, 4))
DO CASE
CASE THIS.nACVersion = 1021
THIS.cACVersion = "AutoCAD 2007"
CASE THIS.nACVersion = 1018
THIS.cACVersion = "AutoCAD 2004/2005/2006"
CASE THIS.nACVersion = 1015
THIS.cACVersion = "AutoCAD 2000/2000i/2002"
CASE THIS.nACVersion = 1014
THIS.cACVersion = "AutoCAD 14"
CASE THIS.nACVersion = 1013
THIS.cACVersion = "AutoCAD 14, Sample"
CASE THIS.nACVersion = 1012
THIS.cACVersion = "AutoCAD 13"
CASE THIS.nACVersion = 1009
THIS.cACVersion = "AutoCAD 11/12"
CASE THIS.nACVersion = 1006
THIS.cACVersion = "AutoCAD 10"
CASE THIS.nACVersion = 1004
THIS.cACVersion = "AutoCAD 9"
OTHERWISE
THIS.cACVersion = ""
ENDCASE
IF THIS.nACVersion < 1014
THIS.PictureVal = FILETOSTR("grafisch/geenvoorbeeld.bmp")
= FCLOSE(lnFileHandle)
RETURN
ENDIF
LOCAL lnStartOfBitmap, lnNumberOfDescriptors, lnNum1
LOCAL lnDescriptorID, lnDescriptorStart, lnDescriptorLength
LOCAL lcBitmap
LOCAL lcFileHeaderType, lcFileSize, lcFileHeaderReserved1, lcFileHeaderReserved2, lcFileHeaderOffsetBits
lnStartOfBitmap = 0
lnNumberOfDescriptors = 0
lnNum1 = 0
lnDescriptorID = 0
lnDescriptorStart = 0
lnDescriptorLength = 0
lcBitmap = ""
lcFileHeaderType = ""
lcFileSize = ""
lcFileHeaderReserved1 = ""
lcFileHeaderReserved2 = ""
lcFileHeaderOffsetBits = ""
= FSEEK(lnFileHandle, 13, 0)
lnStartOfBitmap = DWord2Num(FREAD(lnFileHandle, 4))
= FREAD(lnFileHandle, lnStartOfBitmap - 17 + 16)
= FREAD(lnFileHandle, 4)
lnNumberOfDescriptors = ASC(FREAD(lnFileHandle, 1))
FOR lnNum1 = 1 TO lnNumberOfDescriptors
lnDescriptorID = ASC(FREAD(lnFileHandle, 1))
lnDescriptorStart = DWord2Num(FREAD(lnFileHandle, 4))
lnDescriptorLength = DWord2Num(FREAD(lnFileHandle, 4))
IF lnDescriptorID = 2
EXIT
ENDIF
ENDFOR
= FSEEK(lnFileHandle, lnDescriptorStart, 0)
lcBitMap = FREAD(lnFileHandle, lnDescriptorLength)
= FCLOSE(lnFileHandle)
lcFileHeaderType = Num2Word(19778)
lcFileSize = Num2DWord(14 + lnDescriptorLength)
lcFileHeaderReserved1 = Num2Word(0)
lcFileHeaderReserved2 = Num2Word(0)
lcFileHeaderOffsetBits = Num2DWord(1078)
THIS.PictureVal = lcFileHeaderType + lcFileSize + lcFileHeaderReserved1 + lcFileHeaderReserved2 + ;
lcFileHeaderOffsetBits + lcBitMap