简单的CD控制程序,只支持单光驱
;----------------;编译模式="DLG"
;----------------
.386
.Model Flat, StdCall
Option Casemap :None
;;-------------------------------------------------------
Include windows.inc
Include user32.inc
Include kernel32.inc
include shell32.inc
include winmm.inc
includelib winmm.lib
includelib shell32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
;-------------------------------------------------------
;过程声明
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
;-------------------------------------------------------
.const
;常数定义,只使用一次的ID无需定义为常数,这里仅做为例子
DLG_MAIN equ 101
IDI_TRAY equ 0
IDR_POPMNU equ 102
IDM_OPEN equ 40001
IDM_CLOSE equ 40002
IDM_EXIT equ 40003
szTipText db 'CD Door',0
szOpen db 'set CDAudio door open',0
szClose db 'set CDAudio door closed',0
.data;数据段
myicon NOTIFYICONDATA <>
.data?
hInstance dd ?
hIconA dd ?
hMenu dd ?
;-------------------------------------------------------
.CODE
START:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,0,offset DlgProc,0
invoke ExitProcess,0
;当参数类型为DWORD时,不需要进行类型声明,以下过程详细应该为:
;DlgProc proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
DlgProc proc hWnd,uMsg,wParam,lParam
local @pt:POINT
.if uMsg==WM_INITDIALOG
invoke LoadIcon,hInstance,103
mov hIconA,eax
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke LoadMenu,hInstance,IDR_POPMNU
;mov hMenuExit,eax
invoke GetSubMenu,eax,0
mov hMenu,eax
.elseif uMsg==WM_COMMAND
mov eax,wParam
.if ax==IDCANCEL
invoke EndDialog,hWnd,TRUE
.elseif ax == IDOK
;mov IsTray,TRUE
mov myicon.cbSize,sizeof NOTIFYICONDATA ;需填入NOTIFYICONDATA数据结构的长度
push hWnd
pop myicon.hwnd
mov myicon.uFlags,NIF_ICON+NIF_MESSAGE+NIF_TIP ;设置uCallbackMessage,hIcon,szTip是否有效
mov myicon.uID,IDI_TRAY ;为图标所设置的ID值
push hIconA
pop myicon.hIcon ;显示在状态栏上的图标
mov myicon.uCallbackMessage,WM_USER + 1 ;消息编号
invoke lstrcpy,addr myicon.szTip,addr szTipText ;提示信息
invoke Shell_NotifyIcon,NIM_ADD,addr myicon
invoke ShowWindow,hWnd,SW_HIDE
.elseif ax == IDM_EXIT
invoke EndDialog,hWnd,TRUE
invoke Shell_NotifyIcon,NIM_DELETE,addr myicon
.elseif ax == IDM_OPEN
invoke mciSendStringA,offset szOpen,0,0,0
.elseif ax == IDM_CLOSE
invoke mciSendStringA,offset szClose,0,0,0
.endif
.elseif uMsg==WM_CLOSE
invoke EndDialog,hWnd,FALSE
.elseif uMsg == WM_USER + 1
.if wParam == IDI_TRAY
;.if lParam == WM_LBUTTONDOWN
;invoke SendMessage,hWnd,WM_SYSCOMMAND,SC_RESTORE,NULL
.if lParam == WM_RBUTTONDOWN
invoke GetCursorPos,addr @pt
invoke SetForegroundWindow,hWnd
invoke TrackPopupMenu,hMenu,TPM_RIGHTBUTTON,@pt.x,@pt.y,NULL,hWnd,NULL
invoke PostMessage,hWnd,WM_NULL,0,0
.endif
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
END START
老兄,你这是展示汇编的强大还是展示汇编的繁琐?
打开/关闭光驱只要调用mciSendString API函数就可以了,任何语言都比汇编简单
打开 mciSendString("set CDAudio door open",0,0, 0)
关闭 mciSendString("set CDAudio door closed", 0,0, 0)
可是汇编做出来的最小^_^
我编译出来都不到4k,FAT32的一个蔟也不到
页:
[1]