2.wcslen 和strlen用法相當
3.#ifdef UNICODE
typedef WCHAR TCHAR, * PTCHAR ;
typedef LPWSTR LPTCH, PTCH, PTSTR, LPTSTR ;
typedef LPCWSTR LPCTSTR ;
#else
typedef char TCHAR, * PTCHAR ;
typedef LPSTR LPTCH, PTCH, PTSTR, LPTSTR ;
typedef LPCSTR LPCTSTR ;
#endif
4.Windows函數(shù)呼叫
int WINAPI MessageBox (HWND, LPCSTR, LPCSTR, UINT) ;
注意,函數(shù)的第二個、第三個參數(shù)是指向常數(shù)字符串的指針
5.Windows的字符串函數(shù)
ILength = lstrlen (pString) ;
pString = lstrcpy (pString1, pString2) ;
pString = lstrcpyn (pString1, pString2, iCount) ;
pString = lstrcat (pString1, pString2) ;
iComp = lstrcmp (pString1, pString2) ;
iComp = lstrcmpi (pString1, pString2) ;
6.在Windows中使用printf
char szBuffer [100] ;
sprintf (szBuffer, "The sum of %i and %i is %i", 5, 3, 5+3) ;
puts (szBuffer)
ASCII |
寬字符 |
常規(guī) |
|
參數(shù)的變數(shù)個數(shù) |
|||
標準版 |
sprintf |
swprintf |
_stprintf |
最大長度版 |
_snprintf |
_snwprintf |
_sntprintf |
Windows版 |
wsprintfA |
wsprintfW |
wsprintf |
參數(shù)數(shù)組的指針 |
|||
標準版 |
vsprintf |
vswprintf |
_vstprintf |
最大長度版 |
_vsnprintf |
_vsnwprintf |
_vsntprintf |
Windows版 |
wvsprintfA |
wvsprintfW |
wvsprintf |
格式化消息框
程序2-1 SCRNSIZE
SCRNSIZE.C
/*---------------------------------------------------------------------------
SCRNSIZE.C -- Displays screen size in a message box
(c) Charles Petzold, 1998
----------------------------------------------------------------------------*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ;
// The last argument to wvsprintf points to the arguments
_vsntprintf ( szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;
// The va_end macro just zeroes out pArgList for no good reason
va_end (pArgList) ;
return MessageBox (NULL, szBuffer, szCaption, 0) ;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int cxScreen, cyScreen ;
cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
MessageBoxPrintf ( TEXT ("ScrnSize"),
TEXT ("The screen is %i pixels wide by %i pixels high."),
cxScreen, cyScreen) ;
return 0 ;
}
posted @ 2007-10-17 20:59 link 閱讀(307) | 評論 (0) | 編輯 收藏