このサンプル シリーズでは、明確さと一貫性を確保するために、コーディング スタイル規則を使用します。 "ハンガリー語" 表記規則が使用されます。 これらは、Win32 プログラミングの一般的なコーディングプラクティスとなっています。 変数名に変数の型の提案を与える変数プレフィックス表記が含まれます。
次の表に、一般的なプレフィックスを示します。
| Prefix | 説明 |
|---|---|
| a | Array |
| b | BOOL (int) |
| c | Char |
| cb | バイト数 |
| cr | 色参照値 |
| Cx | x の数 (short) |
| dw | DWORD (unsigned long) |
| f | フラグ (通常は複数のビット値) |
| fn | 機能 |
| G_ | グローバル |
| h | Handle |
| i | 整数 |
| l | Long |
| lp | 長いポインター |
| M_ | クラスのデータ メンバー |
| n | 短い int |
| p | ポインター |
| s | String |
| sz | 0 個の終了文字列 |
| tm | テキスト メトリック |
| u | Unsigned int |
| Ul | Unsigned long (ULONG) |
| 。 | WORD (符号なし short) |
| x,y | x、y 座標 (short) |
これらは、多くの場合、次のように組み合わされます。
| プレフィックスの組み合わせ | 説明 |
|---|---|
| pszMyString | 文字列へのポインター。 |
| m_pszMyString | クラスのデータ メンバーである文字列へのポインター。 |
その他の規則を次の表に示します。
| 表記 | 説明 |
|---|---|
| CMyClass | C++ クラス名のプレフィックス 'C'。 |
| COMyObjectClass | COM オブジェクト クラス名のプレフィックス 'CO'。 |
| CFMyClassFactory | COM クラス ファクトリ名のプレフィックス 'CF'。 |
| IMyInterface | COM インターフェイス クラス名のプレフィックス 'I'。 |
| CImpIMyInterface | COM インターフェイス実装クラスのプレフィックス 'CImpI'。 |
コメント ヘッダー ブロックの一貫性のある規則の一部は、次のようにこのサンプル シリーズで使用されます。
ファイル ヘッダー
/*+===================================================================
File: MYFILE.EXT
Summary: Brief summary of the file contents and purpose.
Classes: Classes declared or used (in source files).
Functions: Functions exported (in source files).
Origin: Indications of where content may have come from. This
is not a change history but rather a reference to the
editor-inheritance behind the content or other
indications about the origin of the source.
Copyright and Legal notices.
Copyright and Legal notices.
===================================================================+*/
プレーン コメント ブロック
/*--------------------------------------------------------------------
Plain block of comment text that usually takes several lines.
Plain block of comment text that usually takes several lines.
--------------------------------------------------------------------*/
クラス宣言ヘッダー
/*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
Class: CMyClass
Summary: Short summary of purpose and content of CMyClass.
Short summary of purpose and content of CMyClass.
Methods: MyMethodOne
Short description of MyMethodOne.
MyMethodTwo
Short description of MyMethodTwo.
CMyClass
Constructor.
~CMyClass
Destructor.
C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
クラス メソッド定義ヘッダー
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CMyClass::MyMethodOne
Summary: Short summary of purpose and content of MyMethodOne.
Short summary of purpose and content of MyMethodOne.
Args: MYTYPE MyArgOne
Short description of argument MyArgOne.
MYTYPE MyArgTwo
Short description of argument MyArgTwo.
Modifies: [list of member data variables modified by this method].
Returns: MYRETURNTYPE
Short description of meaning of the return type values.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
エクスポートされていない関数またはローカル関数
/*F+F+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: MyLocalFunction
Summary: What MyLocalFunction is for and what it does.
Args: MYTYPE MyFunctionArgument1
Description.
MYTYPE MyFunctionArgument1
Description.
Returns: MyReturnType
Description.
-----------------------------------------------------------------F-F*/
エクスポートされた関数定義ヘッダー
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
Function: MyFunction
Summary: What MyFunction is for and what it does.
Args: MYTYPE MyFunctionArgument1
Description.
MYTYPE MyFunctionArgument1
Description.
Returns: MyReturnType
Description.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
COM インターフェイス宣言ヘッダー
/*I+I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I
Interface: IMyInterface
Summary: Short summary of what features the interface can bring to
a COM Component.
Methods: MYTYPE MyMethodOne
Description.
MYTYPE MyMethodTwo
Description.
I---I---I---I---I---I---I---I---I---I---I---I---I---I---I---I---I-I*/
COM オブジェクト クラス宣言ヘッダー
/*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
ObjectClass: COMyCOMObject
Summary: Short summary of purpose and content of this object.
Interfaces: IUnknown
Standard interface providing COM object features.
IMyInterfaceOne
Description.
IMyInterfaceTwo
Description.
Aggregation: [whether this COM Object is aggregatable or not]
O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
これらのコメント ブロック規則はすべて、一貫した開始トークン文字列と終了トークン文字列を持ちます。 この整合性では、何らかの方法でヘッダーの自動処理がサポートされます。 たとえば、AWK スクリプトを記述して、関数ヘッダーを別のテキスト ファイルにフィルター処理し、仕様ドキュメントの基礎として機能させることができます。 同様に、サポートされていない AUTODUCK ユーティリティ (現在は Microsoft Developer Network Development Library CD-ROM で利用可能) などのツールを使用して、これらのヘッダー内のコメント ブロックを処理できます。
次の表に、サンプル チュートリアルで使用される開始トークン文字列と終了トークン文字列を示します。
| トークン | 説明 |
|---|---|
| /*+ | ファイル ヘッダーの開始 |
| +*/ | ファイル ヘッダーの終了 |
| /*- | プレーン コメント ブロック ヘッダーの開始 |
| -*/ | プレーンコメントブロックヘッダーエンド |
| /*C | クラス ヘッダーの開始 |
| C*/ | クラス ヘッダーの終了 |
| /*M | メソッド ヘッダーの開始 |
| M*/ | メソッド ヘッダーの終了 |
| /*F | 関数ヘッダーの開始 |
| F*/ | 関数ヘッダーの終了 |
| /*私 | インターフェイス ヘッダーの開始 |
| 私*/ | インターフェイス ヘッダーの終了 |
| /*O | COM オブジェクト クラス ヘッダーの開始 |
| O*/ | COM オブジェクト クラスヘッダーの終了 |
これらのヘッダーは、ソース ファイルを迅速にスキャンするための視覚的な手掛かりとしても使用できます。 また、エディターで検索文字列を設定し、[最後の検索を繰り返す] を設定してこれらのヘッダーをすばやく見つける場合に、ソースの場所にすばやくアクセスするための利便性も提供されます。
たとえば、検索文字列 "M+M" はメソッド ヘッダーの先頭を見つけ、"M-M" は実際のメソッド定義/実装コードの先頭を見つけます。