Click here to Skip to main content
13,000,323 members (71,794 online)
Click here to Skip to main content
Add your own
alternative version


79 bookmarked
Posted 31 Dec 2009

To Create A COOL Desktop Lyrics Demo (A Gift To All People On CP)

, 1 Jan 2010
Rate this:
Please Sign up or sign in to vote.
Many popular MP3 players have cool desktop lyrics, this demo uses a simple method to realize it. Happy new year!



The code demonstrates how to use GDI plus create an application with VC6. Many popular MP3 players have desktop lyrics. It's really cool, I like it very much. So I decided tp try to realize it. But I found it's really hard. Here,I should thank all the CodeProject contributors first because I learned much from GDI+ section. After I refreshed the GDI+ functions, I wrote the code. Hope it will help you. This is a gift I send to the members on CodeProject. Happy new year! Download the demo right now and have fun!

Explanation of the Code

Now, let's have a look at the code. How was this demo created. The demo was based on a dialog, not a class. But, I will not talk more about the basic steps of generation of dialog. I suppose you know about the usage of MFC. To look for more, read other articles or MSDN online.

Step 1

We use GDI plus functions, so the first thing is include the header and lib files.

#define UNICODE
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#include "gdiplus.h"   		////Modify your path
using namespace Gdiplus;   		//Using the namespace of GDI+
#pragma comment(lib, "gdiplus.lib") 	//Modify your lib path

I add the snippets into the dialog's header. Of course, #include "gdiplus.h" you can also modify your own path of your computer. Be sure the path is correct, or the VC can't find it.

Step 2

We use the class wizard to add several messages deal functions. WM_CREATE WM_TIMER WM_CONTENTMENU WM_DESTROY WM_LBUTTONDOWN... for more, download the resources.

We'll use GDI+, so GdiplusStartup() must be invoked before we use its functions. Before the application exits, we need to invoke another function GdiplusShutdown().

//The snippets put into header file
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;

//Following code put into construction method
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

//Invoke function to clear
void CGDIAPPDlg::OnDestroy() 
 // TODO: Add your message handler code here

Okay! We have finished doing the first job.

Step 3

Initializations for the dialog. We want to invoke the UpdateLayeredWindow() in the "user32.dll", so we should get the address of the function.

int CGDIAPPDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
 if (CDialog::OnCreate(lpCreateStruct) == -1)
  return -1;
    hFuncInst = LoadLibrary("User32.DLL"); 
  UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInst, "UpdateLayeredWindow");
  AfxMessageBox("User32.dll ERROR!");

 // Initialize GDI+.
 m_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000
 m_Blend.BlendFlags=0; //nothingelseisspecial...
 m_Blend.AlphaFormat=1; //...
 return 0;

Step 4

Okay! Now we begin to think how to draw on desktop. The method is:

  1. Create a compatible bitmap.
  2. Draw on the bitmap.
  3. Draw bitmap on the device content.
  4. Invoke the UpdateLayeredWindows().

I write a method to do all the jobs like others do (others' snippets). The following is the code. Let's have a look into the details:

BOOL CGDIAPPDlg::UpdateDisplay(int Transparent)
 HDC hdcTemp=GetDC()->m_hDC;
 m_hdcMemory=CreateCompatibleDC(hdcTemp);   //Create the compatibleDC
 HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,755,350); //Create the compatible bitmap
 SelectObject(m_hdcMemory,hBitMap);//Select bitmap into device content
 if(Transparent<0||Transparent>100) Transparent=100;

 HDC hdcScreen=::GetDC (m_hWnd);
 RECT rct;
 POINT ptWinPos={rct.left,};

 Graphics graph(m_hdcMemory);

 Graphics graphics(m_hdcMemory);


 FontFamily fontFamily(L"Arial Black");
 StringFormat strformat;

//Here is the text we want to show on the desktop, we can read it from a file.
//I'll modify it later.
 wchar_t pszbuf[][80]={{L"Hello everyone!"},
 {L"Happy New Year!"},
 {L"I wish you will lead a  happy life!"},
 {L"Love you!"},
 {L"Thanks all the people on CP!"}

//The following code is used to draw the text on dc
 GraphicsPath path;

 Pen pen(Color(155,215,215,215),3);


 LinearGradientBrush linGrBrush(

 LinearGradientBrush linGrBrushW(
/*Draw shade ,I study from others. */
   for(int i=1; i<9; i+=1)
        Pen pen(Color(62, 0, 2, 2), i);
        graphics.DrawPath(&pen, &path);
   SolidBrush brush(Color(25,228,228,228));
   Pen pen1(Color(155,223,223,223));
   Pen pen2(Color(55,223,223,223));  
   Image image(L"ly.png");


 SIZE sizeWindow={755,350};
 POINT ptSrc={0,0};
 DWORD dwExStyle=GetWindowLong(m_hWnd,GWL_EXSTYLE);	//Don't forget to set 
						//the dialog's extent style.

 bRet= UpdateLayeredWindow( m_hWnd,hdcScreen,&ptWinPos,
 return bRet;

When the dialog is created, call this method and it does work.

Points of Interest

I learned many new ideas and functions while writing the article. Hope you will also like it! You can use the code in any way, and to create much more stronger applications. Thanks for your support again! Happy new year!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aric Wang
China China
Although I was a college studnet now as the same I was also a teacher of C/C++/3DS MAX/website for National Computer Rank Examination.I began to study computer when I was a child 8 year's old.I use BASIC/C/C++/VB/VF/VC/DELPHI/.NET to programming.When in college I was the chairman of Computer Association of our school and I take part in ACM Competition twice in two years.I also was the only person who take part in the National Mathematical Contest in Modeling twice in two years of our school.I like computer programming very much.Hope to be your friend.thx!

You may also be interested in...

Comments and Discussions

QuestionCan you give me the source code? or where can i find it ! please... Pin
Member 106595006-Jan-15 0:24
memberMember 106595006-Jan-15 0:24 
Question谢谢楼主 Pin
94009403317-Jul-14 17:10
member94009403317-Jul-14 17:10 
Question楼主很强 Pin
dlsyaim19-May-14 23:07
memberdlsyaim19-May-14 23:07 
AnswerRe: 楼主很强 Pin
Aric Green17-Oct-14 0:02
memberAric Green17-Oct-14 0:02 
GeneralMy vote of 5 Pin
gndnet31-Jul-12 13:50
membergndnet31-Jul-12 13:50 
GeneralRe: My vote of 5 Pin
Aric Green16-Oct-14 23:50
memberAric Green16-Oct-14 23:50 
Questionnice work Pin
hellix201218-Aug-11 16:37
memberhellix201218-Aug-11 16:37 
AnswerRe: nice work Pin
Aric Green16-Oct-14 23:53
memberAric Green16-Oct-14 23:53 
GeneralI am trying to do the same thing using c# Pin
Hanson Cheng16-Mar-11 17:58
memberHanson Cheng16-Mar-11 17:58 
GeneralRe: I am trying to do the same thing using c# Pin
Aric Green17-Oct-14 0:00
memberAric Green17-Oct-14 0:00 
General这个代码看着好面熟哦... Pin
jackieron22-Feb-11 22:45
memberjackieron22-Feb-11 22:45 
GeneralRe: 这个代码看着好面熟哦... Pin
Aric Green8-Mar-11 16:41
memberAric Green8-Mar-11 16:41 
QuestionVery Good Article Pin
TheRoughGuy9-Feb-10 10:16
memberTheRoughGuy9-Feb-10 10:16 
AnswerRe: Very Good Article Pin
Aric Green9-Feb-10 17:49
memberAric Green9-Feb-10 17:49 
GeneralRe: Very Good Article Pin
TheRoughGuy10-Feb-10 3:38
memberTheRoughGuy10-Feb-10 3:38 
GeneralRe: Very Good Article Pin
Aric Green10-Feb-10 5:38
memberAric Green10-Feb-10 5:38 
GeneralRe: Very Good Article Pin
TheRoughGuy10-Feb-10 6:39
memberTheRoughGuy10-Feb-10 6:39 
GeneralRe: Very Good Article Pin
Aric Green10-Feb-10 21:20
memberAric Green10-Feb-10 21:20 
GeneralRe: Very Good Article Pin
Hanson Cheng16-Mar-11 17:56
memberHanson Cheng16-Mar-11 17:56 
AnswerRe: Very Good Article Pin
eyinlijun16-Sep-10 21:52
membereyinlijun16-Sep-10 21:52 
GeneralVery good! Pin
enzomidi13-Jan-10 23:07
memberenzomidi13-Jan-10 23:07 
GeneralRe: Very good! Pin
Aric Green14-Jan-10 17:16
memberAric Green14-Jan-10 17:16 
GeneralRe: Very good! Pin
enzomidi15-Jan-10 5:12
memberenzomidi15-Jan-10 5:12 
GeneralLittle interest Pin
PatLeCat6-Jan-10 23:35
memberPatLeCat6-Jan-10 23:35 
GeneralRe: Little interest Pin
Aric Green7-Jan-10 2:09
memberAric Green7-Jan-10 2:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 1 Jan 2010
Article Copyright 2009 by Aric Wang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid