博文

如何用API及MMSYSTEM.DLL播放WAV文件(2006-02-15 22:09:00)

摘要:Declare Function sndPlaySound% Lib "MMSYSTEM.DLL" (ByVal lpszSoundName$, ByVal wFlags%)Global Const SND_SYNC = &H0000Global Const SND_ASYNC = &H0001Global Const SND_NODEFAULT = &H0002Global Const SND_LOOP = &H0008Global Const SND_NOSTOP = &H0010' Paramaters:' lpszSoundName$'  Specifies the name of the sound to play. The function first' searches the [sounds] section of the WIN.INI file for an entry' with the specified name, and plays the associated waveform sound' file. If no entry by this name exists, then it assumes the' specified name is the name of a waveform sound file. If this' parameter is NULL, any currently playing sound is stopped.' That is, use a 0& to provide a NULL value.' wFlags%'  Specifies options for playing the sound using one or more' of the following flags: ' SND_SYNC: The sound is played synchronously and the function' does not return until the sound ends.' SND_ASYNC: The sound is played asynchronously and the function' returns immediately af......

阅读全文(2867) | 评论:0

Tag属性的妙用(2006-02-15 22:07:00)

摘要:在VB编程中,我们经常要动态的控制很多不同控件的属性,例如我们要将一个CommandButton阵列共20各控件中的第1、4、6、7、8、11、18、20号删除。该怎么半呢?这时只要将要删除的控件的Tag属性设置为1,然后加入以下代码就可以了。For i=1 To 20If Command1(i).Tag=1 ThenUnload Command1(i)End IfNext i-----------------------------------------------------......

阅读全文(2804) | 评论:0

如何用API播放CD(2006-02-15 22:06:00)

摘要:Declare Function mciSendString& Lib "MMSYSTEM" (ByVal lpstrCommand$, ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%)'Add the code below to appropriate routinesSub cmdPlay_Click ()Dim lRet As LongDim nCurrentTrack As Integer'Open the devicelRet = mciSendString("open cdaudio alias cd wait", 0&, 0, 0)'Set the time format to Tracks (default is milliseconds)lRet = mciSendString("set cd time format tmsf", 0&, 0, 0)'Then to play from the beginninglRet = mciSendString("play cd", 0&, 0, 0)'Or to play from a specific track, say track 4nCurrentTrack = 4lRet = mciSendString("play cd from" & Str(nCurrentTrack), 0&, 0, 0)End Sub' Remember to Close the device when ending playbackSub cmdStop_Click ()Dim lRet As Long'Stop the playbacklRet = mciSendString("stop cd wait", 0&, 0, 0)DoEvents 'Let Windows process the event'Close the devicelRet = mciSendString("close cd", 0&, 0, 0)End Sub---------------------------------------------------......

阅读全文(2311) | 评论:0

音效档播放程式(2006-02-15 22:02:00)

摘要:所需物件:PictureBox(1),Label(6),CommandButton(2),CommonDialog(1),MMControl(1)。Const INTERVAL = 1000Dim CurVal As DoublePrivate Sub CmdEnd_Click()MMControl1.Command = "stop"MMControl1.Command = "close"EndEnd SubPrivate Sub CmdOpen_Click()MMControl1.Command = "stop"MMControl1.Command = "close"Close #1On Error GoTo errhandlerCMDlg.Filter = "音效档(*.wav;*.mid) |*.wav;*.mid"CMDlg.FilterIndex = 1CMDlg.Action = 1Open CMDlg.filename For Input As #1If Right$(CMDlg.filename, 3) = "wav" ThenMMControl1.DeviceType = "waveaudio"ElseMMControl1.DeviceType = "sequencer"End IfMMControl1.filename = CMDlg.filenameMMControl1.Command = "open"CurVal = 0#MMControl1.UpdateInterval = 0errhandler:Exit SubEnd SubPrivate Sub Form_Load()Label1.Caption = "音效档名:"Label2.Caption = "总共时间:"Label3.Caption = "目前位置:"MMControl1.UpdateInterval = 0End SubPrivate Sub Form_Unload(Cancel As Integer)Const MCI_MODE_NOT_OPEN = 524If Not MMControl1.Mode = MCI_MODE_NOT_OPEN ThenMMControl1.Command = "close"End IfEnd SubPrivate Sub MMControl1......

阅读全文(2764) | 评论:0

按字母或数字顺序排列列表框中的列表项.(2006-02-06 17:16:00)

摘要:将以下代码加入到你的程序中.Sub ReSort(L As Control)Dim P%, PP%, C%, Pre$, S$, V&, NewPos%, CheckIt%Dim TempL$, TempItemData&, S1$For P = 0 To L.ListCount - 1S = L.List(P)For C = 1 To Len(S)V = Val(Mid$(S, C))If V > 0 Then Exit ForNextIf V > 0 ThenIf C > 1 Then Pre = Left$(S, C - 1)NewPos = -1For PP = P + 1 To L.ListCount - 1CheckIt = FalseS1 = L.List(PP)If Pre <> "" ThenIf InStr(S1, Pre) = 1 Then CheckIt = TrueElseIf Val(S1) > 0 Then CheckIt = TrueEnd IfIf CheckIt ThenIf Val(Mid$(S1, C)) < V Then NewPos = PPElseExit ForEnd IfNextIf NewPos > -1 ThenTempL = L.List(P)TempItemData = L.ItemData(P)L.RemoveItem (P)L.AddItem TempL, NewPosL.ItemData(L.NewIndex) = TempItemDataP = P - 1End IfEnd IfNextExit Sub......

阅读全文(3439) | 评论:1

小巧的服务程序源码(2006-01-14 19:31:00)

摘要:小巧的服务程序源码 --------------------------------------------------------------------------------上段时间因要写服务程,但发现程序比较大,不包含窗口类的情况下都要120K以上! 实在是太大了! svchost.exe服务程序的大小才 7.76 KB,我想服务程序可以写的很小! 我在网上找找了好长时间终于给我找到精简的服务程序的DELPHI代码(好的DELPHI代码实在是少啊), 我把源代码放上来和大家分享! program DemoSrv; // Windows NT Service Demo Program for Delphi 3 // By Tom Lee , Taiwan , Repubilc of China ( Tomm.bbs@csie.nctu.edu.tw ) // JUL 8 1997 // ver 1.01 // The service will beep every 10 second . uses SysUtils, Windows, WinSvc; const ServiceName = 'TomDemoService'; ServiceDisplayName = 'd99 test Service'; SERVICE_WIN32_OWN_PROCESS = $00000010; SERVICE_DEMAND_START = $00000003; SERVICE_ERROR_NORMAL = $00000001; EVENTLOG_ERROR_TYPE = $0001; // declare global variable var ServiceStatusHandle: SERVICE_STATUS_HANDLE; ssStatus: TServiceStatus; dwErr: DWORD; ServiceTableEntry: array[0..1] of TServiceTableEntry; hServerStopEvent: THandle; // Get error message function GetLastErrorText: string; var dwSize: DWORD; lpszTemp: LPSTR; begin dwSiz......

阅读全文(2808) | 评论:0

上三角矩阵运算 (2006-01-03 07:30:00)

摘要:******************************************************************* * This is a program for defining a new data type to transfer * * an upper trangular matrix. * * Made by Dr. Xue-bin Chi * * Date: April 27, 2005 * * Supercomputing Center * * Computer Network Information Center, CAS * ******************************************************************* program define_new_upper *The header file for using MPI parallel environment, which must be *included for all mpi programs. include 'mpif.h' *Variables declaration integer iam, np, comm, ierr integer lda parameter ( lda = 20 ) integer i, m, status(mpi_status_size), & lens(lda), disp(lda) real a(lda, lda) *Enroll in MPI environment and get the MPI parameters call mpi_ini......

阅读全文(4007) | 评论:0

数据结构类型 (2006-01-03 07:30:00)

摘要:******************************************************************* * This is a program for testing struct defined data type * * Made by Dr. Xue-bin Chi * * Date: April 30, 2005 * * Supercomputing Center * * Computer Network Information Center, CAS * ******************************************************************* program define_struct *The header file for using MPI parallel environment, which must be *included for all mpi programs. include 'mpif.h' *Variables declaration integer iam, np, comm, ierr integer lda, maxblk parameter ( lda = 20, maxblk = 5 ) integer i, m, status(mpi_status_size), newtype, & lens(lda), blclen(maxblk), types(maxblk), displs(maxblk) real a(lda) character*20 c *Enroll in MPI environment and get the MPI parameters ca......

阅读全文(3075) | 评论:1

归约 (2006-01-03 07:29:00)

摘要:******************************************************************* * This is a program for doing the summation of an array in * * each processors. * * Made by Dr. Xue-bin Chi * * Date: May 11, 2005 * * Supercomputing Center * * Computer Network Information Center, CAS * ******************************************************************* program mpi_reducing *The header file for using MPI parallel environment, which must be *included for all mpi programs. include 'mpif.h' *Variables declaration integer iam, np, comm, ierr integer lda parameter ( lda = 20 ) integer i, m, status(mpi_status_size), root, myop, & lens(lda) real a(lda*lda), b(lda*lda), sum(lda*lda), c(lda) external userfunc *Enroll in MPI env......

阅读全文(2249) | 评论:0

计算π值 (2006-01-03 07:29:00)

摘要:******************************************************************* * This is a program for computing the approximation of Pi * * The method is using the trapezoid formular for numerical * * integal. * * Made by Dr. Xue-bin Chi * * Date: April 6, 2005 * * Supercomputing Center * * Computer Network Information Center, CAS * ******************************************************************* program computing_pi *The header file for using MPI parallel environment, which must be *included for all mpi programs. include 'mpif.h' *Variables declaration integer iam, np, comm, ierr integer n, i, num, is, ie real*8 pi, h, eps, xi, s *Enroll in MPI environment and get the MPI parameters call mpi_init(ierr) call mpi_c......

阅读全文(3129) | 评论:0