分享一个16进制文件查看器,原创哦~
迫不及待拿出来分享,不喜勿喷。我写的是查看bmp文件的,里面只需改动一句,就可以查看任何文件。
程序代码:
************************************************** *-- Form: form1 (d:\documents\visual foxpro 项目\bmpviewer.scx) *-- ParentClass: form *-- BaseClass: form *-- Time Stamp: 04/19/23 12:28:01 AM * DEFINE CLASS form1 AS form Height = 654 Width = 852 DoCreate = .T. AutoCenter = .T. Caption = "位图文件查看器" *-- 保存文件数据流。 string = "" Name = "Form1" ADD OBJECT command1 AS commandbutton WITH ; AutoSize = .T., ; Top = 0, ; Left = 0, ; Height = 25, ; Width = 78, ; Caption = "打开BMP文件", ; Name = "Command1" ADD OBJECT commandgroup1 AS commandgroup WITH ; ButtonCount = 4, ; Value = 1, ; Height = 34, ; Left = 1, ; Top = 27, ; Width = 70, ; Name = "Commandgroup1", ; Command1.Top = 5, ; Command1.Left = 5, ; Command1.Height = 25, ; Command1.Width = 60, ; Command1.Caption = "首页", ; Command1.Name = "Command1", ; Command2.Top = 32, ; Command2.Left = 5, ; Command2.Height = 25, ; Command2.Width = 60, ; Command2.Caption = "下一页", ; Command2.Name = "Command2", ; Command3.Top = 59, ; Command3.Left = 5, ; Command3.Height = 25, ; Command3.Width = 60, ; Command3.Caption = "前一页", ; Command3.Name = "Command3", ; Command4.Top = 86, ; Command4.Left = 5, ; Command4.Height = 25, ; Command4.Width = 60, ; Command4.Caption = "末页", ; Command4.Name = "Command4" ADD OBJECT combo1 AS combobox WITH ; Height = 24, ; Left = 748, ; Top = 35, ; Width = 100, ; Name = "Combo1" ADD OBJECT label1 AS label WITH ; AutoSize = .T., ; Caption = "当前页:", ; Height = 16, ; Left = 695, ; Top = 39, ; Width = 50, ; Name = "Label1" ADD OBJECT grid1 AS grid WITH ; Height = 588, ; Left = 2, ; Top = 65, ; Width = 848, ; Name = "Grid1" ADD OBJECT label2 AS label WITH ; AutoSize = .T., ; Caption = "", ; Height = 16, ; Left = 100, ; Top = 6, ; Width = 2, ; Name = "Label2" PROCEDURE Init CREATE CURSOR temp (字节偏移 c(7),f1 N(3,0),f2 N(3,0),; f3 N(3,0),f4 N(3,0),f5 N(3,0),; f6 N(3,0),f7 N(3,0),f8 N(3,0),; f9 N(3,0),f10 N(3,0),f11 N(3,0),; f12 N(3,0),f13 N(3,0),f14 N(3,0),; f15 N(3,0),f16 N(3,0)) thisform.grid1.RecordSourceType= 1 thisform.grid1.RecordSource="temp" FOR i=0 TO 9 thisform.grid1.Columns(i+2).header1.caption=TRANSFORM(i) ENDFOR FOR i=1 TO 6 thisform.grid1.Columns(i+11).header1.caption=CHR(i+64) ENDFOR ENDPROC PROCEDURE command1.Click IF >0 =GETFILE("bmp") *!* cfile=GETFILE() 改这句可以查看任何类型文件。 IF EMPTY(cfile) OR !FILE(cfile) RETURN ENDIF thisform.label2.Caption=cfile thisform.string=FILETOSTR(cfile) nlen=LEN(thisform.string) npages=CEILING(nlen/80000) *************************为避免数据导入太大导致系统假死,故分页显示*********************** FOR i=1 TO npages (TRANSFORM(i)) ENDFOR zap ="1" &&记录当前页 *!* 因为combo1设置了programmaticchange事件,下面代码就不用了,重复 *!* IF VAL()=*!* nrow=ceiling(MOD(nlen,80000)/16) *!* ELSE *!* nrow=5000 &&每页最大显示5000行 *!* ENDIF *************************设置第一列*********************** *!* GO top *!* FOR i=1 TO nrow *!* APPEND BLANK *!* cstr=TRANSFORM((val()-1)*5000+i-1,"@0") *!* REPLACE 字节偏移 with SUBSTR(cstr,4,LEN(cstr)-2) *!* ENDFOR *************************将分页数据存在数组里,以便快速添加到表里*********************** *!* dispdata=SUBSTR(thisform.string,1,nrow*16) *!* DIMENSION colordata[nrow,16] *!* STORE 0 TO colordata &&对数组初始化,以防出现错误 *!* FOR i=2 TO LEN(dispdata) *!* colordata[i]=ASC(SUBSTR(dispdata,i-1,1)) *!* ENDFOR *!* *************************将数组数据复制到表里*********************** *!* GO top *!* REPLACE FROM ARRAY colordata FIELDS like f* for RECNO()<=5000 *!* thisform.grid1.Refresh() IF 1 ("Enabled",.t.) =.f. endif ENDPROC PROCEDURE commandgroup1.Click DO CASE CASE this.Value=1 IF 1" ="1" this.SetAll("enabled",.t.) =.f. =.f. ENDIF CASE this.Value=2 this.SetAll("enabled",.t.) IF VAL()=-1 =.f. ENDIF =TRANSFORM(VAL()+1) CASE this.Value=3 this.SetAll("enabled",.t.) IF ="2" =.f. ENDIF =TRANSFORM(VAL()-1) CASE this.Value=4 this.SetAll("enabled",.t.) IF () =transf() =.f. =.f. ENDIF ENDCASE ENDPROC PROCEDURE commandgroup1.Init lastleft=this.Buttons(1).left lastwidth=this.Buttons(1).width FOR i=2 TO this.ButtonCount this.buttons(i).top=this.buttons(1).top this.buttons(i).left=lastleft+lastwidth+2 lastleft=this.buttons(i).left lastwidth=this.buttons(i).width ENDFOR this.AutoSize=.t. this.setall("Enabled",.f.) ENDPROC PROCEDURE combo1.ProgrammaticChange this.InteractiveChange() ENDPROC PROCEDURE combo1.InteractiveChange ZAP nlen=LEN(thisform.string) IF VAL()==ceiling(MOD(nlen,80000)/16) ELSE nrow=5000 &&每页最大显示5000行 ENDIF *************************设置第一列*********************** FOR i=1 TO nrow APPEND BLANK cstr=TRANSFORM((val()-1)*5000+i-1,"@0") REPLACE 字节偏移 with SUBSTR(cstr,4,LEN(cstr)-2) ENDFOR *************************将分页数据存在数组里,以便快速添加到表里*********************** dispdata=SUBSTR(thisform.string,(val()-1)*80000+1,nrow*16) DIMENSION colordata[nrow,16] STORE 0 TO colordata &&对数组初始化,以防出现错误 FOR i=2 TO LEN(dispdata) colordata[i]=ASC(SUBSTR(dispdata,i-1,1)) ENDFOR *************************将数组数据复制到表里*********************** GO top REPLACE FROM ARRAY colordata FIELDS like f* for RECNO()<=5000 thisform.grid1.Refresh() DO CASE CASE this.ListCount=1 ("enabled",.f.) CASE this.Value="1" AND this.ListCount>1 = .F. = .F. CASE VAL(this.Value)=this.ListCount AND this.listcount>1 = .F. = .F. OTHERWISE ("enabled",.t.) ENDCASE ENDPROC ENDDEFINE * *-- EndDefine: form1 **************************************************
[此贴子已经被作者于2023-4-19 00:37编辑过]