Go Windows Programming Naming conventions

Source: Internet
Author: User
Tags naming convention

The Hungarian nomenclature is a naming convention when programming. The basic principle is: variable name = attribute + Type + object description. Each object's name requires a clear meaning and can take the full name of the object or part of the name. Naming is based on the principle that easy memory is easy to understand. The naming conventions currently used in Windows Program development and MFC program development are Hungarian nomenclature. Here is the general rule of the HN nomenclature.

Properties section
Global variable G_
CONST constant C_
C + + class member variable m_
Static variable S_

Type section
Pointer P
Invalid V
Handle h
Long integral type L
Boolean b
Floating point type (sometimes referred to as a file) F
Dual-word DW
String sz
Short-integer n
Double precision floating point D
Count C (usually CNT)
Character ch (usually in C)
Integral type I (usually N)
Word w
Real Type R
unsigned u

Description section
Max Max
Min min
Initialize Init
Temp variable T (or temp)
Source Object Src
Destination Object Dest

Here are a few examples to write about:
(1) Hwnd:h is a type description, representing a handle, WND is a variable object description, representing the window, so the HWND represents the window handle;
(2) PFNEATAPPLE:PFN is a type description that represents a pointer to a function, Eatapple is a variable object description, so it represents
A function pointer variable that points to the Eatapple function.
(3) G_cch:g_ is a property description, representing a global variable, and C and CH are count types and character types, together representing variable classes
Type, where the object description is omitted, so it represents a global variable that counts the characters. Summary: Hungarian nomenclature

Naming conventions for MFC, handles, controls, and structs Windows Type Sample variables MFC Class Sample variables
HWND hwnd; cwnd* pWnd;
Hdlg hdlg; cdialog* Pdlg;
HDC hdc; cdc* PDC;
Hgdiobj hgdiobj; cgdiobject* pgdiobj;
Hpen hpen; cpen* Ppen;
Hbrush hbrush; cbrush* Pbrush;
Hfont hfont; cfont* Pfont;
Hbitmap hbitmap; cbitmap* Pbitmap;
Hpalette Hpaltte; cpalette* Ppalette;
HRGN HRGN; crgn* prgn;
HMENU HMENU; cmenu* Pmenu;
HWND hctl; cstate* pState;
HWND hctl; cbutton* Pbutton;
HWND hctl; cedit* pEdit;
HWND hctl; clistbox* Plistbox;
HWND hctl; ccombobox* Pcombobox;
HWND hctl; cscrollbar* Pscrollbar;
HSZ hszstr; CString pStr;
Point pt; CPoint pt;
Size size; CSize size;
Rect rect; CRect rect;

Generic prefix naming specification prefix type instance
Class C or structure cdocument,cprintinfo
M_ member Variable M_pdoc,m_ncustomers

Variable naming specification prefix type description instance
CH Char 8-bit character Chgrade
Ch TCHAR If _UNICODE is defined, it is a 16-bit character chname
b bool Boolean value benable
n int integer (its size depends on the operating system) nlength
n UINT unsigned value (its size depends on the operating system) nheight
W WORD 16-bit unsigned value Wpos
L LONG 32-bit signed integer loffset
DW DWORD 32-bit unsigned integer dwrange
p * Pointer PDoc
LP far* far pointer lpszName
Lpsz LPSTR 32-bit string pointer lpszName
Lpsz LPCSTR 32-bit constant string pointer lpszName
Lpsz LPCTSTR If _UNICODE is defined, it is a 32-bit constant string pointer lpszName
H handle Windows object handle HWND
LPFN callback pointer to callback function

Resource type naming specification prefix symbol type instance scope
Idr_ multiple resource sharing identities for different types Idr_maiinframe 1~0X6FFF
Idd_ Dialog Resource Idd_spell_check 1~0x6fff
Hidd_ dialog resource's help context Hidd_spell_check 0X20001~0X26FF
Idb_ Bitmap Resource Idb_company_logo 1~0x6fff
IDC_ Cursor Resource Idc_pencil 1~0X6FFF
Idi_ icon Resource Idi_notepad 1~0x6fff
Id_ commands from a menu item or toolbar id_tools_spelling 0X8000~0XDFFF
HID_ Command Help Context hid_tools_spelling 0X18000~0X1DFFF
IDP_ message box prompt Idp_invalid_partno 8~0xdeef
HIDP_ message Box Help context Hidp_invalid_partno 0x30008~0x3deff
Ids_ String Resources Ids_copyright 1~0x7eef
IDC_ controls in the dialog box Idc_recalc 8~0xdeef

Microsoft MFC macro Naming Specification name type
_afxdll unique dynamic Link Library,dll version
_alpha only the DEC ALPHA processor is compiled
_DEBUG includes debug versions of diagnostics
_mbcs Compiling multibyte character sets
_unicode to open UNICODE in an application
AFXAPI functions provided by MFC
CALLBACK functions that pass the pointer callback

Library identifier naming method identifier value and meaning
U ANSI (N) or Unicode (U)
D Debug or Release: D = Debug; Ignore identifier for release.

Static library version naming specification library description
NAFXCWD. LIB Debug Version: MFC Static Connection Library
NAFXCW. LIB release Version: MFC static Connection Library
UAFXCWD. LIB Debug Version: MFC static connection library with Unicode support
UAFXCW. LIB release Version: MFC static connection library with Unicode support

Dynamic Connection Library naming specification name type
_afxdll Unique Dynamic Connection library (DLL) version
WINAPI functions provided by Windows

Description of the new naming specification type definition in Windows.h
WINAPI uses the far Pascal location in the API declaration, if you are writing a DLL with an exported API population point, you can use that type in your own API
CALLBACK uses the location of Far Pascal in application callback routines, such as Windows and dialog boxes
LPCSTR is the same as LPSTR, except that LPCSTR is used for read-only string pointers and is similar in definition (const char far*)
UINT Portable unsigned integer type, which is a synonym for unsigned int
LRESULT the type of the return value of the window program
LPARAM declares the type used by LPARAM, LPARAM is the fourth parameter of a window program
WPARAM declares the type used by WPARAM, WPARAM is the third parameter of a window program
LPVOID generic pointer type, same as (void *), can be used instead of LPSTR Hungarian programming naming conventions The Hungarian nomenclature includes conventions relating to the following names: variables, functions, types and constants, classes.

(1) The Hungarian nomenclature of variables.
With the Hungarian nomenclature, all variable names should appear in the form of a prefix + name. Like what:

char* SzName; A string with a 0 terminator, which stores the name variable
BOOL Bcanexit; Boolean variable, can you exit?
DWORD Dwmaxcount; 32-bit double-character variable, maximum count

(2) The Hungarian nomenclature of functions.
Unlike the name of a variable, a function is named without a prefix, and the first letter of each word in the function is capitalized. Like what:

int convertnumber (int ix);
void ShowMessage (char* szmessage);

(3) Hungarian nomenclature of types and constants.
All types and constants are named in uppercase letters, such as:

#define MAX_NUM 256
typedef unsigned char UCHAR;

(4) The Hungarian nomenclature of the class.
The naming convention for a class is to precede the name with a letter C, for example:

Class CMyClass
CMyClass ();
~cmyclass ();

When you name a member variable of a class, you typically precede the variable name with the m_ prefix. In general, it is best to program according to this rule, so that you can understand the role of variables more quickly when you read the program or modify the program later.

Reprinted from: http://blog.sina.com.cn/s/blog_52cbfc3f0100fdy6.html

Go Windows Programming Naming conventions

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.