Naming Specification for MFC, handle, control and structure
Windows type sample variable MFC class sample variable HWNDhWnd; CWnd * pWnd; HDLGhDlg; CDialog * pDlg; HDChDC; CDC * pDC; HGDIOBJhGdiObj; CGdiObject * pGdiObj; HPENhPen; CPen * pPen; HBRUSHhBrush; 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;
General prefix naming specification
Prefix type example Class C or structure cDocument, CPrintInFom_ member variable m_pdoc, m_ncustomers
Variable naming specification
Prefix Type Description Instance Chchar8 Bit Character Chgradech Tchar If _unicode definition, 16-bit character chnamebbool Boolean Benablen int integer (whose size depends on operating system) NLENGTHN UINT No symbol value (whose size depends on operating system) NHEighTW Word 16 Non-symbolic WPOSL Long 32-bit Symbol Integer LoffSetDW DWORD 32-bit No Symbol Integer DWRANGEP * Pointer PDOCLP FAR * Far Pointer LPSZNAMELPSZ LPSTR 32 Bit Characters LPSZNAMELPSZ LPCSTR 32-bit Constant string pointer Lpsznamelpsz lpctstr If _unicode definition, The 32-bit constant string pointer lpsznameh handle windows object handle hwndlpfn callback points to the far pointer to the Callback function
Application symbol naming specification
Examples of types of symbols prefixed range IDR_ Help context HIDD_SPELL_CHECK plurality of different types of resource-sharing identification IDR_MAIINFRAME1 ~ 0x6FFFIDD_ dialog resource IDD_SPELL_CHECK 1 ~ 0x6FFFHIDD_ dialog resource 0x20001 ~ 0x26FFIDB_ bitmap resource IDB_COMPANY_LOGO 1 ~ 0x6FFFIDC_ cursor resource IDC_PENCIL 1 ~ 0x6FFFIDI _ icon resource IDI_NOTEPAD 1 ~ 0x6FFFID_ command from the menu or toolbar ID_TOOLS_SPELLING 0x8000 ~ 0xDFFFHID_ command Help context HID_TOOLS_SPELLING 0x18000 ~ 0x1DFFFIDP_ message box prompts IDP_INVALID_PARTNO 8 ~ 0xDEEFHIDP_ message box Help context HIDP_INVALID_PARTNO 0x30008 ~ 0x3DEFFIDS_ string resources IDS_COPYRIGHT 1 ~ 0x7eefidc_ dialog box Control IDC_Recalc 8 ~ 0xdeefmicrosoft MFC Macro Name Specification
Name Type_Afxdll Unique Dynamic Library (DLL) version _alpha only compiles DEC Alpha processors _debug includes the diagnostic debug version _mbCS compile multi-byte character set _Unicode Open UnicodeafxAPI MFC in an application Function of function Callback passes the function of the pointer callback
Library identifier nomenclature
Identifiers and Meaning U ANSI (N) or Unicode (U) D debug or release: d = debug; ignore the identifier is issued.
Static library version naming specification
Description Nafxcwd.lib debug version: MFC Static connection library NAFXCW.LIB Release: MFC Static connection library uafxcwd.lib debug version: MFC static connection library with Unicode support UAFXCW.LIB Release: MFC static connection library supported by Unicode
Dynamic connection library naming specification
Name Type_AFXDLL Unique Dynamic Connection Library (DLL) Version WINAPI Windows Functions Provided
New naming specification in Windows.h
Type Definition Description WinAPI uses the FAR Pascal location in the API declaration, if you are writing a DLL with exporting API people, you can use this type of Callback in your own API to use in the application recursive routine, such as windows and conversations The position LPCSTR of the FAR PASCAL in the frame is the same as LPSTR, just LPCSTR is used for read-only string pointers, which defines similar (const char far *) uint-free integer type, whose size is determined by host environment (for Windows NT and Windows 9x are 32 bits); it is the synonym of unsigned int LRESULT window program Return Value LPARAM declares that the type used by LPARAM, LPARAM is the fourth parameter of the window, WPARAM is used, WPARAM is a window. The third parameter of the program LPVOID general pointer type, with (void *), can be used instead of LPSTR
Below you are available from the document collection
1.1 Construction Hungary Name
A usual Hungary name is spliced by one or more prefixes, a basic identity (Base Tag) and a modifier. The basic identifier indicates the type of variable (such as "CO" representing color), the prefix corrects the type (such as "RG" means an array, then "RGCO" means a color array), the modifier describes the particular type of application (such as " RgCography "means a color array for grayscale). Not all the names use all of the components, the prefix is often unwanted, and when the type of application is obvious, the modifier can also be omitted when only one related type is included in the criterion. It is worth reminding that many (perhaps most) Basic identity and modifiers will be applications because they are used to represent the type and application of the application definition. Although we have defined standard identities for some basic types (part of it will be listed below), it is incorrect with these standard identifiers more suitable for applications with abstract types. For example, if a color is implemented with long, some people may use "RGL" to identify a color array, but this will destroy abstraction to Color.
When the Hungarian nomenclature is used for function name, the modifier usually identifies the action of the function. It is sometimes useful for Hungarian types that add a description of the function parameters after the basic identifier. Of course, the first letters of the function name must be capitalized. For example, "FinitFoofromhWndxy" should be a function of a function, which will use the type of HWND, X and Y to initialize a "foo" structure, and return a Boolean success code. This approach is not mandatory, only when this will make function names easier to understand.
1.2 Standard Basic Identification
The standard basic identification of the basic type is given in the table below. As mentioned above, the application will define many own identities for their internal types.
f Sign (BOOL). Value is True or False. The modifier should be described when the flag is TRUE, such as Ferror indicates that the variable is TRUE when an error occurs. CH single-byte character (char). SZ ends with a CHAR type string (classic C string). Sometimes the maximum length of the string can be described, such as "SZ255" means that the actual character string can accommodate 255 characters, so 256 characters must be assigned. ST band length prefix CHAR type string. This string length does not exceed 255 characters because its length must be stored in one byte. Like SZ, you can use "ST32" to indicate the maximum length of 32, so you need to assign 33 characterspace to store the character and its length. The STZ band length prefix also also is also a CHAR type string ending at 0. Note If you describe the length Length in the name, then at least you must allocate Length 2 char. CHW, WT, WZ, WTZ
Wide Character (Wchar) version of CH, SZ, ST, and STZ. All end user visible strings must use a wide string (Unicode). FN function. Typically and "P" prefix (see below) to use "PFN" because only function addresses can be stored in variables in C. b A Byte. W A 16-bit unsigned number value (Word, Short, or Ushort). DW
A 32-bit unsigned double word (DWORD). l A long (with a sign 32 digit value). U One unsigned long integer (Ulong). In the classic Hungarian nomenclature, this represents an unsigned word, in Office, which represents an unsigned 32-bit number value, which is the same as "DW", but when the type is more than the "U" identifier (and Ulong type). v Void type. Always use "P" to make "PV", identify pointers to unknown types. Scole Scode HR
Ole HRESULT VAR
Ole Variant Varg
Ole Variantarg
1.3 standard prefix
A standard prefix for modifying the basic identification type is given in the table below. One or more prefixes can be used. Applications are possible (but maybe rare) need to define their own prefix (typical case is that an application will only define basic identity and modifiers).
p pointer. For example, the "PCH" identifier points to a character, in the classic Microsoft Hungarian nomenclature, "P" represents Near Pointer, "LP" and "HP" are used to represent long (far) Pointer and HUGE POIIInter. In the 32-bit world, this is no longer a problem. RG array (change from "Range"). For example, "RGCH" means a character array. Like the C / C usage, this can be a name of a nice array, or the name of the pointer to the array. i 's basic type of array index. For example, "ICH" means an index of the character array. C The total number of basic type items. For example, "CCH" indicates the total number of characters. n The other represents the prefix of the total number of a basic type project (indicating "number of"), but it is best to use "C". D a difference between a basic type value, such as "DX" indicates the difference in the value of two types x. H handle. A non-transparent reference to a basic type item that cannot be indirectly accessed by the user (in the past use this is because there is a different usage of removable memory blocks). For example, "hWnd" is a handle to the window ("WND"), because the handle is not in your address space, so you do not allow you to access the domain in the window structure (this also maintains an abstraction of non-transparent references). An application module should lead to a handle to an abstract data type (typically defined as VOID *) so that customers can only use this reference and absolutely unable to see the data domain. However, in C , since the pointer to the key object can be drawn through private data, it is not necessary. PL
A "from" object (a "Plex" of Objects). This is another option other than the simple array ("rg"), indicating an array of variable modes using Plex (see Inc / Msoalloc.h). MP is used to map indexes or other scales to an array of values. This prefix should be added to the index and value identifier, such as "MPCHDX" indicates an array that maps the character value (as an array index) to the DX value corresponding to the character. V Global variables, always the first prefix.
In addition, we can add some prefixed to any Hungarian naming prefix before appropriate:
M_ C class data member. Static data member of the S_ C class. Global functions taken by MSO. The custom type of MSO. Global constant or global variables from MSO.
1.4 Standard modifiers Most modifications are defined in accordance with the occasions used, but there are still some predefined standard modifiers as follows:
The first element of the first element or the first element of interest (such as PCHFirst). The last original or last interested element in the Last collection (such as PCHLAST). When used as an index, Last represents the last legitimate / desired value, so the loop can be defined as follows: for (ICH = ICHFirst; ICH <= ICHLAST; ICH ) Lim set The upper limit of the elements. Unlike LAST, LIM does not represent legal values, LIM is the last legal value plus 1, so the loop can be defined below: for (ICH = ICHFirst; ICH The situation is slightly special when using the Hungarian nomenclature in VB Since VB is not case sensitive, the meaningful naming rules should be more meaningful.