www.pudn.com > gate.rar > CoCoPlayer.asm


.386 
.Model Flat, StdCall 
Option Casemap :None   ; 不区分大小写(对API与API常数无效) 
;___________________________________________________________________________ 
include head.asm 
;___________________________________________________________________________ 
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD 
	LOCAL wc:WNDCLASSEX 
	LOCAL msg:MSG 
	local TempNum,TempNum1 
	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,DLGWINDOWEXTRA 
	push  hInst 
	pop   wc.hInstance 
	push hBackBrush2 
	pop   wc.hbrBackground 
	mov   wc.lpszClassName,OFFSET szClassName 
	invoke LoadIcon,NULL,IDI_APPLICATION 
	mov   wc.hIcon,eax 
	mov   wc.hIconSm,eax 
	invoke LoadCursor,NULL,IDC_ARROW 
	mov   wc.hCursor,eax 
	invoke RegisterClassEx, addr wc 
	invoke CreateDialogParam,hInstance,100,NULL,NULL,NULL 
	mov   hWnd,eax 
	include SubClassControls.asm 
	include ReadSetting.asm 
	invoke GetPrivateProfileInt,offset Config,offset CreateHotKey,0,offset INIPath 
	cmp eax,0 
	jz @ALLREG 
	invoke RegisterHotKey,hWnd,10,0,VK_F9 
	cmp eax,0 
	jz @F 
	invoke RegisterHotKey,hWnd,11,0,VK_F10 
	cmp eax,0 
	jz @F 
	invoke RegisterHotKey,hWnd,13,0,VK_F11 
	cmp eax,0 
	jz @F 
	invoke RegisterHotKey,hWnd,14,0,VK_F12 
	cmp eax,0 
	jz @F 
	jmp @ALLREG 
	@@: 
		invoke LoadString,hInstance,48,offset TempBuffer,sizeof TempBuffer 
		invoke SetDlgItemText,hWnd,1001,offset TempBuffer 
	@ALLREG: 
	INVOKE ShowWindow, hWnd,SW_SHOWNORMAL 
	INVOKE UpdateWindow, hWnd 
;=============================================== 
;加载加速键 
invoke LoadAccelerators,hInstance,100 
mov hAcc,eax 
;消息循环 
StartLoop: 
	invoke GetMessage,ADDR msg,NULL,0,0 
		cmp eax, 0 
		je ExitLoop 
		cmp RecordMode,TRUE 
		jz @F 
			invoke TranslateAccelerator,hWnd,hAcc,addr msg 
			cmp eax,0 
			jne StartLoop 
		@@: 
			invoke IsDialogMessage, hWnd, ADDR msg  
			.if eax==0 
				invoke TranslateMessage, ADDR msg 
				invoke DispatchMessage,  ADDR msg 
			.endif 
		jmp StartLoop 
ExitLoop: 
	mov     eax,msg.wParam 
	invoke UnregisterHotKey,hWnd,10 
	invoke UnregisterHotKey,hWnd,11 
	invoke UnregisterHotKey,hWnd,13 
	invoke UnregisterHotKey,hWnd,14 
	ret 
WinMain endp 
;----------------------------------------------------------------------- 
WndProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM 
local TempNum,Index,Num,mDC,hdc,CurNum,AllNum,TimeNum 
local ps:POINT 
local rect:RECT 
local TempBuff[200]:BYTE 
	.if uMsg==WM_CREATE 
		;分割窗口 
		invoke CreateRoundRectRgn,0,0,288,267,10,10 
		invoke SetWindowRgn,hWin,eax,TRUE 
		invoke LoadIcon,hInstance,100 
		invoke SendMessage,hWin,WM_SETICON,ICON_SMALL,eax 
		invoke wsprintf,offset TimeBuffer,offset TimeShow,offset ZeroStr,0,offset ZeroStr,0 
		;增加系统栏图标 
		mov inf.cbSize,SIZEOF NOTIFYICONDATA 
		push hWin 
		pop inf.hwnd 
		mov inf.uID,100 
		mov inf.uFlags,NIF_MESSAGE or NIF_ICON or NIF_TIP 
		mov inf.uCallbackMessage,WM_USER + 5 
		invoke LoadIcon,hInstance,100 
		mov inf.hIcon,eax 
		INVOKE Shell_NotifyIcon,NIM_ADD,ADDR inf 
		;加载右键菜单 
		invoke LoadMenu,hInstance,100 
		mov Menu,eax 
		push eax 
		invoke GetSubMenu,eax,0 
		mov hMenu,eax 
		pop eax 
		invoke GetSubMenu,eax,1 
		mov hMenu1,eax 
		invoke LoadString,hInstance,11,offset CurrPlayFileName,sizeof CurrPlayFileName 
	;=========================================================================================================== 
	;初始化打开文件对话框的数据 
	  	mov ofn.lStructSize,sizeof OPENFILENAME 
		push hWin 
		pop ofn.hwndOwner 
		push hInstance 
		pop ofn.hInstance 
		mov ofn.Flags,OFN_EXPLORER or OFN_HIDEREADONLY or OFN_ALLOWMULTISELECT or OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES 
 
.elseif uMsg==WM_COMMAND 
	include command.asm 
.elseif uMsg==WM_DROPFILES ;接受拖动文件 
			invoke DragQueryFile,wParam,-1,0,0 
			mov TempNum,eax 
			mov Index,0 
			@@: 
				invoke DragQueryFile,wParam,Index,offset Buffer,sizeof Buffer 
				invoke GetFileAttributes,offset Buffer 
				cmp eax,FILE_ATTRIBUTE_DIRECTORY 
				jz @N 
					invoke GetFileTitle,offset Buffer,offset Buffer1,MAX_PATH 
					invoke SendMessage,hList1,LB_GETCOUNT,0,0 
					invoke wsprintf,offset TempBuffer,offset tempstr,eax,offset Buffer1 
					invoke SendMessage,hList,LB_ADDSTRING,0,offset TempBuffer 
					invoke GetShortPathName,offset Buffer,offset Buffer1,sizeof Buffer1 
					invoke SendMessage,hList1,LB_ADDSTRING,0,offset Buffer1 
				@N: 
				inc Index 
				mov eax,Index 
				cmp eax,TempNum 
				jl @B  
			invoke DragFinish,wParam 
			invoke SendMessage,hList1,LB_GETCOUNT,0,0 
			sub eax,1 
			invoke SendMessage,hScroll,TBM_SETRANGEMAX,TRUE,eax 
;是热键信息 
.elseif uMsg==WM_HOTKEY 
	invoke SendDlgItemMessage,hWnd,wParam,WM_LBUTTONUP,0,0 
;是系统栏图标的消息 
.elseif uMsg==WM_USER + 5 
            .IF lParam==WM_LBUTTONUP 
						INVOKE ShowWindow,hWin,TRUE 
						invoke SetForegroundWindow,hWin 
				.elseif lParam==WM_RBUTTONUP 
						invoke GetCursorPos,addr ps 
						invoke SendMessage,hList,LB_GETCOUNT,0,0 
						.if (eax==0) 
							invoke EnableMenuItem,hMenu,104,MF_BYCOMMAND or MF_GRAYED  
							invoke EnableMenuItem,hMenu,105,MF_BYCOMMAND or MF_GRAYED 
						.else 
							invoke EnableMenuItem,hMenu,104,MF_BYCOMMAND or MF_ENABLED  
							invoke EnableMenuItem,hMenu,105,MF_BYCOMMAND or MF_ENABLED 
						.endif 
						invoke TrackPopupMenu,hMenu,TPM_LEFTALIGN,ps.x,ps.y,NULL,hWin,NULL 
						invoke PostMessage,hWin,0,0,0 
            .ENDIF  
.elseif uMsg==WM_CONTEXTMENU 
		invoke GetCursorPos,addr ps 
		invoke GetWindowRect,hList,addr rect 
		mov eax,ps.x 
		mov ecx,ps.y 
		;如果范围在播放列表中,则弹出操作列表的菜单 
		.if (eax>rect.left && eaxrect.top && ecxeax ;如果到最前则滚到最后(负数是用补码表示的) 
				cmp TempNum,MF_CHECKED 
				jnz @F 
				sub eax,1 
				mov ecx,eax 
			.endif 
		.endif 
			invoke SendMessage,hList1,LB_SETCARETINDEX ,ecx,FALSE 
			invoke SendMessage,hWin,WM_COMMAND,100,lParam ;播放 
			ret 
			@@: 
			invoke SendMessage,hWin,WM_COMMAND,102,0 
	.endif 
.elseif uMsg == WM_CLOSE 
		;退出程序先关闭驱动器 
		invoke SendMessage,hWin,WM_COMMAND,102,lParam 
		INVOKE Shell_NotifyIcon,NIM_DELETE,ADDR inf 
		;保存播放器的参数 
		.if ProgMin==FALSE 
			invoke GetWindowRect,hWin,addr rect 
			invoke wsprintf,offset Buffer1,offset tempnum,rect.top 
			invoke WritePrivateProfileString,offset Config,offset top,offset Buffer1,offset INIPath 
			invoke wsprintf,offset Buffer1,offset tempnum,rect.left 
			invoke WritePrivateProfileString,offset Config,offset left,offset Buffer1,offset INIPath 
		.endif 
		invoke wsprintf,offset Buffer1,offset tempnum,WindowMode 
		invoke WritePrivateProfileString,offset Config,offset Window,offset Buffer1,offset INIPath 
		;是否随机 
		invoke GetMenuState,hMenu,103,MF_BYCOMMAND 
		.if eax==MF_CHECKED 
			invoke wsprintf,offset Buffer1,offset tempnum,1 
		.else 
			invoke wsprintf,offset Buffer1,offset tempnum,0 
		.endif 
			invoke WritePrivateProfileString,offset Config,offset RandPlay,offset Buffer1,offset INIPath 
		;循环模式 
		invoke GetMenuState,hMenu,107,MF_BYCOMMAND 
		.if eax==MF_CHECKED 
			invoke wsprintf,offset Buffer1,offset tempnum,1 
		.else 
			invoke wsprintf,offset Buffer1,offset tempnum,0 
		.endif 
			invoke WritePrivateProfileString,offset Config,offset LoopPlay,offset Buffer1,offset INIPath 
			;歌词显示模式 
			invoke wsprintf,offset Buffer1,offset tempnum,SongWordShowMode 
			invoke WritePrivateProfileString,offset Config,offset SongWordShowModeSave,offset Buffer1,offset INIPath 
			;显示速度 
			invoke GetDlgItem,hWin,1006 
			invoke SendMessage,eax,TBM_GETPOS,0,0 
			invoke wsprintf,offset Buffer1,offset tempnum,WordShowTime 
			invoke WritePrivateProfileString,offset Config,offset SongWordShowTime,offset Buffer1,offset INIPath 
 
		;如果正在显示的是CD列表,则跳过 
		cmp PlayMode,TRUE 
		jz CDSkip 
		;退出时保存播放列表 
		;保存之前清空以前的播放列表 
		lea eax,MP3List 
		invoke WritePrivateProfileString,eax,0,0,offset INIPath 
		invoke SendMessage,hList1,LB_GETCOUNT,0,0 
		mov TempNum,eax 
		mov Index,0 
		@@: 
		mov eax,TempNum 
		cmp Index,eax ;如果当前选择超出索引(小于列表总数也有可能是没任何项目)则跳出 
		jae @F 
			invoke SendMessage,hList1,LB_GETTEXT,Index,offset Buffer1 
			invoke GetLongPathName,offset Buffer1,offset TempBuffer,sizeof TempBuffer 
			invoke GetFileTitle,offset TempBuffer,offset OnlyFileName,sizeof OnlyFileName 
			lea eax,temp 
			invoke wsprintf,offset MciResult,eax,Index 
			invoke lstrcat,offset OnlyFileName,offset CuPathStr 
			invoke lstrcat,offset OnlyFileName,offset Buffer1 
			lea eax,MP3List 
			invoke WritePrivateProfileString,eax,offset MciResult,offset OnlyFileName,offset INIPath 
			inc Index ;继续选择下一个 
			jmp @B 
		@@: 
	CDSkip: 
		invoke KillTimer,hWin,100 
		;程序销毁 
		invoke PostQuitMessage,NULL 
	.ELSE 
		invoke DefWindowProc,hWin,uMsg,wParam,lParam 
		ret 
	.ENDIF 
	xor    eax,eax 
	ret 
WndProc endp 
include OtherProc.asm 
;定时器过程 
TimeEventProc proc uid,umsg,dwuser,dw1 
	.if Mp3State==1 
		.if PlayMode==TRUE 
 
			lea eax,GetCDCurrentPos 
			invoke mciSendString,eax,offset MciResult,sizeof MciResult,hWnd 
			invoke StrToDword,offset MciResult 
			sub eax,CurrCDPosition 
			cmp eax,TotalLength 
			jl @F 
				invoke SendMessage,hWnd,WM_COMMAND,105,0 
				ret 
			@@: 
			mov CurrPosition,eax 
			invoke GetDlgItem,hWnd,9 
			invoke InvalidateRect,eax,NULL,TRUE 
		.else 
 
			invoke GetDlgItem,hWnd,9 
			invoke InvalidateRect,eax,NULL,TRUE 
			.if ExistFile==TRUE 
				invoke GetDlgItem,hWnd,1009 
				invoke InvalidateRect,eax,NULL,TRUE 
			.endif 
			lea eax,GetMp3CurrentPos 
			invoke mciSendString,eax,offset MciResult,sizeof MciResult,hWnd 
			invoke StrToDword,offset MciResult 
			mov CurrPosition,eax 
		.endif 
		invoke SendMessage,hTrack,TBM_SETPOS,TRUE,CurrPosition 
	.endif 
ret 
TimeEventProc endp 
 
END START