[Vc6] image file format data viewer

Source: Internet
Author: User
Tags format definition

In rare cases today, we need to study the image file format unless in some specific scenarios. Here, I made such a small tool first. Currently, the BMP, ICO, and cur file formats can be displayed. In fact, as long as you know the format definition of a file, you can display any type of files (such as EXE, DLL, PSD, etc ), for example, in the next step, I may consider adding the PE File Format (executable files ). Of course, binary files are displayed here, that is, files that usually need to be viewed in a hexadecimal editor, text files like TXT are not defined in the file format (it only has the concept of Encoding ). I used it to display the ICO file format, while the BMP file format is the most basic, so it is the first function I added, for the file format of BMP, refer to the relevant description in msdn.

Keywords: treelist control, BMP file format, cximage, MFC, C ++, and VC.

For more information, see the end of this article.

The tool is as follows (to display the content of the BMP file). The icon in front of the tree node indicates the value of sizeof (bytes) of the node data ):

 

 

(1) I have referenced and used the treelist control in this article. The original source of the control may not be very accurate. You can obtain information from references. This control is equivalent to the combination of treectrl and listview and is not a standard control. So you need to customize it. My original idea was to maintain the data structure of a tree in the memory based on the List Control in VC, and then complete the control through list user painting. However, the treelist control I saw on codeproject.com is basically implemented based on treectrl + User plotting. This may be because:

(A) At the beginning, the author adopted treectrl-based implementation, and subsequent personnel referred to it, thus being inherited.

(B) Using treectrl as the basis is more convenient than using list as the basis, with less workload.

However, we can compare the two methods.

 

(A) treectrl-based: the advantage is that the basic control inherits the direction key navigation, Mouse clicking, double-clicking, and other operations on the tree from the keyboard. We do not need to perform more encoding. The disadvantage is that the mouse operation is unfriendly, And the hittest of treectrl is almost ineffective (because the node Text of the basic control cannot fully simulate the effect). When performing horizontal scrolling, because the basic control is not moved, therefore, some operations on the mouse are not friendly. (These are some of the disadvantages of the original control. I have made a lot of corrections and functions for the source code so that most of the flaws and shortcomings can be compensated and corrected ).

 

(B) list-based, with the advantage of flexible customization, it is easier to place the column where the tree is located in the middle (rather than the common first column) than the former ), because the behavior and appearance of the control are closer to the list in nature, you can imagine that the title and first-class mouse operations will be very correct for the control to be implemented in this way. The disadvantage is that we must maintain a logical structure of treectrl by ourselves, dynamically add, delete, and delete items in the list, and manually add related tree mouse and keyboard operations (such as fold and expand buttons. This is undoubtedly a great maintenance burden for us. In addition, due to the limited energy, we will use the achievements we have gained from our predecessors.

 

Because both of them must be customized, you can easily control the appearance of the column, for example, you can freely draw progress bars, icons, text, and so on.

 

I have made many changes to the original treectrl and added some features, such as whether to draw a grid, set the background color, grid color, and set whether to click the title header for sorting, at the same time, we also modified some settings for drawing and mouse response.CodeIt is basically the availability, ease of use, and user-friendly improvement of this control. It can be used smoothly and complete the functions I want, that is, to clearly display a series of file information. Maybe I can write another article about this control.ArticleIntroduce it, including my improvements to it and how to add it to your MFC ApplicationProgram. This article can be viewed as an example application of this control.

 

(2) because there are many bitmap types, such as indexes, true colors, and so on, they are not necessarily compatible with the DC we plot, so I finally decided to introduce the cximage code, to create a preview image. Of course, if you do not need to preview images, then all cximage code is not required.

 

This tool can be combined with a hexadecimal editor to view the original data of the file. The "Address" is the file address (hexadecimal), and the size is 10 hexadecimal (in bytes ). There is basically no technical research point for BMP file formats. However, for ICO, GIF, JPG and other image file formats, it is still not clear enough, of course, unless some file format plug-ins are made, there is no need to pay attention to these contents. In the next step, I plan to display the file format of ICO files (icons, cursors.

 

[Note] For the sake of simplicity, I did not strictly verify the validity of the file data in the code. I assume that all the BMP files read are correct and valid bitmap files, it is assumed that all memory allocations will not fail. This makes the code for reading files very concise and intuitive, but the exception handling cannot be omitted in actual development work.

 

This small program is developed using vc6 + MFC. Some feature symbols automatically generated by IDE have not been changed, such as application icons and dialog boxes, these external features are associated with specific ide versions and technologies. You can see that they are developed using vc6 and MFC. The information in the treelist control code, such as the window class name, has not been changed to show respect for the original author.

 

[Update ]:

The ICO and cur file formats are added at,. the cur file format is the same as the ICO file format. The effect is shown in (the ICO file content is displayed ):

When reading a super big image with a size greater than 255, the bug in calculating the data block size should be corrected at, (the image width and height in bitmapinfoheader should prevail ).

 

Add a view of the PE file format at, September 7. You can view the EXE/dll/ocx file. Shows the effect:

The original author of the treelist control used cstring to maintain the multi-column text of the node. However, exceptions are often triggered when node data is released in vc6 (I am not sure the specific cause at present, may be related to the MFC class library carried by vc6), so I changed the cstring object to the string object in the C ++ standard library. To clear the control node accidentally triggered exceptions.

 

The PE file format is usually used for cracking. People with viruses are very familiar with it, or people who want to study this field must be familiar with the format, although it always seems very simple, that's because I folded those complex nodes. However, in fact, some nodes are very complex (for example, image_optional_header), and there are many subnodes. Although there is only one code to add subnodes, this job still enables me to open another small project, to help me complete the code for adding subnodes (I copy the definition of the relevant structure to a text file, and then read it row by row using this applet, parse the member types and names, assemble them into code for adding sub-nodes, and write them into another text file. From the final source code, you can see that when the PE format is displayed, the code of the treelist control is filled, far exceeding the previous display of BMP and ICO file formats ), the opened EXE file is the Helper applet.

Because the PE format involves many structures and members, no matter where you read the materials, it takes some effort to figure out it, so this tool may be helpful. This tool converts a "linear byte stream" into a "Structured description" used for file format definition, and combines the two into a very intuitive understanding, it is helpful to quickly understand a file format that is not familiar enough. I personally think this is great. Complex file formats such as PE, if you do not have long-term contact, may soon forget his details.

Of course, the development of this tool is not my ultimate goal, because my ultimate goal is to create a file format plug-in for a commercial software, so before production, it is necessary to understand the file format to be processed, so that the prototype of this tool appears in my mind, and then I will create it first.

 

TheSource codeDownload link:

Http://files.cnblogs.com/hoodlum1980/BmpFileView_Src.rar

 

[Reference :]

For the treelist control, search for treelist on the codeproject website. Because I have made a lot of modifications and improvements to the original control, if you need this control, I suggest using the control code I provided in this article, it is more comprehensive and available than the original controls.

 

(1) extended tree list control;

(2) tree control with columns;

 

For cximage, you can load files in multiple image formats, such as BMP, JPG, GIF, ICO, and PNG.

(3) cximage Version 6.0.0 02/FEB/2008

 

For the ICO file format, refer to a Windows application developed by Microsoft pure Win32:

(4) iconpro tool source code and its help file;

 

For PE file formats, refer to the "PE File Format viewer" component in the "window viewer" that I released a few years ago (but it is clear that the current tool looks better .) :

(5) finally solved the problem of using the mouse to find the window in C #, which turned out to be so simple.

(6) The articles on the PE format in the collection of "see the best of snow Forum" are divided into multiple parts. The specific documents and authors are not detailed. The materials are from the "see snow Forum.

 

[Additional resources] are not the materials I have referenced in this article, but they can also be used by interested readers.

 

Here are some examples of Bitmap:

(1) Example BMP images (all windows V3 ready t as indicated );

 

BMP file format:

(2) BMP file format;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.