| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2114 人关注过本帖, 1 人收藏
标题:分享一个16进制文件查看器,原创哦~
只看楼主 加入收藏
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:708
专家分:2848
注 册:2018-3-13
收藏
得分:0 
因为是两个有符号参数,我先担心 vfp 会把 0x8000,0000 变成负数形式传给第一个参数
刚试了试,传 -1 进去会返回 3.99GB,这就大致清楚了

这家伙很懒,啥也没留下
2023-04-21 00:05
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
收藏
得分:0 
附上完整代码。
改进如下:
1,分页显示不同格式的数据,16进制,10进制,以及字符。
2,改进分页显示下,第一行第一列数据为零的问题。
程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\bmpviewer.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   04/22/23 02:52:02 PM
*
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 label2 AS label WITH ;
        AutoSize = .T., ;
        Caption = "", ;
        Height = 16, ;
        Left = 100, ;
        Top = 6, ;
        Width = 2, ;
        Name = "Label2"


    ADD OBJECT pageframe1 AS pageframe WITH ;
        ErasePage = .T., ;
        PageCount = 3, ;
        TabStyle = 1, ;
        Top = 66, ;
        Left = 1, ;
        Width = 852, ;
        Height = 587, ;
        TabOrientation = 1, ;
        Name = "Pageframe1", ;
        Page1.Caption = "Num", ;
        Page1.Name = "Page1", ;
        Page2.Caption = "Hex", ;
        Page2.Name = "Page2", ;
        Page3.Caption = "Str", ;
        Page3.Name = "Page3"


    ADD OBJECT form1.pageframe1.page1.grid1 AS grid WITH ;
        Height = 558, ;
        Left = 0, ;
        Top = 0, ;
        Width = 847, ;
        Name = "Grid1"


    ADD OBJECT form1.pageframe1.page2.grid1 AS grid WITH ;
        Height = 558, ;
        Left = 0, ;
        Top = 0, ;
        Width = 847, ;
        Name = "Grid1"


    ADD OBJECT form1.pageframe1.page3.grid1 AS grid WITH ;
        Height = 558, ;
        Left = 0, ;
        Top = 0, ;
        Width = 847, ;
        Name = "Grid1"


    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.pageframe1.page1.grid1.RecordSourceType= 1
        thisform.pageframe1.page1.grid1.RecordSource="temp"

        FOR i=0 TO 9
            thisform.pageframe1.page1.grid1.Columns(i+2).header1.caption=TRANSFORM(i)
        ENDFOR
        FOR i=1 TO 6
            thisform.pageframe1.page1.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
        ="1" &&记录当前页

        IF 1
            ("Enabled",.t.)
            =.f.
        ENDIF

        *!*    DECLARE long malloc IN msvcrt as apiMalloc long
        *!*    DECLARE long free   IN msvcrt as apiFree   long

        *!*    CREATE CURSOR tt (字节偏移 c(8),f0 c(2),f1 c(2),f2 c(2),f3 c(2),f4 c(2),f5 c(2),f6 c(2),f7 c(2),;
        *!*                                    f8 c(2),f9 c(2),fa c(2),fb c(2),fc c(2),fd c(2),fe c(2),ff c(2))
        *!*    fn = GETFILE()
        *!*    IF !FILE(fn)
        *!*        RETURN 
        *!*    ENDIF
        *!*    cs = FILETOSTR(fn)
        *!*    n  = LEN(cs)
        *!*    ps = apiMalloc(n)
        *!*    IF ps == 0
        *!*        ? "分配内存失败"
        *!*        RETURN 
        *!*    ENDIF
        *!*    p = ps
        *!*    SYS(2600,p,n,cs)
        *!*    m = 0
        *!*    DO WHILE m < n
        *!*        ALINES(arr,RIGHT(TRANSFORM(m,"@0"),8)+TRANSFORM(STRCONV(SYS(2600,p,IIF((n-m)<16,n-m,16)),15),"@R "+REPLICATE(" ##",16)),15,0h20)
        *!*        INSERT INTO tt FROM ARRAY arr
        *!*        p = p + 16
        *!*        m = m + 16
        *!*    ENDDO
        *!*    apiFree(ps)
        *!*    *SELECT * FROM tt

        *!*    thisform.grid1.RecordSourceType = 1
        *!*    thisform.grid1.RecordSource ="tt"
    ENDPROC


    PROCEDURE commandgroup1.Click
        thisform.pageframe1.ActivePage=1
        thisform.pageframe1.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
        thisform.pageframe1.ActivePage=1
        thisform.pageframe1.Click()
        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(CHR(0)+thisform.string,(val()-1)*80000+1,nrow*16)
        &&数组下标是从1开始的,而表格的第一列的坐标是0,0,dispdata的第一个数据实际上是数组的第二个元素。在dispdata的最前面加个空字符,就解决了。
        DIMENSION colordata[nrow,16]
        STORE 0 TO colordata &&对数组初始化,以防出现错误
        FOR i=1 TO LEN(dispdata)
            colordata[i]=ASC(SUBSTR(dispdata,i,1))
        ENDFOR
        *************************将数组数据复制到表里***********************
        GO top
        REPLACE FROM ARRAY colordata FIELDS like f* for RECNO()<=5000
        thisform.pageframe1.page1.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

        *!*    fn = GETFILE()
        *!*    IF !FILE(fn)
        *!*        RETURN 
        *!*    ENDIF
        *!*    fp = FOPEN(fn)
        *!*    i = 0
        *!*    DO WHILE ALINES(arr,RIGHT(TRANSFORM(i,"@0"),8)+TRANSFORM(STRCONV(FREAD(fp,16),15),"@R "+REPLICATE(" ##",16)),15,0h20) > 1
        *!*        INSERT INTO temp FROM ARRAY arr
        *!*        i = i + 16
        *!*    ENDDO
        *!*    FCLOSE(fp)
    ENDPROC


    PROCEDURE pageframe1.Click
        DO CASE 
            CASE this.ActivePage=1
                SELECT temp

            case this.ActivePage=2
        *!*            MESSAGEBOX("You have clicked page2!")
                SELECT 字节偏移,RIGHT(TRANSFORM(f1,'@0'),2) as h0,;
                    RIGHT(TRANSFORM(f2,'@0'),2) as h1,;
                    RIGHT(TRANSFORM(f3,'@0'),2) as h2,;
                    RIGHT(TRANSFORM(f4,'@0'),2) as h3,;
                    RIGHT(TRANSFORM(f5,'@0'),2) as h4,;
                    RIGHT(TRANSFORM(f6,'@0'),2) as h5,;
                    RIGHT(TRANSFORM(f7,'@0'),2) as h6,;
                    RIGHT(TRANSFORM(f8,'@0'),2) as h7,;
                    RIGHT(TRANSFORM(f9,'@0'),2) as h8,;
                    RIGHT(TRANSFORM(f10,'@0'),2) as h9,;
                    RIGHT(TRANSFORM(f11,'@0'),2) as h10,;
                    RIGHT(TRANSFORM(f12,'@0'),2) as h11,;
                    RIGHT(TRANSFORM(f13,'@0'),2) as h12,;
                    RIGHT(TRANSFORM(f14,'@0'),2) as h13,;
                    RIGHT(TRANSFORM(f15,'@0'),2) as h14,;
                    RIGHT(TRANSFORM(f16,'@0'),2) as h15;
                    FROM temp INTO CURSOR temp1
                this.page2.grid1.recordsourcetype=1
                this.page2.grid1.recordsource="temp1"
                FOR i=0 TO 9
                    this.page2.grid1.Columns(i+2).header1.caption=TRANSFORM(i)
                ENDFOR
                FOR i=1 TO 6
                    this.page2.grid1.Columns(i+11).header1.caption=CHR(i+64)
                ENDFOR
                this.page2.grid1.setall("width",24)
                this.page2.grid1.Columns(1).width=55
            CASE this.ActivePage =3
                SELECT 字节偏移,CHR(f1) as h0,;
                    chr(f2) as h1,;
                    chr(f3) as h2,;
                    chr(f4) as h3,;
                    chr(f5) as h4,;
                    chr(f6) as h5,;
                    chr(f7) as h6,;
                    chr(f8) as h7,;
                    chr(f9) as h8,;
                    chr(f10) as h9,;
                    chr(f11) as h10,;
                    chr(f12) as h11,;
                    chr(f13) as h12,;
                    chr(f14) as h13,;
                    chr(f15) as h14,;
                    chr(f16) as h15;
                    FROM temp INTO CURSOR temp2
                this.page3.grid1.recordsourcetype=1
                this.page3.grid1.recordsource="temp2"
                FOR i=0 TO 9
                    this.page3.grid1.Columns(i+2).header1.caption=TRANSFORM(i)
                ENDFOR
                FOR i=1 TO 6
                    this.page3.grid1.Columns(i+11).header1.caption=CHR(i+64)
                ENDFOR
                this.page3.grid1.setall("width",24)
                this.page3.grid1.Columns(1).width=55
        ENDCASE 
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

2023-04-22 15:01
快速回复:分享一个16进制文件查看器,原创哦~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045191 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved