| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2156 人关注过本帖, 1 人收藏
标题:分享一个16进制文件查看器,原创哦~
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:805
专家分:1231
注 册:2021-10-13
结帖率:96.83%
收藏(1)
已结贴  问题点数:20 回复次数:41 
分享一个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编辑过]

搜索更多相关主题的帖子: Value thisform Left this Top 
2023-04-19 00:34
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1790
专家分:3389
注 册:2012-2-29
收藏
得分:4 
谢谢分享!
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2023-4-19 06:47编辑过]

2023-04-19 06:03
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏(1)
得分:4 
简单的几句就可以
图片附件: 游客没有浏览图片的权限,请 登录注册

程序代码:
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)
i = 1
cHex = SUBSTR(cs,i,16)
nLen = LEN(cHex)
DO WHILE nLen > 0
    ALINES(arr,RIGHT(TRANSFORM(i-1,"@0"),8)+" "+TRANSFORM(STRCONV(cHex,15),"@R "+REPLICATE("## ",16)),15,0h20)
    INSERT INTO tt FROM ARRAY arr
    i = i + 16
    cHex = SUBSTR(cs,i,16)
    nLen = LEN(cHex)
ENDDO
SELECT * FROM tt
收到的鲜花
  • sam_jiang2023-04-19 12:43 送鲜花  1朵  
  • liunis2023-04-19 13:20 送鲜花  1朵  
  • igaoyuan2023-04-21 10:54 送鲜花  1朵  
2023-04-19 09:19
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1790
专家分:3389
注 册:2012-2-29
收藏
得分:0 
回复 3楼 吹水佬
简洁,谢谢!
2023-04-19 11:09
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:805
专家分:1231
注 册:2021-10-13
收藏
得分:0 
牛B class
2023-04-19 12:34
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:805
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 3楼 吹水佬
你们调入较大文件会不会卡?
2023-04-19 12:36
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
以下是引用sam_jiang在2023-4-19 12:36:39的发言:

你们调入较大文件会不会卡?

卡不卡要看文件大小。
FILETOSTR读文件相对FREAD理论上应该会快点,但一次全读入会受字符串大小限制。
2023-04-19 13:12
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏(2)
得分:0 
示例还可以简单一点,减少一些环节。
程序代码:
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)
i = 1
DO WHILE ALINES(arr,RIGHT(TRANSFORM(i-1,"@0"),8)+TRANSFORM(STRCONV(SUBSTR(cs,i,16),15),"@R "+REPLICATE(" ##",16)),15,0h20) > 1
    INSERT INTO tt FROM ARRAY arr
    i = i + 16
ENDDO
SELECT * FROM tt
2023-04-19 13:14
liunis
Rank: 1
等 级:新手上路
帖 子:142
专家分:7
注 册:2021-9-25
收藏
得分:4 
回复 8楼 吹水佬
大佬,改好后反向写回这个文件如何操作
2023-04-19 13:21
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:805
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 7楼 吹水佬
用你的代码读取一个2.79M的图片,也是很卡,可能是我的电脑问题?看来还是需要分页显示。。。

不过你的代码真的简洁,很受启发,谢谢!
2023-04-19 13:43
快速回复:分享一个16进制文件查看器,原创哦~
数据加载中...
 
   



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

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