程序作者:管寧 個人網站:www.cndev-lab.com VC作為一個主流的開發平臺一直深受編程愛好者的喜愛,但是很多人卻對它的入門感到難于上青天,究其原因主要是大家對他錯誤的熟悉造成的,嚴格的來說VC++不是門語言,雖然它和C++之間有密切的關系,假如形象點比喻的話,可以C++看作為一種”工業標準”,而VC++則是某種操作系統平臺下的”廠商標準”,而”廠商標準”是在遵循”工業標準”的前提下擴展而來的。 VC++應用程序的開發主要有兩種模式,一種是WIN API方式,另一種則是MFC方式,傳統的WIN API開發方式比較繁瑣,而MFC則是對WIN API再次封裝,所以MFC相對于WIN API開發更具備效率優勢,但為了對WINDOWS開發有一個較為全面細致的熟悉,筆者在這里還是以講解WIN API的相關內容為主線。 話說到這里可能更多人關心的是學習VC++需要具備什么條件,為什么對于這扇門屢攻不破呢? 要想學習好VC必須具備良好的C/C++的基礎,必要的英語閱讀能力也是必不可少的,因為大量的技術文檔多以英文形式發布。 許多初學VC++的人對于它怪異的寫法和程序奇異的工作方式非常不理解,為了幫助大家對它的入門有一個比較概括的了解,我們把這一小節內容分成若干部分講解。 第一部分:VC++中的對象的命名規則、常用宏定義的命名,以及VC++下的數據類型。 注:這部分簡單瀏覽即可。 第二部分:VC++常用技術術語的解釋。 第三部分:HelloWin程序的具體分析。 更多內容請看C/C++技術學堂 C/C++技術專題 Solaris基礎知識入門專題,或 第一部分匈牙利命名法規則 一般情況下,變量的取名方式為:<scope_> + <PRefix_> + <qualifier>。 范圍前綴_,類型前綴_,限定詞。非凡的類型命名,前綴表示: 類、接口 前綴 類型例子備注LmClass LmObject表示類型本身 不與范圍前綴結合使用IInterface 接口IUnknown 注:類名前綴改為Lm,對于非全局的類最好有語義表示其所屬模塊。類的實例命名與類名大致相同,只是類名語義表示類的通用含義,而類名表示此實例的具體語義。如類名LmSketPoint表示草圖點的類定義,而它的兩個實例 _StartPoint,_EndPoint分別代表起點和終點的語義。類的實例命名帶上前綴_。 非凡約定: a. MouseTool的派生類的前綴為_Mt. b. 對話框類的前綴為CDlg. c. 橡皮條類的前綴為_Rb.凡圍前綴: 前綴類型例子備注g_全局作用域g_Servers m_成員變量m_pDoc, l_局部作用域l_strName少用 注:編程時盡量少用全程變量,對于全程變量還應在類型前綴后加上如下要害字: 特征模塊 : Fea 草圖模塊 : Sket 裝配模塊 : Asm 工程圖模塊: Lay 曲面模塊 : Surf 界面模塊 : Ui 常用的一般數據類型的前綴 前綴類型內存規格描述例子chchar8-bit characterchGradechTCHAR16-bit character if _UNICODE is definedchNamebBOOLBoolean valuebEnablednintInteger (size dependent on Operating system)nLengthnUINTUnsigned value (size dependent on operating system)nLengthwWord16-bit unsigned valuewPoslLONG32-bit signed integerlOffsetdwDWORD32-bit unsigned integerdwRangep*Ambient memory model pointerpDoclpFAR*Far pointerlpDoclpszLPSTR32-bit pointer to character stringlpszNamelpszLPCSTR32-bit pointer to constant character stringlpszNamelpszLPCTSTR32-bit pointer to constant character string if _UNICODE is definedlpszNamehhandleHandle to Windows objecthWndlpfn(*fn)()callbackFar pointer to CALLBACK functionlpfnAbort
常用Windows對象名稱縮寫 Windows 對象例子變量MFC類例子對象HWNDhWnd;CWnd*pWnd;HDLGhDlg;CDialog*pDlg;HDChDC;CDC*pDC;HGDIOBJhGdiObj;CGdiObject*pGdiObj;HPENhPen;CPen*pPen; HBRUSHhBrush;CBrush*pBrush; HFONThFont;CFont*pFont; HBITMAPhBitmap;CBitmap*pBitmap; HPALETTEhPalette;CPalette*pPalette; HRGNhRgn;CRgn*pRgn; HMENUhMenu;CMenu*pMenu; HWNDhCtl;CStatic*pStatic; HWNDhCtl;CButton*pBTn;HWNDhCtl;CEdit*pEdit; HWNDhCtl;CListBox*pListBox;HWNDhCtl;CComboBox*pComboBox; Visual C++常用宏定義命名列表 前綴符號類型符號例子范圍IDR_標識多個資源共享的類型IDR_MAINFRAME1 to 0x6FFFIDD_對話框資源(Dialog)IDD_SPELL_CHECK1 to 0x6FFFIDB_位圖資源(Bitmap)IDB_COMPANY_LOGO1 to 0x6FFFIDC_光標資源(Cursor)IDC_PENCIL1 to 0x6FFFIDI_圖標資源(Icon)IDI_NOTEPAD1 to 0x6FFFID_IDM_工具欄或菜單欄的命令項ID_TOOLS_SPELLING0x8000 to 0xDFFFHID_命令上下文幫助(Command Help context)HID_TOOLS_SPELLING0x18000 to 0x1DFFFIDP_消息框提示文字資源IDP_INVALID_PARTNO8 to 0xDFFFHIDP_消息框上下文幫助(Message-box Help context)HIDP_INVALID_PARTNO0x30008 to 0x3DFFFIDS_字符串資源(String)IDS_COPYRIGHT1 to 0x7FFFIDC_對話框內的控制資源(Control)IDC_RECALC8 to 0xDFFF VISUAL C++ 下的數據類型 類型含義ATOMAtom. For more information, see Atoms.BOOLBoolean variable (should be TRUE or FALSE).BOOLEANBoolean variable (should be TRUE or FALSE).BYTEByte (8 bits).CALLBACKCalling convention for callback functions.CHAR8-bit Windows (ANSI) character. For more information, see Character Sets Used By Fonts.COLORREFRed, green, blue (RGB) color value (32 bits). See COLORREF for information on this type.CONSTVariable whose value is to remain constant during execution.DWORD32-bit unsigned integer.DWORD_PTRUnsigned long type for pointer precision. Use when casting a pointer to a long type to perform pointer arithmetic. (Also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows. )DWORD3232-bit unsigned integer.DWORD6464-bit unsigned integer.FLOATFloating-point variable.HACCELHandle to an accelerator table.HANDLEHandle to an object.HBITMAPHandle to a bitmap. HBRUSHHandle to a brush.HCONVHandle to a dynamic data exchange (DDE) conversation.HCONVLISTHandle to a DDE conversation list.HCURSORHandle to a cursor.HDCHandle to a device context (DC).HDDEDATAHandle to DDE data.HDESKHandle to a desktop.HDROPHandle to an internal drop strUCture.HDWPHandle to a deferred window position structure.HENHMETAFILEHandle to an enhanced metafile.HFILEHandle to a file opened by OpenFile, not CreateFile.HFONTHandle to a font.HGDIOBJHandle to a GDI object.HGLOBALHandle to a global memory block.HHOOKHandle to a hook.HICONHandle to an icon.HIMAGELISTHandle to an image list.HIMCHandle to input context.HINSTANCEHandle to an instance.HKEYHandle to a registry key.HKLInput locale identifier.HLOCALHandle to a local memory block.HMENUHandle to a menu.HMETAFILEHandle to a metafile.HMODULEHandle to a module. The value is the base address of the module.HMONITORHandle to a display monitor.HPALETTEHandle to a palette.HPENHandle to a pen. HRGNHandle to a region.HRSRCHandle to a resource.HSZHandle to a DDE string.HWINSTAHandle to a window station.HWNDHandle to a window.INT32-bit signed integer.INT_PTRSigned integral type for pointer precision. Use when casting a pointer to an integer to perform pointer arithmetic.INT3232-bit signed integer.INT6464-bit signed integer.LANGIDLanguage identifier. For more information, see Locales.LCIDLocale identifier. For more information, see Locales.LCTYPELocale information type. For a list, see Locale and Language Information.LONG32-bit signed integer. LONG_PTRSigned long type for pointer precision. Use when casting a pointer to a long to perform pointer arithmetic.LONG3232-bit signed integer.LONG6464-bit signed integer.LONGLONG64-bit signed integer.LPARAMMessage parameter.LPBOOLPointer to a BOOL. LPBYTEPointer to a BYTE. LPCOLORREFPointer to a COLORREF value.LPCRITICAL_SECTIONPointer to a CRITICAL_SECTION.LPCSTRPointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.LPCTSTRAn LPCWSTR if UNICODE is defined, an LPCTSTR otherwise.LPCVOIDPointer to a constant of any type.LPCWSTRPointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.LPDWORDPointer to a DWORD.LPHANDLEPointer to a HANDLE.LPINTPointer to an INT.LPLONGPointer to a LONG.LPSTRPointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.LPTSTRAn LPWSTR if UNICODE is defined, an LPSTR otherwise.LPVOIDPointer to any type.LPWORDPointer to a WORD.LPWSTRPointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.LRESULTSigned result of message processing.LUIDLocally unique identifier. PBOOLPointer to a BOOL.PBOOLEANPointer to a BOOL.PBYTEPointer to a BYTE.PCHARPointer to a CHAR.PCRITICAL_SECTIONPointer to a CRITICAL_SECTION.PCSTRPointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.PCTSTRA PCWSTR if UNICODE is defined, a PCSTR otherwise.PCWCHPointer to a constant WCHAR.PCWSTRPointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts. PDWORDPointer to a DWORD.PFLOATPointer to a FLOAT.PHANDLEPointer to a HANDLE.PHKEYPointer to an HKEY.PINTPointer to an INT. PLCIDPointer to an LCID.PLONGPointer to a LONG.PLUIDPointer to a LUID. POINTER_3232-bit pointer. On a 32-bit system, this is a native pointer. On a 64-bit system, this is a truncated 64-bit pointer. POINTER_6464-bit pointer. On a 64-bit system, this is a native pointer. On a 32-bit system, this is a sign-extended 32-bit pointer.PSHORTPointer to a SHORT.PSTRPointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.PTBYTEPointer to a TBYTE.PTCHARPointer to a TCHAR.PTSTRPWSTR if UNICODE is defined, a PSTR otherwise.PTBYTEPointer to a TBYTE.PTCHARPointer to a TCHAR.PTSTRA PWSTR if UNICODE is defined, a PSTR otherwise.PUCHARPointer to a UCHAR.PUINTPointer to a UINT.PULONGPointer to a ULONG.PUSHORTPointer to a USHORT.PVOIDPointer to any type.PWCHARPointer to a WCHAR.PWORDPointer to a WORD.PWSTRPointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.REGSAMSecurity access mask for registry key.SC_HANDLEHandle to a service control manager database. For more information, see SCM Handles.SC_LOCKHandle to a service control manager database lock. For more information, see SCM Handles.SERVICE_STATUS_HANDLEHandle to a service status value. For more information, see SCM Handles.SHORTShort integer (16 bits).SIZE_TThe maximum number of bytes to which a pointer can point. Use for a count that must span the full range of a pointer.SSIZE_ TSigned SIZE_T.TBYTEA WCHAR if UNICODE is defined, a CHAR otherwise.TCHARA WCHAR if UNICODE is defined, a CHAR otherwise.UCHARUnsigned CHAR.UINTUnsigned INT.UINT_PTRUnsigned INT_PTR.UINT32Unsigned INT32.UINT64Unsigned INT64.ULONGUnsigned LONG.ULONG_PTRUnsigned LONG_PTR.ULONG32Unsigned LONG32.ULONG64Unsigned LONG64.ULONGLONG64-bit unsigned integer.UNSIGNEDUnsigned attribute.USHORTUnsigned SHORT.VOIDAny type.WCHAR16-bit Unicode character. For more information, see Character Sets Used By Fonts.WINAPICalling convention for system functions.WORD16-bit unsigned integer.WPARAMMessage parameter. 更多內容請看C/C++技術學堂 C/C++技術專題 Solaris基礎知識入門專題,或