[整理版]VC 制作具有声响后果的动画桌面精灵
VC++?à?Ì??ÊõÁ?ÔØ?,?,?,VC++ÖÆ×??ßÓÐÉùÒôÐ??ûµÄ???,×ÀÃæ??Áé
2007-06-18 11:09:52
VC++?à?Ì??ÊõÁ?ÔØ?,?,?,VC++ÖÆ×??ßÓÐÉùÒôÐ??ûµÄ???,×ÀÃæ??Áé
?ÉÓÃÍ?Ã?Î?Í?????ÔÚ×ÀÃæÉÏÏÔÊ?Î?Í?????Ê??ü??Î?Í?ÒÔʵÏÖ???,Ð??û??ÔÙ?ÉÓÃ???ÅÄÚ??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_CBBD225E
6BC4__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_RESOURCE|SND_PURGE|SND
_NODEFAULT );
SetTimer(2,61080,NULL); //ÉèÖÃ???ÅÉùÒôÊ??ä61.08Ãë //×ÊÔ?WAVÎÄ?þµÄIDÐë?ÓË?ÒýºÅ??ÓÃÏÂAPIº?Êý???Å PlaySound("WEST",AfxGetResourceHandle(),SND_RESOURCE|SND_ASYNC|SND
_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_NOSIZE|SWP_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;
}