|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 BinGu 于 2012-1-12 22:58 编辑
图标.rar
(1.5 KB, 下载次数: 0)
之前好多人问,怎么把变量变成字符串,这个问题确实难住了好多人!因为汇编语言里面没有wprintf这样的函数,确实让人头疼!但是汇编中有另外一个函数也能做到,相必不少人已经知道哪个函数了,不错,就是wsprintf函数!
wsprintf函数的用法:简单的说就是用wsprintf函数把变量格式化之后放入到缓冲区,然后就再冲缓冲区拿出来就是字符串了!明白了吗?嘿嘿~就是这么简单~~~
;代码程序:.386
.model flat, stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
DLG_MAIN equ 1
IDC_CUSTOMTEXT equ 100
ICO_MAIN equ 1000h
.data
szText db "请输入~!", 0
szCaption db "123", 0
szText2 db "wsprintf函数示范", 0
.data?
hInstance dd ?
szBuffer byte 256 dup (?)
.code
_ProcMain proc uses ebx edi esi hWnd, wMsg, wParam, lParam
local @szBuffer[256]: BYTE
mov eax, wMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon, hInstance, ICO_MAIN
invoke SendMessage, hWnd, WM_SETICON, ICON_BIG, eax
.elseif eax == WM_COMMAND
mov eax, wParam
.if ax == IDOK
invoke GetDlgItemText,hWnd,IDC_CUSTOMTEXT,addr @szBuffer,sizeof @szBuffer
.if @szBuffer == 0
invoke SetWindowText, hWnd, addr szText2
invoke MessageBox, hWnd, addr szText, addr szCaption, MB_OK
.else
invoke wsprintf, addr szBuffer, addr @szBuffer
invoke SetWindowText, hWnd, addr szBuffer
.endif
.elseif eax == IDCANCEL
invoke EndDialog, hWnd, NULL
.endif
.else
mov eax, FALSE
ret
.endif
mov eax, TRUE
ret
_ProcMain endp
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, DLG_MAIN, NULL, _ProcMain, NULL
invoke ExitProcess, NULL
end start
;**********************************************************
//资源文件: #include <resource.h>
#define DLG_MAIN 1
#define IDC_CUSTOMTEXT 100
DLG_MAIN DIALOG 193, 180, 310, 134
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "wsprintf函数示范"
FONT 9, "宋体"
{
DEFPUSHBUTTON "Hit Me", IDOK, 58, 46, 50, 14
EDITTEXT IDC_CUSTOMTEXT, 190, 55, 105, 12
}
想~~大家应该都能看明白吧!
注意:看代码的时候,直接点击复制代码,然后粘帖到记事本中再看,那样格式就不乱了!
该贴已经同步到 BinGu的微博
|
|