Using shell extensions to implement the source Code statistics program

Source: Internet
Author: User
Tags call shell implement

First, the preface

In the Windows Explorer window, we have seen software such as Winzip,winrar can add a few menu items to the default shortcut menu in a file or folder, which allows users to operate directly in the windows without having to go inside the software, and is very user-friendly. This is certainly a good application model, it is what we call shell extension technology. This article will use a common source code statistics program as an example to illustrate how to implement shell expansion technology. Here's how the program works:

Figure One example code run effect diagram one

Figure Two example code run effect figure two

Ii. Principle of realization

In order to extend the default menu of files or folders in any Windows window, we must have Windows load our program segments in the Display shortcut menu, which we typically use with COM components to achieve this goal. COM components are divided into three kinds: in-process service programs, local service programs, and remote service programs. To get the Explorer to load and execute our code, of course, we have to use an in-process service, which is represented by a DLL, which is mapped to the virtual address space of the executable program after it is loaded, and we provide some interfaces to the explorer that the Explorer will call when the shortcut menu is displayed , we can do something we want to do in those interfaces, such as adding a shortcut menu, Implementing a menu item, and so on, to achieve the shell expansion.

As for source code statistics, it is not difficult to implement. Here I take the C + + style source code as an example, and apply one of the simplest statistical rules, when the statistics file, we read the contents of the code into the cache, to determine whether each character is a newline (\ n), if, the Count plus 1. Of course we are making statistics more meaningful, so we can use the recursive method to traverse all the files in the folder, find a valid file (here I only statistics C + + program, so only processing suffix named. C. Cpp. H's file), according to the previous method one by one statistics can find out all the code in the folder total number of rows.

Related Article

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.