wsprintf????????

969209pxb 2002-09-05 11:38:50
详细解释它的用法,谢谢!!!
...全文
54 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
javanew 2002-09-06
  • 打赏
  • 举报
回复
针对unicode的sprintf
icansaymyabc 2002-09-06
  • 打赏
  • 举报
回复
和sprintf的用法一样。
cwwa 2002-09-06
  • 打赏
  • 举报
回复
2楼的E文看的眼花,晕.
没仔细看:(
================================================================
In355Hz 2002-09-06
  • 打赏
  • 举报
回复
就是sprintf的Unicode版本,有一个小变动就是
%s 输出Unicode字符串
%S 输出ANSI字符串
和sprintf正相反
969209pxb 2002-09-06
  • 打赏
  • 举报
回复
to imhua(华弟)
这个我看过,还不够完整!
冰壶2013 2002-09-06
  • 打赏
  • 举报
回复
The wsprintf function formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count.

int wsprintf(

LPTSTR lpOut, // pointer to buffer for output
LPCTSTR lpFmt, // pointer to format-control string
... // optional arguments
);


Parameters

lpOut

Points to a buffer to receive the formatted output.

lpFmt

Points to a null-terminated string that contains the format-control specifications. In addition to ordinary ASCII characters, a format specification for each argument appears in this string. For more information about the format specification, see the Remarks section.

...

Specifies one or more optional arguments. The number and type of argument parameters depend on the corresponding format-control specifications in the lpFmt parameter.



Return Values

If the function succeeds, the return value is the number of characters stored in the output buffer, not counting the terminating null character.
If the function fails, the return value is less than the length of the format-control string. To get extended error information, call GetLastError.

Remarks

The format-control string contains format specifications that determine the output format for the arguments following the lpFmt parameter. Format specifications, discussed below, always begin with a percent sign (%). If a percent sign is followed by a character that has no meaning as a format field, the character is not formatted (for example, %% produces a single percent-sign character).
The format-control string is read from left to right. When the first format specification (if any) is encountered, it causes the value of the first argument after the format-control string to be converted and copied to the output buffer according to the format specification. The second format specification causes the second argument to be converted and copied, and so on. If there are more arguments than format specifications, the extra arguments are ignored. If there are not enough arguments for all of the format specifications, the results are undefined.

A format specification has the following form:
%[-][#][0][width][.precision]type
Each field is a single character or a number signifying a particular format option. The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields control other aspects of the formatting. Following are the optional and required fields and their meanings:

Field Meaning
- Pad the output with blanks or zeros to the right to fill the field width, justifying output to the left. If this field is omitted, the output is padded to the left, justifying it to the right.
# Prefix hexadecimal values with 0x (lowercase) or 0X (uppercase).
0 Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces.
width Copy the specified minimum number of characters to the output buffer. The width field is a nonnegative integer. The width specification never causes a value to be truncated; if the number of characters in the output value is greater than the specified width, or if the width field is not present, all characters of the value are printed, subject to the precision specification.
.precision For numbers, copy the specified minimum number of digits to the output buffer. If the number of digits in the argument is less than the specified precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds the specified precision. If the specified precision is 0 or omitted entirely, or if the period (.) appears without a number following it, the precision is set to 1.
For strings, copy the specified maximum number of characters to the output buffer.
type Output the corresponding argument as a character, a string, or a number. This field can be any of the following character sequences:


Sequence Insert
c A single character. The wsprintf function ignores character arguments with a numeric value of zero. This sequence is interpreted as type WCHAR when the calling application uses the #define UNICODE compile flag and as type CHAR otherwise.
C A single character. This sequence is interpreted as type CHAR when the calling application uses the #define UNICODE compile flag and as type WCHAR otherwise.
d A signed decimal integer argument. This sequence is equivalent to the i sequence.
hc, hC A single character. The wsprintf function ignores character arguments with a numeric value of zero. This sequence is always interpreted as type CHAR, even when the calling application uses the #define UNICODE compile flag.
hs, hS A string. This sequence is always interpreted as type LPSTR, even when the calling application uses the #define UNICODE compile flag.
i A signed decimal integer. This sequence is equivalent to the d sequence.
lc, lC A single character. The wsprintf function ignores character arguments with a numeric value of zero. This sequence is always interpreted as type WCHAR, even when the calling application does not use the #define UNICODE compile flag.
ld A long signed decimal integer. This sequence is equivalent to the li sequence.
li A long signed decimal integer. This sequence is equivalent to the ld sequence.
ls, lS A string. This sequence is always interpreted as type LPWSTR, even when the calling application does not use the #define UNICODE compile flag. This sequence is equivalent to the ws sequence.
lu A long unsigned integer.
lx, lX A long unsigned hexadecimal integer in lowercase or uppercase.
s A string. This sequence is interpreted as type LPWSTR when the calling application uses the #define UNICODE compile flag and as type LPSTR otherwise.
S A string. This sequence is interpreted as type LPSTR when the calling application uses the #define UNICODE compile flag and as type LPWSTR otherwise.
u An unsigned integer argument.
x, X An unsigned hexadecimal integer in lowercase or uppercase.


Note Unlike other Windows functions, wsprintf uses the C calling convention (_cdecl), rather than the Pascal calling convention. As a result, it is the responsibility of the calling process to pop arguments off the stack, and arguments are pushed on the stack from right to left. In C-language modules, the C compiler performs this task.



See Also

wvsprintf
对日常债务进行数据库操作 .586 .model flat,stdcall option casemap:none include pay.inc include p_Func.asm include p_const.asm include p_struct.asm include p_data.asm include macro.mac .data hInstance HINSTANCE ? CommandLine LPSTR ? hParent dword ? hCursor dword ? hconn_g dword ? henv_g dword ? hstmt_g dword ? dwCount_g dword ? bFlag_g dword ? pPayForData_g PAYFORDATA <> pConfigData CONFIGDATA <> .code include p_code.asm include p_db.asm include p_Dialog.asm include p_ListView.asm include P_ini.asm include p_html.asm ; --------------------------------------------------------------------------- start: invoke GetModuleHandle, NULL mov hInstance,eax invoke DialogBoxParam,hInstance,addr LoginDlgName,0,addr LoginDialog,NULL .if bFlag_g invoke GetCommandLine mov CommandLine,eax invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT .endif invoke ExitProcess,eax WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND LOCAL hMenu:HWND LOCAL hAccelerator:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszMenuName,offset MenuName mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_MAIN_ICON mov wc.hIcon,eax mov wc.hIconSm,eax mov hMainIco,eax invoke LoadMenu,hInstance,IDR_MENU mov hMenu,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke LoadCursor,hInstance,IDI_HANDLE_ICON mov hCursor,eax invoke LoadAccelerators,hInstance,IDA_ACCELERATOR mov hAccelerator,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\ hInst,NULL mov hwnd,eax mov hParent,eax invoke ShowWindow, hwnd,SW_SHOWNORMAL invoke UpdateWindow, hwnd .WHILE TRUE invoke GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) invoke TranslateAccelerator,hwnd,hAccelerator,addr msg .if eax == 0 invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg .endif .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc uses ebx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM local @stFont:LOGFONT,@hFont:DWORD LOCAL @dwColor:dword .IF uMsg==WM_DESTROY invoke KillTimer,hWnd,IDC_TIMER_STATUSBAR invoke PostQuitMessage,NULL .elseif uMsg==WM_TIMER .if wParam==IDC_TIMER_STATUSBAR invoke _PrintMsg_3 .endif .ELSEIF uMsg==WM_CREATE invoke SetTimer,hWnd,IDC_TIMER_STATUSBAR ,1000,NULL invoke LoadIcon,hInstance,IDI_MAIN_ICON invoke SendMessage, hWnd, WM_SETICON, ICON_BIG,eax ;control invoke _DoToolBar,hInstance,hWnd,IDC_MAIN_TB mov hToolBar,eax ;invoke _DoEdit,hInstance,hToolBar,IDC_MAIN_EDIT ;mov hEdit,eax ;invoke _DoButton,hInstance,hToolBar,IDC_MAIN_BUTTON,_T("搜索") ;mov hButton,eax ;LABEL invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_3,200,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_3,_T("当前用户:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_NAME,270,3,150,20 invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_1,340,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_1,_T("借入:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_IN,380,3,150,20 invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_2,480,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_2,_T("借出:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_OUT,520,3,150,20 invoke _DoStatusBar,hInstance,hWnd,IDC_MAIN_SB mov hStatusBar,eax invoke _DoListView,hInstance,hWnd,IDC_MAIN_LSV mov hListView ,eax invoke _InsertColumnToMainListV,hListView invoke _DoPopupMainMenu, hInstance,hWnd mov hPopupMainMenu,eax invoke _InitConfig,hWnd .elseif uMsg==WM_NOTIFY push edi mov edi, lParam mov eax, [edi.NMHDR].hwndFrom .if eax==hListView .if [edi.NMHDR].code==NM_DBLCLK ;双击 .elseif [edi.NMHDR].code==NM_CLICK ;单击 invoke _GetCurrentFocus,hListView,addr pPayForData_g .elseif [edi.NMHDR].code==NM_RCLICK ;右击 invoke _GetCurrentFocus,hListView,addr pPayForData_g invoke _ShowPopupMainMenu,hWnd,hPopupMainMenu .endif .endif pop edi .elseif uMsg==WM_COMMAND .if lParam !=0 ;工具栏 LOWORD wParam .if eax==IDC_TBB_NEW invoke DialogBoxParam,hInstance,addr NewDlgName,hWnd,addr IddNewDialog,NULL .elseif eax==IDC_TBB_SEE invoke DialogBoxParam,hInstance,addr SeeDlgName,hWnd,addr SeeDialog,NULL .elseif eax==IDC_TBB_PRINT invoke _Print_Html,hWnd .elseif eax==IDC_TBB_HELP invoke DialogBoxParam,hInstance,addr AboutDlgName,hWnd,addr AboutDialog,NULL .elseif eax==IDC_TBB_EXIT invoke SendMessage,hWnd,WM_CLOSE,0,0 .endif .elseif lParam ==0 HIWORD wParam .if eax==0 ;菜单栏 mov eax,wParam .if ax==IDM_NEW invoke DialogBoxParam,hInstance,addr NewDlgName,hWnd,addr IddNewDialog,NULL invoke _RefreshMTData,hWnd,hListView .elseif ax==IDM_SEE invoke DialogBoxParam,hInstance,addr SeeDlgName,hWnd,addr SeeDialog,NULL .elseif ax==IDM_PRINT invoke _Print_Html,hWnd .elseif ax==IDM_CALC invoke _OpenProgramExeFile,hWnd,addr SZCALC,NULL .elseif ax==IDM_HELP invoke DialogBoxParam,hInstance,addr AboutDlgName,hWnd,addr AboutDialog,NULL .elseif ax==IDM_PWD invoke DialogBoxParam,hInstance,addr PwdDlgName,hWnd,addr PwdDialog,NULL .elseif ax==IDM_REFRESH invoke _RefreshMTData,hWnd,hListView .elseif ax==IDM_DEMO invoke DialogBoxParam,hInstance,addr DemoDlgName,hWnd,addr DemoDialog,NULL .elseif ax==IDM_CAL invoke _PromptMsg,_T("建设中...") .endif .elseif eax==1 ;快捷键 .endif .endif .elseif uMsg ==WM_SIZE .if wParam!=SIZE_MINIMIZED invoke SendMessage,hStatusBar,uMsg,wParam,lParam invoke SendMessage,hToolBar,uMsg,wParam,lParam mov eax,lParam mov edx,eax and eax,0ffffh shr edx,16 sub edx,46 invoke MoveWindow,hListView, 0, 28, eax,edx,TRUE mov eax,lParam and eax,0ffffh mov ebx,eax sub eax,210 sub ebx,55 invoke MoveWindow,hEdit, eax, 3,150,20,TRUE invoke MoveWindow,hButton,ebx, 3,50,20,TRUE .endif .elseif uMsg==WM_SIZING LimitWindowWidth 455 LimitWindowHeight 455 .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp _RefreshMTData proc hWnd:dword,hOwner:dword pushad ;连接数据库 invoke DBConnect,hWnd .if eax invoke _PrintMsg_1,_T("数据库连接成功!") .endif ;显示数据 invoke SQLExecDirect,hstmt_g,addr SHOW_ALL_RECODE_MT,sizeof SHOW_ALL_RECODE_MT .if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO ;73570000h invoke _ReadMTToMainListV,hOwner,hstmt_g mov dwCount_g,eax invoke _PrintMsg_2,dwCount_g,_T(" ") invoke _PrintMsg_1,_T("加载成功!") .endif invoke DisDBConnect,hWnd .if eax invoke _PrintMsg_1,_T("断开与数据库的连接!") .endif popad ret _RefreshMTData endp _RefreshOPData proc hWnd:dword,hOwner:dword LOCAL @nCount:dword pushad ;连接数据库 invoke DBConnect,hWnd .if eax invoke _PrintMsg_1,_T("数据库连接成功!") .endif ;显示数据 invoke SQLExecDirect,hstmt_g,addr SHOW_ALL_RECODE_OP,sizeof SHOW_ALL_RECODE_OP .if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO ;73570000h invoke _ReadOPToSeeListV,hOwner,hstmt_g mov @nCount,eax invoke _SetGroupText,hWnd,@nCount invoke _PrintMsg_1,_T("加载成功!") .endif invoke DisDBConnect,hWnd .if eax invoke _PrintMsg_1,_T("断开与数据库的连接!") .endif popad ret _RefreshOPData endp _InitConfig proc hWnd:dword LOCAL @Buff[MAX_PATH]:byte pushad invoke _RefreshMTData,hWnd,hListView invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_NAME,addr pConfigData.szName invoke _CalcMTPayForRecord,hWnd,addr pConfigData.szName,FALSE mov dwMoneyIn,eax invoke wsprintf,addr @Buff,addr szMoney,dwMoneyIn invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_IN,addr @Buff invoke _CalcMTPayForRecord,hWnd,addr pConfigData.szName,TRUE mov dwMoneyOut,eax invoke wsprintf,addr @Buff,addr szMoney,dwMoneyOut invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_OUT,addr @Buff ;TITLE invoke RtlZeroMemory,addr @Buff,sizeof @Buff invoke lstrcpy,addr @Buff,addr pConfigData.szAppName invoke lstrcat,addr @Buff,_T(" -- ") invoke lstrcat,addr @Buff,addr pConfigData.szName invoke SendMessage,hWnd,WM_SETTEXT,0,addr @Buff popad ret _InitConfig endp end start

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧