设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Visual C++ >> 如何制作具有声音效果的动画桌面精灵
精品推荐
Visual C++点击TOP10
·用WINSOCK实现聊天室的VC++程序设计
·利用mfc编写activex控件
·用vc实现生产者消费者问题
·DirectX8.0
·C/C++ 大量经典编程书籍下载
·VC快捷键大全
·CreateFileMapping的MSDN翻译和使用心得
·Windows环境下的麦克风录音系统
·挂钩Windows API
·如何开发OPC Server
编程开发点击TOP10
·数字小键盘指法练习
·用C语言编通讯录程序(初学者级别的)
·ASP.NET 程序中常用的三十三种代码
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·java笔试题
·Modem 常用AT指令集
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

如何制作具有声音效果的动画桌面精灵

作者: 来源:网络文章 时间:2005-12-13 18:13:19

如何制作具有声音效果的动画桌面精灵(1)  

如何制作具有声音效果的动画桌面精灵XML:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

作者:徐景周

 

下载实例代码:CSdn.net/cnshare/soft/7/7085.shtm">http://www.csdn.net/cnshare/soft/7/7085.shtm

http://www.csdn.net/cnshare/soft/6/6620.shtm

 

你想制作出一个在桌面上透明显示,动态唱歌的桌面小精灵么?下面我来用我原来做的一个例子来教你如何来实现它。例子运行界面如下:

 

基本思路:采用透明位图方法在桌面上显示位图,定时更换位图以实现动画效果,再采用播放内部WAV资源文件方法来播放自带WAV文件既可(右键可关闭此程序)。

 

具体实现步骤如下:

1、  在新建的工程文件中(VC6.0)中导入一WAV文件,取名“WEST”,再导入两幅位图取名“WEST1”和“WEST2”。

2、  新建一.h文件,取名TransparentWnd.h

代码内容如下:

#if !defined(AFX_TRANSPARENTWND_H__6508F000_5685_11D3_9001_CBBD225E6BC4__INCLUDED_)

#define AFX_TRANSPARENTWND_H__6508F000_5685_11D3_9001_CBBD225E6BC4__INCLUDED_

 

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// TransparentWnd.h : header file

//

//////////////////////////////////////

//作者: 徐景周. 2000.12

//功能:透明位图及WAV资源播放

//////////////////////////////////////

// TransparentWnd window

 

class TransparentWnd : public CWnd

{

// ConstrUCtion

public:

TransparentWnd();

 

void CreateTransparent(LPCTSTR pTitle, RECT &rect);

void SetupRegion(CDC *pDC);

void DoChange(void);

void SoundPlay(void);

 

CBitmap m_bmpDraw;

    int m_iAniSeq;

 

// Attributes

public:

 

// Operations

public:

 

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(TransparentWnd)

//}}AFX_VIRTUAL

 

// Implementation

public:

virtual ~TransparentWnd();

 

// Generated message map functions

protected:

//{{AFX_MSG(TransparentWnd)

afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

afx_msg BOOL OnEraseBkgnd(CDC* pDC);

afx_msg void OnTimer(UINT nIDEvent);

afx_msg void OnRButtonDown(UINT nFlags, CPoint point);

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

 

/////////////////////////////////////////////////////////////////////////////

 

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

 

#endif // !defined(AFX_TRANSPARENTWND_H__6508F000_5685_11D3_9001_CBBD225E6BC4__INCLUDED_)

3、  新建一.cpp文件,取名:TransparentWnd.cpp

代码内容如下:

// TransparentWnd.cpp : implementation file

//////////////////////////////////////

//作者: 徐景周. 2000.12

//功能:透明位图及WAV资源播放

//////////////////////////////////////

#include "stdafx.h"

#include "West.h"

#include "TransparentWnd.h"

#include "WestDlg.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

 

/////////////////////////////////////////////////////////////////////////////

// TransparentWnd

 

TransparentWnd::TransparentWnd()

{

m_iAniSeq=0; //图像变化初始值

}

 

TransparentWnd::~TransparentWnd()

{

}

 

BEGIN_MESSAGE_MAP(TransparentWnd, CWnd)

//{{AFX_MSG_MAP(TransparentWnd)

ON_WM_LBUTTONDOWN()

ON_WM_CREATE()

ON_WM_ERASEBKGND()

ON_WM_TIMER()

ON_WM_RBUTTONDOWN()

ON_COMMAND(IDR_HELP, OnHelp)

ON_COMMAND(IDR_EXIT, OnExit)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

//********************************************************************************

//* CreateTransparent()

//*

//* Creates the main application window transparent

//********************************************************************************

void TransparentWnd::CreateTransparent(LPCTSTR pTitle, RECT &rect)

{

// 创建一个隐藏窗口

CreateEx(   0, 

     AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW)),

             pTitle,

             WS_POPUP ,

             rect,

             NULL,

             NULL,

             NULL);

DoChange();

}

 

//********************************************************************************

//* SetupRegion()

//*

//* Set the Window Region for transparancy outside the mask region

//********************************************************************************

void TransparentWnd::SetupRegion(CDC *pDC)

{

CDC                 memDC;

CBitmap         &cBitmap=m_bmpDraw;

CBitmap*        pOldMemBmp = NULL;

COLORREF        col,colMask;

CRect               cRect;

int                 x, y;

CRgn                wndRgn, rgnTemp;

 

GetWindowRect(&cRect);

CPoint ptOrg=cRect.TopLeft();

 

BITMAP bmInfo;

cBitmap.GetObject(sizeof(bmInfo),&bmInfo);

CRect rcNewWnd=CRect(ptOrg,CSize(bmInfo.bmWidth,bmInfo.bmHeight));

 

memDC.CreateCompatibleDC(pDC);

pOldMemBmp = memDC.SelectObject(&cBitmap);

colMask=memDC.GetPixel(0,0);

 

wndRgn.CreateRectRgn(0, 0, rcNewWnd.Width(), rcNewWnd.Height());

for(x=0; x<=rcNewWnd.Width(); x++)

{

     for(y=0; y<=rcNewWnd.Height(); y++)

     {

         col = memDC.GetPixel(x, y);

         if(col == colMask)

         {

             rgnTemp.CreateRectRgn(x, y, x+1, y+1);

             wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);

             rgnTemp.DeleteObject();

         }

     }

}

if (pOldMemBmp) memDC.SelectObject(pOldMemBmp);

SetWindowRgn((HRGN)wndRgn, TRUE);

MoveWindow(rcNewWnd);

}

 

void TransparentWnd::DoChange(void)

{

  char szBmp[20];

 

   //不断替换图像

   sprintf(szBmp,"WEST%d",m_iAniSeq%2+1);

 

m_bmpDraw.DeleteObject();

m_bmpDraw.LoadBitmap(szBmp);

CWindowDC dc(this);

SetupRegion(&dc);

Invalidate();

 

}

 

void TransparentWnd::SoundPlay(void)

{

 //先关闭原声音播放

PlaySound("WEST",AfxGetResourceHandle(),SND_RESOURCESND_PURGESND_NODEFAULT  );

    SetTimer(2,61080,NULL); //设置播放声音时间61.08秒

 //资源WAV文件的ID须加双引号,用下API函数播放

    PlaySound("WEST",AfxGetResourceHandle(),SND_RESOURCESND_ASYNCSND_NODEFAULT  );

}

 

void TransparentWnd::OnLButtonDown(UINT nFlags, CPoint point)

{

 

CWnd::OnLButtonDown(nFlags, point);

 

//实现无标题拖动

PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));

}

 

int TransparentWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CWnd::OnCreate(lpCreateStruct) == -1)

     return -1;

    SetTimer(1,1000,NULL);  //开始时的图像显示时间

    SetTimer(2,500,NULL); //启动声音播放计时器

 

SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZESWP_NOMOVE); //窗体总在总前面  

return 0;

}

 

BOOL TransparentWnd::OnEraseBkgnd(CDC* pDC)

{

    CRect    rect;

GetWindowRect(&rect);

 

CDC memDC;

CBitmap         &cBitmap=m_bmpDraw;;

CBitmap*        pOldMemBmp = NULL;

CFont* pOldMemFont=NULL;

 

memDC.CreateCompatibleDC(pDC);

pOldMemBmp = memDC.SelectObject(&cBitmap);

pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY);

 

if (pOldMemBmp) memDC.SelectObject( pOldMemBmp );

 

return TRUE;   

//   return CWnd::OnEraseBkgnd(pDC);

}

 

void TransparentWnd::OnTimer(UINT nIDEvent)

{

   switch(nIDEvent)

{

case(1)://变换图像

     DoChange();

     break;

case(2): //播放声音

     SoundPlay();

     break;

default:

     break;

}

m_iAniSeq++;

if(m_iAniSeq==2)

      m_iAniSeq=0;

CWnd::OnTimer(nIDEvent);

}

 

void TransparentWnd::OnRButtonDown(UINT nFlags, CPoint point)

{

CWnd::OnRButtonDown(nFlags, point);

 

   DestroyWindow(); //鼠标右键点击时关闭此程序

}

 

4、  在应用类(West.cpp)代码中初始化实例涵数改为下面既可:

BOOL CWest::InitInstance()

{

        srand(time(NULL));

   

    //一次只运行一个程序实例,如果已运行则退出

    if( FindWindow(NULL,"大话西游经典系列之--情感天地")) exit(0);

 

    TransparentWnd* pFrame = new TransparentWnd;

    m_pMainWnd = pFrame;

   

    // create and load the frame with its resources

    CRect rect(0, 0, 100, 100);

    pFrame->CreateTransparent("大话西游经典系列之--情感天地", rect);//IDB_MASK, IDB_BACK);

    pFrame->CenterWindow();  //初始显示窗体位置

    pFrame->ShowWindow(SW_SHOW);

   

    return TRUE;

}

 

其中具体实现细节,请在下载实例代码后仔细查看,~o~

 

作者EMAIL:jingzhou_xu@163.net

未来工作室(Future Studio)

共2页 9 7 [1] [28 :>

如何制作具有声音效果的动画桌面精灵 相关文章:
如何制作具有声音效果的动画桌面精灵 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com