Five reverse lookup tools

Source: Internet
Author: User

1. Five reverse lookup tools

Maybe you will say, reverse lookup or something, just a map container to get it done, there is something to say. Indeed, the simplest thing is. Even so, you have to prepare words, five codes, a root chart, and their relationships. These are not readily available on the Internet, that is, you have to prepare yourself. The method I have prepared is to write a small crawler and get these items together on a five-time reverse lookup website (For details, refer to the previous article ). After preparing the most important part, it will take a bit more effort to make it more decent. So there is something to write.

Put a few pictures first, and then share the difficulties encountered when doing this.

 

2. Font root chart

There are a total of 6763 root charts. If you publish them directly, it is obviously not beautiful. Therefore, it is necessary to package and release it again. Unfortunately, no suitable packaging tool was found on the Internet (if you know, please tell me> _ <). There is only one way to do the rest-package your own. The packaging method I used is simple: create a file header that records the file offset, and put the image after the file header in order.

The offset of the record file is represented by the following class:

Struct fileindex {// auxiliary class, the offset of a single file in the package file
DWORD dwoffset; // The offset from the file header
DWORD dwsize; // the size of the image itself
Char szname [256]; // the original name of the image
};

If I package 1.gif, 2. gif to the file 0. Zero, the file structure of 0. Zero should be like this.

(2) (fileindex) (content of 1.gif) (content of 2.gif)

The above 2 indicates a total of two files or two fileindexes. The first fileindex is 1st. GIF information. The second fileindex is 2. GIF information, followed by 1. GIF and 2. GIF content

The specific packaging code is as follows:

// Package all files in the strsrcdirectory to strdestfile.
Bool cfilepack: makepack (const STD: string & strsrcdirectory, const STD: string & strdestfile ){
STD: vector <STD: String> arfilelist;
Cstring szdirectory;
Szdirectory. Format ("% s", strsrcdirectory. c_str ());
Getallfilenameindirectory (szdirectory, arfilelist); // put all file names in the specified folder in the vector container

File * fp = fopen (strdestfile. c_str (), "WB ");
If (! FP ){
Return false;
}

DWORD dwsize = arfilelist. Size ();
Fwrite (& dwsize, 1, 4, FP); // write a total of several files

Fileindex * pfilelist = new fileindex [arfilelist. Size ()];
Fwrite (pfilelist, 1, arfilelist. Size () * sizeof (fileindex), FP); // reserve a place to save the file offset information first

// Pack files in sequence
For (INT I = 0; I <arfilelist. Size (); ++ I)
{
Strcpy (pfilelist [I]. szname, arfilelist [I]. c_str ());
STD: String filepath = strsrcdirectory + "\" + arfilelist [I];
File * fbuf = fopen (filepath. c_str (), "rb ");
If (! Fbuf)
{
Fclose (FP );
Delete pfilelist;
Return false;
}
DWORD fsize = filelength (fileno (fbuf ));

Pfilelist [I]. dwsize = fsize;
Pfilelist [I]. dwoffset = ftell (FP );

Char * Buf = new char [fsize];
Fread (BUF, 1, fsize, fbuf );
Fclose (fbuf );

Fwrite (BUF, 1, fsize, FP );
Delete Buf;
}

// Write the file offset information to the reserved place
Fseek (FP, 4, seek_set );
Fwrite (pfilelist, 1, arfilelist. Size () * sizeof (fileindex), FP );

Fclose (FP );
Delete pfilelist;

Return true;
}

It is easy to extract the package. First, read all the fileindexes, find the corresponding fileindex Based on the file name, and then read the original content based on the offset value and file size.

 

3. Display GIF

The root image is in GIF format. The picture control of MFC does not support the GIF format... Unfortunately, third-party image display support is easily available. After some comparison, we finally chose pictureex. The reason is that pictureex is very small and has only one header file and one CPP file. In addition, it is easy to use: Call load (image path) and then call draw () to display the image. However, I have already packaged all the images into a file. Do I have to read the image content before writing it to XX. gif? Before answering this question, let's take a look at the loading methods.

 // loads a picture from a file
// i.e. Load(_T("mypic.gif"));
BOOL Load(LPCTSTR szFileName);

// loads a picture from a global memory block (allocated by GlobalAlloc)
// Warning: this function DOES NOT free the global memory, pointed to by hGlobal
BOOL Load(HGLOBAL hGlobal, DWORD dwSize);

// loads a picture from a program resource
// i.e. Load(MAKEINTRESOURCE(IDR_MYPIC),_T("GIFTYPE"));
BOOL Load(LPCTSTR szResourceName,LPCTSTR szResourceType);

From the above description, we can use the second form of reload-display the content of a memory block as the image content. The specific method is to read the image content from the package file, copy it To the memory block referred to by hglobal, and call the load function. The Code is as follows:

// Display the image specified by filename
Void cwubifangcha_zerodlg: display86zigen (cstring filename ){
STD: String strfilename (filename. getbuffer (0 ));
Char * Buf = m_packfile.getfile (strfilename); // read the content of the specified filename file from the package file

If (BUF ){
Int ifilesize = m_packfile.getfilesize (strfilename); // get the size of the file specified by filename
Hglobal = globalalloc (gmem_moveable, ifilesize );
If (hglobal = NULL ){
MessageBox (_ T ("insufficient memory "));
Afxpostquitmessage (0); // exit the program
}

Lpvoid pvdata = globallock (hglobal );
If (pvdata = NULL ){
Globalunlock (hglobal );
MessageBox (_ T ("memory cannot be locked "));
Afxpostquitmessage (0 );
}

Memcpy (pvdata, Buf, ifilesize );
Globalunlock (hglobal );
M_86zigen.load (hglobal, ifilesize); // read the image content
M_86zigen.draw (); // display the image

Delete [] Buf;
: Globalfree (hglobal );
}

Filename. releasebuffer ();
}


4. Resources

A. pictureex

Http://ishare.iask.sina.com.cn/f/22351801.html

B. Five lookups _ zero V1.0

Http://ishare.iask.sina.com.cn/f/22375411.html

Introduction to C. mfc42d. dll

Http://www.cppblog.com/duqingwei/archive/2011/06/12/148545.html

 

// Configure //-----------------------------------------------------------------------------------------

Updated on March 25

Thanks to LCS-Shuai for not running the problem. The missing mfc42d. dll is required by the debug version. Now it is changed to the release version and used for static compilation.

If you have any questions, leave a message.

 

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.