A text skin replacement method for the Program Interface

Source: Internet
Author: User
A program interface text skin replacement method aiguille. LIU2008-11-23 for GUI programs, the interface will present a lot of pictures and text information. Images are generally loaded from the external during running, making it easier to replace. However, most of the text information is directly written in the program code. In this case, if you want to change the text, you need to re-compile the program, which is very inconvenient. This article introduces a text skin replacement method for the program interface, which can be used for OEM or multilingual scenarios without re-compiling the program. 1. The text displayed on all interfaces of the dictionary library is stored in the dictionary library. It is a program-independent file. Files can be plain text, encrypted text, dynamic link library, or any other form. When running the program, read the required text information from the dictionary. Therefore, when you need to modify the interface text, you only need to modify the dictionary library and then publish it. The application does not need to be modified or re-compiled. For example, app. dic: [App] app_name = program name app_caption = program title app_version = program version app_copyright = program copyright 2. dictionary database access interface API there is only one API here, that is, extract text information from the dictionary. The function prototype can be as follows: char * get_dictionary (char * dictionary, char * Section, char * Key); where, dictionary is the dictionary file name; section is the shard name, as shown in [App] above; the key is the identifier of the specified text information, and the return value is the text information corresponding to the dictionary. The specific implementation can be determined based on the actual situation. In fact, many development tools provide similar APIs. We only need to encapsulate them in a simple way. 3. Call get_dictionary () to obtain the required text. However, in some cases, text information in the form of constants, such as the initialization structure or class, must be used. In this case, you cannot use the API. However, macro definitions can be used to achieve this purpose. The macro definition is similar to the following: # defineget_dictionary (key) get_dictionary ("app. dic "," app ", Key), whether it is a constant or variable string, we can use get_dictionary to assign values. 4. A simple example
  1. /*
  2. * Demo. DIC
  3. */
  4. [Demo]
  5. Demo_zh = This is a demo
  6. Demo_us = This is a demo
  7. /*
  8. * Dict. h
  9. */
  10. # Ifndef _ dict_h
  11. # DEFINE _ dict_h
  12. Inline char * get_dictionary (char * dictionary, char * Section, char * key)
  13. {
  14. // Implemented based on actual conditions
  15. }
  16. # Endif
  17. /*
  18. * Demo. c
  19. */
  20. # Include "dict. H"
  21. # Define get_dictionary (key) get_dictionary ("demo. DIC", "Demo", key)
  22. Int main (INT argc, char * argv [])
  23. {
  24. Printf ("% s/n", get_dictionary ("demo_zh "));
  25. Printf ("% s/n", get_dictionary ("demo_us "));
  26. Return 0;
  27. }

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.