- UID
- 17680
注册时间2006-7-8
阅读权限10
最后登录1970-1-1
周游历练
该用户从未签到
|
[程序名称]生肖查询器
[程序作者]张科
[程序说明]一个查询生肖的工具,输入一个年份后点查询就可以得到生肖,如1989(我出生那年,呵呵!)
[附加说明]本来开始是想把这个DD发布到看雪论坛的,但是觉得那牛太多了,可能没什么用
这里新手比较多,所以就发到这来,大家一起学习一下
[开发日期]2006-7-8
[最早发布地点]飘云阁
[注意~!!!!]本程序绝对原创,转载请务必注明转载自飘云阁
[程序代码]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 生肖查询器 ;
; ;
; 作者:张科 ;
; 2006-7-8 ;
; QQ:25282740 ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.486
.model flat, stdcall
option casemap :none
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
GetYear proto :DWORD
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\msvcrt.lib
.data?
hInstance HINSTANCE ?
swidth dd ?
sheight dd ?
dwidth dd ?
dheight dd ?
rect RECT <>
yearname db ?
.data
year0 db "猴年",0
year1 db "鸡年",0
year2 db "狗年",0
year3 db "猪年",0
year4 db "鼠年",0
year5 db "牛年",0
year6 db "虎年",0
year7 db "兔年",0
year8 db "龙年",0
year9 db "蛇年",0
year10 db "马年",0
year11 db "羊年",0
yearmsg db "年是",0
mytitle db "查询结果",0
MyDialog db "IDD_MYDIALOG",0
ErrorText db "Program already run...",0
ErrorTitle db "Warning!!!",0
szMutex db "zhangkesyear",0
appname db "生肖查询器",0
description db "查询生肖的程序,输入年份就可,比如1989",0
copyright db "作者:张科",13,10,"使用汇编语言编写于2006年7月8日",13,10,"Assembly is great.",0
.const
EDITIN equ 1000
BTNASK equ 1001
MAINICON equ 1002
.code
start:
;mainpart
invoke GetModuleHandle,NULL
mov eax,hInstance
invoke DialogBoxParam,hInstance,addr MyDialog,NULL,addr DlgProc,NULL
invoke ExitProcess,NULL
;mainpart
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hIcon:HICON
.IF uMsg==WM_INITDIALOG
invoke CreateMutex,NULL,FALSE,addr szMutex
invoke GetLastError
.IF eax == ERROR_ALREADY_EXISTS
invoke MessageBox,NULL,addr ErrorText,addr ErrorTitle,MB_ICONWARNING
invoke ExitProcess,NULL
.ENDIF
;上面几行代码的作用的防止程序多开(即只能运行一个实例)
invoke GetSystemMetrics,SM_CXSCREEN ;
mov swidth,eax ;
invoke GetSystemMetrics,SM_CYSCREEN ;
mov sheight,eax ;
invoke GetWindowRect,hWnd,addr rect ;
mov eax,rect.right ;这几行是为下面invoke SetWindowPos做准备
sub eax,rect.left ;
mov dwidth,eax ;
sub swidth,eax ;使窗体出现在屏幕中心
mov eax,rect.bottom ;
sub eax,rect.top ;
mov dheight,eax ;其中不明白的地方看一下Platform SDK就可以了
sub sheight,eax ;
shr sheight,1 ;
shr swidth,1 ;
invoke SetWindowPos,hWnd,HWND_NOTOPMOST,swidth,sheight,dwidth,dheight,SWP_SHOWWINDOW
invoke LoadIcon,hInstance,MAINICON
mov hIcon,eax
invoke AboutBox,hWnd,hInstance,hIcon,addr appname,addr description,addr copyright
;AboutBox是Masm32库中的
.ELSEIF uMsg==WM_CLOSE
invoke ExitProcess,NULL
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax == BTNASK
invoke GetDlgItemText,hWnd,EDITIN,addr yearname,6 ;最长为6,意思是最多能查询到999999年
invoke atodw,addr yearname ;
invoke GetYear,eax ;为了简单一点,这段代码没有输入验证
push eax ;
invoke szCatStr,addr yearname,addr yearmsg
pop eax
invoke szCatStr,addr yearname,eax
invoke MessageBox,hWnd,addr yearname,addr mytitle,MB_ICONINFORMATION
.ENDIF
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
DlgProc endp
;关于如何获得生肖这个算法,在我遥远的小学时代就会了
;当时记得是一个哥哥,懂什么八卦、奇门盾甲等等,他就说告诉他一个年份
;他就能算出是什么年(就是指算出那年的生肖),我不相信,就找了几个试他
;结果他几个都说对了,我就要他教我,于是他就教我了,我在高一学习Pascal
;(我学习的第一种语言)的时候,编写的第一个程序也是这个,就是输入一个年份
;输出生肖.......现在马上就上高三了,以后玩电脑的时间不长了,幸好这段
;时间又学习了汇编语言,觉得太好了,特别是编译出来的程序特别小
;(这个算法)就是把 年份/12 然后根据余数来判断
GetYear proc year:DWORD
mov eax,year
here:
cmp eax,12
jb exit
sub eax,12
jmp here
exit:
.IF eax == 0
lea eax,year0
.ELSEIF eax == 1
lea eax,year1
.ELSEIF eax == 2
lea eax,year2
.ELSEIF eax == 3
lea eax,year3
.ELSEIF eax == 5
lea eax,year5
.ELSEIF eax == 6
lea eax,year6
.ELSEIF eax == 7
lea eax,year7
.ELSEIF eax == 8
lea eax,year8
.ELSEIF eax == 9
lea eax,year9
.ELSEIF eax == 10
lea eax,year10
.ELSEIF eax == 11
lea eax,year11
.ENDIF
ret
GetYear endp
end start
前面那些包含文件没去,是QEditor生成模版的时候自动加上的,有的可以去掉
[资源文件]
#include "\masm32\include\resource.h"
#define EDITIN 1000
#define BTNASK 1001
#define IDI_MAINICON 1002
IDI_MAINICON ICON "China.ico"
IDD_MYDIALOG DIALOGEX 0, 0, 174, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "生肖查询器"
FONT 10, "System"
BEGIN
EDITTEXT EDITIN,58,28,80,12,ES_AUTOHSCROLL
PUSHBUTTON "查询",BTNASK,74,48,45,17,0,WS_EX_STATICEDGE
LTEXT "输入年份:",IDC_STATIC,18,30,38,9
END
程序编译出来只有10kb,真是小啊!喜欢汇编就是这点 |
-
-
year.rar
5.78 KB, 下载次数: 23, 下载积分: 飘云币 -2 枚
下载代码及程序
|