#include "stdafx.h"
#include "nc.h"
#include "ncDlg.h"
#include "winuser.h"
#include "FileCopyProgress.h"
#include "FlgDel.h"
#include "include\fs.h"
//#include <direct.h>
//nc
#include "NcFolder.h"
//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual void OnOK();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//DDX_Control(pDX, IDC_BUTTON1, m_btn);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNcDlg dialog

CNcDlg::CNcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNcDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDI_SYS_ICON);
	m_hIcontp = AfxGetApp()->LoadIcon(IDI_ICON_TP);
	statflag=0;
	m_listflag=0;
	m_musicflag=0;
	checkncflag=0;
	/*_snprintf(m_SkinPath, MAX_PATH, "%s\0", SkinFile);
	char *tmp = strrchr(m_SkinPath, '\\');
	if(tmp != NULL)
		*(tmp + 1) = 0;

	SkinPath.Format("%s",m_SkinPath);*/
}

void CNcDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//	//{{AFX_DATA_MAP(CNcDlg)
	DDX_Control(pDX, IDC_CLOSE, m_btclose);
	DDX_Control(pDX, IDC_MIN, m_btmin);
	//	DDX_Control(pDX, IDC_max, m_btmax);
	DDX_Control(pDX, IDC_BUTTON1, m_btback);
	DDX_Control(pDX, IDC_BUTTON2, m_btplay);
	DDX_Control(pDX, IDC_BUTTON3, m_btnext);
	DDX_Control(pDX, IDC_BUTTON4, m_btmusic);
	DDX_Control(pDX, IDC_BUTTON5, m_btpicture);
	DDX_Control(pDX, IDC_BUTTON6, m_btebook);
	DDX_Control(pDX, IDC_NDIR, m_btndir);
	DDX_Control(pDX, IDC_DEL, m_btdel);
	DDX_Control(pDX, IDC_REFRESH, m_btrefresh);
	DDX_Control(pDX, IDC_LIST1, m_SkinList);
	DDX_Control(pDX, IDC_VOLUME, m_volume);
	DDX_Control(pDX, IDC_CARD_SPACE, m_cardspace);
	DDX_Control(pDX, IDC_MUTE_CTL, m_mute);
	DDX_Control(pDX, IDC_FREESPACE, m_freespace);
	DDX_Control(pDX, IDC_STATIC_FREESPACE_BK, m_freespace_bk);
	//DDX_Control(pDX, IDC_MUTE, m_mute);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNcDlg, CDialog)
//	//{{AFX_MSG_MAP(CNcDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_WM_ACTIVATE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_max, Onmax)
ON_BN_CLICKED(IDC_MIN, OnMin)
ON_BN_CLICKED(IDC_CLOSE, OnClose)
ON_BN_CLICKED(IDC_BUTTON2, OnPlayMusic)
ON_BN_CLICKED(IDC_BUTTON4, OnListMusic)
ON_BN_CLICKED(IDC_BUTTON5, OnListPicture)
ON_BN_CLICKED(IDC_BUTTON6, OnListBook)
ON_BN_CLICKED(IDC_NDIR, OnAddFile)
ON_BN_CLICKED(IDC_M_ADD, OnAddFile)
ON_BN_CLICKED(IDC_DEL, OnDelFile)
ON_BN_CLICKED(IDC_M_DEL, OnDelFile)
ON_BN_CLICKED(IDC_REFRESH, OnRefreshList)
ON_BN_CLICKED(IDC_M_REFRESH, OnRefreshList)
ON_BN_CLICKED(IDC_BUTTON3, OnNextFile)
ON_WM_HSCROLL()
ON_WM_TIMER()
ON_MESSAGE(WM_NOTIFYICON, OnNotifyIcon)	
ON_BN_CLICKED(IDC_MUTE_CTL, OnMute)
ON_WM_MOUSEWHEEL()
ON_WM_MOVE()
ON_WM_CANCELMODE()
ON_WM_KILLFOCUS()
ON_WM_DROPFILES()
ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList)
ON_NOTIFY( NM_DBLCLK, IDC_LIST1, OnDBclickList)
ON_MESSAGE(MYWM_NOTIFYICON,OnMyIconNotify)
ON_WM_DRAWITEM()
//	//}}AFX_MSG_MAP


END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNcDlg message handlers
afx_msg LRESULT CNcDlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
	if ((wParam == IDI_ICON)&&(lParam == WM_LBUTTONDOWN))
		ShowWindow(SW_SHOWNORMAL);
	//refresh min button status
	CPoint pt;
	pt.x=1;pt.y=1;
	m_btmin.OnMouseLeave(1,pt);
	return 0;
}

void CNcDlg::SetButtonStatus(BOOL btstat)
{
	//m_btnext.EnableWindow(btstat);
	//m_btback.EnableWindow(btstat);
	m_btplay.EnableWindow(btstat);
	m_btplay.Invalidate();
	//m_mute.EnableWindow(btstat);
	//m_volume.EnableWindow(btstat);
}
BOOL CNcDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	if(m_hIcon && m_hIcontp )
	{
		this->SetIcon(m_hIcontp, FALSE);		// Set small icon
		this->SetIcon(m_hIcon, TRUE);			// Set big icon
	}
	
	// TODO: Add extra initialization here
	m_cardspace.SetRange(1,100);//设置进度条范围	
	m_cardspace.SetStep(1);//设置步长
	
	// 将图标放入系统托盘
	nd.cbSize	= sizeof (NOTIFYICONDATA);
	nd.hWnd	= m_hWnd;
	nd.uID	= IDI_ICON;
	nd.uFlags	= NIF_ICON|NIF_MESSAGE|NIF_TIP|NIF_INFO;
	nd.uCallbackMessage	= WM_NOTIFYICON;
	nd.dwInfoFlags=NIIF_WARNING;//警告
	nd.hIcon	= m_hIcontp;
	nd.uTimeout=100;
	//notify set
	_tcscpy(nd.szInfoTitle ,"iQue聚乐部管理软件");
	_tcscpy(nd.szInfo,"注意:关闭本软件后才能在聚乐卡上操作!");
	strcpy(nd.szTip, "iQue聚乐部管理软件");
	Shell_NotifyIcon(NIM_ADD, &nd);
	
	//Shell_NotifyIcon(NIM_MODIFY, &nd);
	//end notify
	//start skinlist process
	m_SkinList.InsertItem(0,"dfd");
	//m_SkinList.SetBkImage(IDB_LISTBK);
	
	
	//set style of list
	DWORD dwStyle=m_SkinList.GetExStyle();
	dwStyle |=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES;
	m_SkinList.SetExtendedStyle(dwStyle);
	RECT r;
	GetClientRect(&r);
	
	CBitmap bmp;
	
	//m_SkinList.SetBkImage(_T(".\\r\\new.bmp"));
	m_SkinList.InsertColumn(0, "", LVCFMT_LEFT, 0);
	m_SkinList.InsertColumn(1, "文件名", LVCFMT_RIGHT, (r.right-269)/3 -25);
	m_SkinList.InsertColumn(2, "大小", LVCFMT_RIGHT, (r.right-269)/3) - 25;
	m_SkinList.InsertColumn(3, "类型", LVCFMT_RIGHT, (r.right-269)/3) - 25 ;
	
	
	m_volume.SetRange(0, 60000);
	m_volume.SetPos(10000);
	//InitFace();
	m_pic1.SubclassWindow( m_hWnd );
	m_pic1.m_nMessageHandler = CBitmapWindow::BackGroundPaint;
	
	
	//	bmp.LoadBitmap(IDB_LISTBK);
	//m_SkinList.SetBkImage(IDB_LISTBK);
	//m_SkinList.SetBkColor(RGB(239,239,239));
	m_toolTip.Create( this );
	straInfo.RemoveAll();
	straInfo.Add( "添加文件" );
	m_toolTip.AddControlInfo( IDC_CARD_SPACE, straInfo );
	// CG: The following block was added by the ToolTips component.
	{
		// Create the ToolTip control.
		m_tooltip.Create(this);
		m_tooltip.Activate(TRUE);
		
		// TODO: Use one of the following forms to add controls:
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");
		//	m_tooltip.AddTool(GetDlgItem(IDC_BUTTON1),"上一首");
		//	m_tooltip.AddTool(GetDlgItem(IDC_BUTTON2),"播放音乐");
		//	m_tooltip.AddTool(GetDlgItem(IDC_BUTTON3),"下一首");
		
		m_tooltip.AddTool(GetDlgItem(IDC_NDIR),"添加文件");
		m_tooltip.AddTool(GetDlgItem(IDC_DEL),"删除文件");
		m_tooltip.AddTool(GetDlgItem(IDC_REFRESH),"刷新列表");
	}

	//m_btmusic.m_bHasChanged=TRUE;//default status
	
	//m_btmusic.Invalidate();
	//set timer
	timer2=SetTimer(2,60000,NULL);
	timer1=SetTimer(1,1,NULL);
	//OnListMusic();
	//CBitmap bmp;
	//BOOL kk=m_SkinList.SetBkImage(IDB_LISTBK);
	//m_SkinList.SetBkImage(".\\r\\new.bmp");
	
	SetWindowText("iQue聚乐部管理软件");//set title of this window
	//end skinlist init	
	sort();
	getdefpath();
	SkinFile.Format("%s\\%s",m_DefPath,"ncskin\\red\\skin.ini");
	SetSkin((char*)(LPCTSTR)SkinFile);
	//SetSkin("D:\\skin07\\nc\\skin\\skin.ini");
	//RECT r;
	//GetClientRect(&r);
	CRgn rgn;
	rgn.CreateRoundRectRgn( 0, 0,r.right , r.bottom, 20,20 ); ;
	SetWindowRgn(rgn,TRUE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}
void CNcDlg::LoadButtonSkin(char *m_SkinFile,char *m_ButtonName)
{
	//CString bt1 = _T("BUT_MUSIC");
	CString bt1,databuf ;
	bt1.Format("%s",m_ButtonName);
	::GetPrivateProfileString("BUTTONINFO",bt1,"NULL",databuf.GetBuffer(MAX_PATH),MAX_PATH,m_SkinFile); 

	char *buf;
	buf = (char*)(LPCTSTR)databuf;
	
	//strtok();
	//butpicbuf.Compare()
	CString p1,p2,p3,p4,p5,p6,p7,butpicbuf;
	butpicbuf.Format("%s",strtok(buf, ","));
	if(butpicbuf != "(null)") 	
	{
		p1.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s",strtok(NULL, ",")); 
	if(butpicbuf != "(null)")	
	{	
		p2.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s",strtok(NULL, ",")); 
	if(butpicbuf != "(null)") 	
	{
		p3.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s",strtok(NULL, ",")); 
	if(butpicbuf != "(null)") 	
	{
		p4.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s\0",strtok(NULL, ","));
	if(butpicbuf != "(null)") 	 
	{
		p5.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s",strtok(NULL, ",")); 
	if(butpicbuf != "(null)") 	
	{
		p6.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	butpicbuf.Format("%s",strtok(NULL, ",")); 
	if(butpicbuf != "(null)")	
	{
		p7.Format("%s%s\0",m_SkinPath,butpicbuf);
		butpicbuf.Empty();
	}
	if(bt1 == "BUT_MUSIC")
	{m_btmusic.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_PHOTO")
	{m_btpicture.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_BOOK")
	{m_btebook.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_BACK")
	{m_btback.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_PLAY")
	{m_btplay.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_NEXT")
	{m_btnext.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_MIN")
	{m_btmin.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_CLOSE")
	{m_btclose.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_NEWDIR")
	{m_btndir.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_DEL")
	{m_btdel.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_REFRESH")
	{m_btrefresh.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	if(bt1 == "BUT_MUTE")
	{m_mute.LoadBitmaps(p1,p2,p3,p4,p5,p6,p7);}
	//m_mute.LoadBitmaps(IDB_VOLUME,IDB_VOLUME,0,IDB_MUTE);
	
}
void CNcDlg::SetSkin(char *m_SkinFile)
{
	//m_SkinFile.Load(SkinFile);
	SkinFile.Format("%s\0",m_SkinFile);
	_snprintf(m_SkinPath, MAX_PATH, "%s\0", m_SkinFile);
	char *tmp = strrchr(m_SkinPath, '\\');
	if(tmp != NULL)
		*(tmp + 1) = 0;

	SkinPath.Format("%s",m_SkinPath);
	//begin load dialog skin ---------------->
	CString sk1,sk2,sk3,sk4,sk6,sk8,sk9,sk0,sk10,sktitle,skbtleft,sktmp;
	
	int k=	::GetPrivateProfileString("DIALOG","1","default.fil",sk1.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","2","default.fil",sk2.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","3","default.fil",sk3.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","4","default.fil",sk4.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","6","default.fil",sk6.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","8","default.fil",sk8.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","9","default.fil",sk9.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","0","default.fil",sk0.GetBuffer(MAX_PATH),MAX_PATH, m_SkinFile);   
	k=	::GetPrivateProfileString("DIALOG","10","default.fil",sk10.GetBuffer(MAX_PATH),MAX_PATH,m_SkinFile);
	k=	::GetPrivateProfileString("DIALOG","TITLE","default.fil",sktitle.GetBuffer(MAX_PATH),MAX_PATH,m_SkinFile);
	k=	::GetPrivateProfileString("DIALOG","BOTTOMLEFT","default.fil",skbtleft.GetBuffer(MAX_PATH),MAX_PATH,m_SkinFile);
 
	
	sktmp.Format("%s%s\0",m_SkinPath,sk1); sk1=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk2); sk2=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk3); sk3=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk4); sk4=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk6); sk6=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk8); sk8=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk9); sk9=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk0); sk0=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sk10); sk10=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,sktitle); sktitle=sktmp;
	sktmp.Format("%s%s\0",m_SkinPath,skbtleft); skbtleft=sktmp;
	
	
	
	//
	m_pic1.Load(sk1,1);  
	m_pic1.Load(sk2,2);  
	m_pic1.Load(sk3,3);  
	m_pic1.Load(sk4,4);  
	m_pic1.Load(sk6,6);  
	m_pic1.Load(sk8,8);  
	m_pic1.Load(sk9,9);  
	m_pic1.Load(sk0,0);  
	m_pic1.Load(sk10,10);
	//m_pic1.LoadTitleAndBtLeft(sktitle,skbtleft);
	
//return;
	//init dialog end<---
	//set button skin -->
	LoadButtonSkin(m_SkinFile,"BUT_MUSIC");
	LoadButtonSkin(m_SkinFile,"BUT_PHOTO");
	LoadButtonSkin(m_SkinFile,"BUT_BOOK");
	LoadButtonSkin(m_SkinFile,"BUT_BACK");
	LoadButtonSkin(m_SkinFile,"BUT_PLAY");
	LoadButtonSkin(m_SkinFile,"BUT_NEXT");
	LoadButtonSkin(m_SkinFile,"BUT_MIN");
	LoadButtonSkin(m_SkinFile,"BUT_CLOSE");
	LoadButtonSkin(m_SkinFile,"BUT_NEWDIR");
	LoadButtonSkin(m_SkinFile,"BUT_DEL");
	LoadButtonSkin(m_SkinFile,"BUT_REFRESH");
	LoadButtonSkin(m_SkinFile,"BUT_MUTE");	
	//end set button skin<-- last changed 2007-4-19 21:34
	//init slider skin---->
	m_volume.LoadSliderSkin(m_SkinFile);	
	//m_volume.Invalidate();
	m_volume.EnableWindow(FALSE);
	m_volume.EnableWindow();
	//init slider skin end<------------
	//init static freespce skin
	CString m_freespace_bk_skin;
	
	::GetPrivateProfileString("FREESPACE","bk","default.fil",m_freespace_bk_skin.GetBuffer(MAX_PATH),MAX_PATH,m_SkinFile);
	sktmp.Format("%s%s\0",m_SkinPath,m_freespace_bk_skin); m_freespace_bk_skin=sktmp;
	HBITMAP p1 =(HBITMAP)::LoadImage(NULL,m_freespace_bk_skin,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
	CBitmap*   dstBmp=CBitmap::FromHandle((HBITMAP)CopyImage(p1,IMAGE_BITMAP,363,69,0));
	//m_freespace_bk.ModifyStyle(0xF,   SS_BITMAP|SS_CENTERIMAGE );CBitmap::FromHandle
	m_freespace_bk.SetBitmap((HBITMAP)p1); 
	DeleteObject(p1);
	//m_freespace_bk.GetClientRect()
	//init progress skin
	m_cardspace.LoadSkin(m_SkinFile);
	//init progress skin end
	//init listview bk
	
	m_SkinList.LoadSkin(m_SkinFile);
	//init listview bk end
	
}
void CNcDlg::sort()
{
	RECT r ; 
	GetClientRect(&r);
	
	//	CDC* dc=GetDC();	
	m_btebook.MoveWindow(17,303,232,120);
	m_btmusic.MoveWindow(17,63,232,120);
	m_btpicture.MoveWindow(17,183,232,120);
	
	m_SkinList.MoveWindow(CRect(249,44,r.right-20,r.bottom-98));
	
	m_btback.MoveWindow(27,r.bottom-76,37,51);
	m_btplay.MoveWindow(64,r.bottom-76,44,51);
	m_btnext.MoveWindow(108,r.bottom-76,37,51);
	
	m_btmin.MoveWindow(r.right-74,9,29,29);
	//	m_btmin.MoveWindow(r.right-102,8,29,29);
	//	m_btmax.MoveWindow(r.right-72,8,29,29);
	m_btclose.MoveWindow(r.right-45,9,29,29);
	
	m_btndir.MoveWindow(r.right-183,r.bottom-46,36,36);
	m_btdel.MoveWindow(r.right-139,r.bottom-46,36,36);
	m_btrefresh.MoveWindow(r.right-95,r.bottom-46,36,36);
	m_cardspace.MoveWindow(281,r.bottom-29,222,16);
	m_mute.MoveWindow(148,r.bottom-61,25,25);
	m_volume.MoveWindow(174,r.bottom-66,80,30);		
	m_freespace.MoveWindow(350,r.bottom-79,222,16);
	m_freespace_bk.MoveWindow(340,r.bottom-98,163,69);
	//m_freespace_bk.GetBitmap();
	
	//this->UpdateData();
	Invalidate(FALSE);
	
}
void CNcDlg::InitFace()
{
	//init Dialog
	m_pic1.SubclassWindow( m_hWnd );
	m_pic1.m_nMessageHandler = CBitmapWindow::BackGroundPaint;
	
	m_pic1.Load(".\\ncskin\\bk_part1.dat",1);
	m_pic1.Load(".\\ncskin\\bk_part2.dat",2);
	m_pic1.Load(".\\ncskin\\bk_part3.dat",3);
	m_pic1.Load(".\\ncskin\\bk_part4.dat",4);
	m_pic1.Load(".\\ncskin\\bk_part6.dat",6);
	//m_pic1.Load(".\\ncskin\\bk_part7.dat",7);	
	m_pic1.Load(".\\ncskin\\bk_part8.dat",8);
	m_pic1.Load(".\\ncskin\\bk_part9.dat",9);
	m_pic1.Load(".\\ncskin\\bk_part0.dat",0);
	m_pic1.Load(".\\ncskin\\bk_part10.dat",10);
	

	//init button face
	m_btback.LoadBitmaps(IDB_BACK_N,IDB_BACK_H,IDB_BACK_G,IDB_BACK_H,IDB_BACK_D);
	m_btback.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btplay.LoadBitmaps(IDB_PLAY_N,IDB_PLAY_H,IDB_PLAY_G,IDB_PLAY_STOP,IDB_PLAY_D,IDB_STOP_H,IDB_STOP_D);
	m_btplay.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btnext.LoadBitmaps(IDB_NEXT_N,IDB_NEXT_H,IDB_NEXT_G,IDB_NEXT_H,IDB_NEXT_D);
	m_btnext.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btmin.LoadBitmaps(IDB_MIN_N,IDB_MIN_H,IDB_MIN_H,IDB_MIN_H,IDB_MIN_D);
	m_btmin.SetTextAlignment(CBitButton::AlignBelow);
	
	//m_btmax.LoadBitmaps(IDB_MAX_N,IDB_MAX_H,IDB_MAX_H,IDB_RESTORE);
	//m_btmax.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btclose.LoadBitmaps(IDB_CLOSE_N,IDB_CLOSE_H,IDB_CLOSE_H,IDB_CLOSE_H,IDB_CLOSE_D);
	m_btclose.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btebook.LoadBitmaps(IDB_EBOOK_G,IDB_EBOOK_F,IDB_EBOOK_G,IDB_EBOOK_H);
	m_btebook.SetTextAlignment(CBitButton::AlignBelow);	
	
	m_btmusic.LoadBitmaps(IDB_MUSIC_G,IDB_MUSIC_F,IDB_MUSIC_G,IDB_MUSIC_H);
	m_btmusic.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btpicture.LoadBitmaps(IDB_PICTURE_G,IDB_PICTURE_F,IDB_PICTURE_G,IDB_PICTURE_H);
	m_btpicture.SetTextAlignment(CBitButton::AlignBelow);
	
	
	
	m_btndir.LoadBitmaps(IDB_NDIR_N,IDB_NDIR_H,IDB_NDIR_N,IDB_NDIR_H,IDB_NDIR_D);
	m_btndir.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btdel.LoadBitmaps(IDB_DEL_N,IDB_DEL_H,IDB_DEL_N,IDB_DEL_H,IDB_DEL_D);
	m_btdel.SetTextAlignment(CBitButton::AlignBelow);
	
	m_btrefresh.LoadBitmaps(IDB_REFRESH_N,IDB_REFRESH_H,IDB_REFRESH_N,IDB_REFRESH_H,IDB_REFRESH_D);
	m_btrefresh.SetTextAlignment(CBitButton::AlignBelow);
	
	m_mute.LoadBitmaps(IDB_VOLUME,IDB_VOLUME,0,IDB_MUTE);
	m_mute.SetTextAlignment(CBitButton::AlignBelow);
	
	RECT r;
	GetClientRect(&r);
	CRgn rgn;
	rgn.CreateRoundRectRgn( 0, 0,r.right , r.bottom, 20,20 ); ;
	SetWindowRgn(rgn,TRUE);
	
	//ShowCardSpace();
}
void CNcDlg::OnMyIconNotify(WPARAM wParam,LPARAM lParam)
{
	UINT uMouseMsg=LOWORD(lParam);
	switch(uMouseMsg)
	{
	case WM_LBUTTONDBLCLK:
		SendMessage(WM_CLOSE,0,0);
		break;
		
	case WM_LBUTTONDOWN:
		Shell_NotifyIcon(NIM_MODIFY,&nd);
		break;
	}
}

void CNcDlg::redrawsomepart()
{
	m_btplay.Invalidate();
	m_btnext.Invalidate();
	m_btback.Invalidate();
	m_btebook.Invalidate();
	m_volume.Invalidate();
	m_cardspace.Invalidate();
}
void CNcDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	if (nID == SC_MAXIMIZE)
	{	
		sort();
		return;
	}
	if (nID == SC_MINIMIZE)
		ShowWindow(SW_HIDE);
	else
		CWnd::OnSysCommand(nID, lParam);
}

void CNcDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for paint	ing
		
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}


HCURSOR CNcDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CNcDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDialog::OnLButtonDown(nFlags, point);
	PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y)); 
}

void CNcDlg::OnButton1() 
{
	if(m_SkinList.GetSelectionMark() !=0)
	{
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark(),0,  LVIS_SELECTED);
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark()-1,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
		m_SkinList.SetSelectionMark(m_SkinList.GetSelectionMark()-1);
	}
	else
	{
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark(),0,  LVIS_SELECTED);
		m_SkinList.SetItemState(m_SkinList.GetItemCount()-1,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
		m_SkinList.SetSelectionMark(m_SkinList.GetItemCount()-1);
	}
	if(m_listflag =2 )
	{
		if (mp.MCIIsPlaying())
		{
			mp.MCIStop();
			mp.MCIClose();
			LVITEM m_item;
			m_SkinList.GetItem(&m_item);
			playmusic();
		}
	}
}

void CNcDlg::Onmax() 
{
	if(statflag==0)//max
	{
		RECT orect;
		GetWindowRect(&orect);
		oldwidth=orect.right-orect.left;
		oldhight=orect.bottom-orect.top;
		px=orect.left;
		py=orect.top;
		
		RECT r;
		int   nWidth=GetSystemMetrics(SM_CXMAXIMIZED)-6;
		int   nHeight=GetSystemMetrics(SM_CYMAXIMIZED)-6;
		//		SetWindowPos(&wndTopMost,0,0,nWidth,nHeight,SWP_SHOWWINDOW);
		SetWindowPos(&CWnd::wndTop   ,0,0,nWidth,nHeight,SWP_DRAWFRAME);
		
		GetClientRect(&r);
		CRgn rgn;
		rgn.CreateRoundRectRgn( 0, 0,r.right , r.bottom, 20,20 ); ;
		SetWindowRgn(rgn,TRUE);
		PostMessage(WM_ERASEBKGND);
		sort();
		statflag=1;
		return;
	}
	else if(statflag==1)//restore
	{
		SetWindowPos(&CWnd::wndTop   ,px,py,oldwidth,oldhight,SWP_DRAWFRAME);
		CRect r;
		GetClientRect(&r);
		CRgn rgn;
		rgn.CreateRoundRectRgn( 0, 0,r.right , r.bottom, 20,20 ); ;
		SetWindowRgn(rgn,TRUE);
		PostMessage(WM_ERASEBKGND);
		sort();
		statflag=0;
	}
}

void CNcDlg::OnMin() 
{
	
	OnSysCommand(SC_MINIMIZE, 0x0000);//hide the main window
	
}

void CNcDlg::OnClose() 
{
	DestroyWindow();
	//	Shell_NotifyIcon(NIM_DELETE, &nd);
}

BOOL CNcDlg::DestroyWindow() 
{
	Shell_NotifyIcon(NIM_DELETE, &nd);
	return CDialog::DestroyWindow();
}


void CNcDlg::OnMute()
{
	if(m_mute.m_bHasChanged)
	{
		m_volume.EnableWindow(FALSE);
	}
	else
		m_volume.EnableWindow(TRUE);
}

void CNcDlg::OnPlayMusic() 
{//中止正在进行的播放
	if (mp.MCIIsPlaying())
	{
		mp.MCIStop();
		mp.MCIClose();
		m_btplay.m_musicplaying=FALSE;
		return;
	}
	if(m_listflag != 2)
	{
		m_btplay.m_bHasChanged=FALSE;
		return;
	}
	LVITEM m_item;
	if(m_SkinList.GetItemCount() <1)
	{
		m_btplay.m_bHasChanged=FALSE;
		m_btplay.Invalidate();
		//MessageBox("未找到音乐文件","错误",MB_OK);
		return;
	}
	if(m_SkinList.GetSelectedCount() <1)
	{
		m_btplay.m_bHasChanged=FALSE;
		m_btplay.Invalidate();
		//MessageBox("请选择音乐文件","错误",MB_OK);
		return;
	}
	
	m_SkinList.GetItem(&m_item);
	playmusic();
	m_musicflag=1;
	m_btplay.m_musicplaying=TRUE;
	//	m_btplay.m_bHasChanged=FALSE;
	//return;
}
void CNcDlg::playmusic()
{
	char tmp[MAX_PATH] ;
	char tmp2[MAX_PATH] ;
	if (mp.MCIIsPlaying())
	{
		mp.MCIStop();
		mp.MCIClose();
		return;
	}
	CString m_filename;
	int k=m_SkinList.GetSelectionMark();
	m_filename=m_SkinList.GetItemText(k,0);
	CNcFolder fld;
	HRESULT hr;
	//TCHAR realname[MAX_PATH];
	TCHAR WindowTemp[]=_T("\\temp");
	TCHAR szWindowsPath[MAX_PATH];
	//IOSFd ncf;
	
	::GetWindowsDirectory(szWindowsPath,MAX_PATH);
	_tcscat(szWindowsPath,WindowTemp);
	playingmusicname=m_filename;
	sprintf(tmp,"%s\\%s",szWindowsPath,m_filename);
	sprintf(tmp2,"%s\\%s",szWindowsPath,m_filename);
	
	WIN32_FIND_DATA fd;
	if(FindFirstFile(tmp,&fd)==INVALID_HANDLE_VALUE)
	{
		if(fld.OpenDevice()==E_FAIL)
		{
			MessageBox("连接聚乐卡失败，请检查USB连接是否正常!","错误",MB_OK);
			return;
		}
		//文件被删除了，告警，并刷新文件列表
		if(fld.GetNCFile(m_filename,2)!=S_OK)
		{
			MessageBox("文件不存在，可能已被删除","错误",MB_OK);
			getlistinfo(m_listflag);
			m_btplay.m_bHasChanged=FALSE;
			m_btplay.Invalidate();
			return;
		}
		
		hr=fld.CloseDevice();
	}	
	if(m_filename.Right(4)!=".mp3")//加扩展名
	{
		strcat(tmp,".mp3");	
		rename(tmp2,tmp);
	}
	if(mp.MCIIsPlaying())	
		mp.MCIClose();	
	mp.MCIOpen(tmp);
	if (!mp.MCIIsOpened())
	{	
		return;
	}		
	if (!mp.MCIIsPlaying())
		if (mp.MCIIsOpened())
			mp.MCIPlay();
		//	if (mp.MCIIsPlaying())	{MessageBox("music playing now!");}
}


void CNcDlg::getdefpath()
{
	char DirSpec[MAX_PATH];
	::SetCurrentDirectory((LPCSTR)DirSpec);
	::GetCurrentDirectory(MAX_PATH,(LPTSTR)(LPCTSTR)DirSpec);
	strcpy(m_DefPath,DirSpec);
}

void CNcDlg::OnListPicture() 
{
	if(m_listflag==3)
		return;
	else
	{
		if(m_listflag==1)//book
		{
			m_btebook.m_bHasChanged=FALSE;
			m_btebook.Invalidate();
		}
		if(m_listflag==2)//music
		{
			m_btmusic.m_bHasChanged=FALSE;
			m_btmusic.Invalidate();
		}
		m_listflag=3;
	}
	
	if (mp.MCIIsPlaying())
	{
		m_btplay.m_bHasChanged=FALSE;
		mp.MCIStop();
		mp.MCIClose();
	}
	SetButtonStatus(FALSE);
	if (getlistinfo(m_listflag)==E_FAIL)
	{
		return;
	}
	ShowCardSpace();
	
}
void CNcDlg::OnListMusic() 
{
	if(m_listflag==2)
		return;
	else
	{
		if(m_listflag==1)//book
		{
			m_btebook.m_bHasChanged=FALSE;
			m_btebook.Invalidate();
		}
		if(m_listflag==3)//music
		{
			m_btpicture.m_bHasChanged=FALSE;
			m_btpicture.Invalidate();
		}
		m_listflag=2;
	}
	
	if (getlistinfo(m_listflag)==E_FAIL)
	{
		return;
	}
	
	SetButtonStatus(TRUE);
	ShowCardSpace();
}
void CNcDlg::OnListBook() 
{
	
	if(m_listflag==1)
		return;
	else
	{
		if(m_listflag==3)//photo
		{
			m_btpicture.m_bHasChanged=FALSE;
			m_btpicture.Invalidate();
		}
		if(m_listflag==2)//music
		{
			m_btmusic.m_bHasChanged=FALSE;
			m_btmusic.Invalidate();
		}
		
		m_listflag=1;
	}
	
	if (mp.MCIIsPlaying())
	{
		mp.MCIStop();
		mp.MCIClose();
		m_btplay.m_bHasChanged=FALSE;
	}
	
	SetButtonStatus(FALSE);
	if (getlistinfo(m_listflag)==E_FAIL)
	{
		//MessageBox("连接聚乐卡失败!","错误",MB_OK);
		return;
	}
	ShowCardSpace();	
}

HRESULT CheckFileType(CString filename,int type)
{
	
	if(type == 1 ) //book	
	{
		CString tmpstr =filename.Right(3);
		char tmp[5];
		strcpy(tmp,tmpstr);
		tmpstr = strlwr(tmp);
		if(tmpstr != "txt")
		{
			//MessageBox(NULL,"不是系统支持的电子书格式，请重新选择文件","错误...",MB_OK);
			return E_FAIL;
		}
		else
			return S_OK;
		
	}
	if(type == 2 )//music
	{
		CString tmpstr =filename.Right(3);
		char tmp[5];
		strcpy(tmp,tmpstr);
		tmpstr = strlwr(tmp);
		if((tmpstr == "mp3") || (tmpstr == "wav"))
		{
			return S_OK;
		}	
		else
		{
			//MessageBox(NULL,"不是系统支持的音乐格式，请重新选择文件","错误...",MB_OK);
			return E_FAIL;
		}
	}
	
	if(type == 3 )//photo
	{
		CString tmpstr =filename.Right(3);
		char tmp[5];
		strcpy(tmp,tmpstr);
		tmpstr = strlwr(tmp);
		if((tmpstr == "bmp") || (tmpstr == "jpg") || \
			(tmpstr==_T("gif"))|| (tmpstr == "png")|| \
			(tmpstr==_T("ico"))|| (tmpstr==_T("pcx"))|| \
			(tmpstr==_T("ppm")))	
			return S_OK;
		else
		{
			//MessageBox(NULL,"不是系统支持的图片格式，请重新选择文件","错误...",MB_OK);
			return E_FAIL;
		}
		
	}
	
}
void CNcDlg::OnAddFile() 
{
	CString strFileName;
	HRESULT hr;
	CNcFolder fld;
	//HRESULT hr;
	if(fld.OpenDevice()==E_FAIL)
	{
		//MessageBox("连接聚乐卡失败，请检查USB连接是否正常!","Warring",MB_OK);
		return;
	}
	if(m_listflag<1)
	{
		MessageBox("请选择文件类型","警告",MB_OK);
		return;
	}
	CString ftype;
	if(m_listflag == 1)
		ftype="文本文件 (.txt)|*.txt|";
	else if(m_listflag == 2)
		ftype="音乐文件(*.mp3;*.wav;*.raw;*.au;*.aiff;*.dat;*.cdr;*.avr;*.vms;*.hcom;*.voc;*.vox;*.wve;*.sf;*.maud;*.txw)|*.mp3;*.wav;*.raw;*.au;*.aiff||";
	else if(m_listflag == 3)
		ftype="图片文件 (*.bmp;*.jpg;*.gif;*.png;*.ico;*.iff;*.pcd;*.tiff;*.psd;*.jng;*.lbm;*.mng;*.pbm;*.pcx;*.pgm;*.ppm;*.ras;*.cut;*.xbm;*.xpm;*.dds;*.hdr)|*.bmp;*.jpg;*.gif;*.png;*.ico;*.tiff||";
	else
		return;
	DWORD dwVersion,dwWindowsMajorVersion,dwWindowsMinorVersion; 
	
	//检测目前的操作系统，GetVersion具体用法详见MSDN 
	dwVersion = GetVersion(); 
	dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); 
	dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); 
	
	
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,_T(ftype),NULL);
	DWORD MAXFILE = 16384; // allocate enough memory space
	dlg.m_ofn.nMaxFile = MAXFILE; // set the buffer size
	char* buf = new char[MAXFILE];
	
	// 如果运行的操作系统是Windows NT/2000 
	if (dwVersion < 0x80000000) 
		dlg.m_ofn.lStructSize =88;//显示新的文件对话框 
	else 
		//运行的操作系统Windows 95/98 
	dlg.m_ofn.lStructSize =76;//显示老的文件对话框* /
	
	dlg.m_ofn.lpstrInitialDir = "c:\\";		//缺省为c盘	
	dlg.m_ofn.lpstrFile = buf;
	dlg.m_ofn.lpstrFile[0] = NULL; 
	int iReturn = dlg.DoModal();
	m_SkinList.Invalidate();
	
	if(iReturn == IDOK)
	{
		POSITION pos = dlg.GetStartPosition();
		while (pos != NULL)
		{
			strFileName=dlg.GetNextPathName(pos); // get the individual file name
			//	HRESULT hrr = CheckFileType(strFileName,m_listflag);
			if(CheckFileType(strFileName,m_listflag)==E_FAIL)//check filetype
			{
				CString ftype;
				if(m_listflag == 1)
					ftype="不支持的电子书格式,请重新选择文件！";
				if(m_listflag == 2)
					ftype="不支持的音乐格式,请重新选择文件！";
				if(m_listflag == 3)
					ftype="不支持的照片格式,请重新选择文件！";
				MessageBox(ftype,"错误",MB_OK);
				return;
			}
			if(fld.AddFile(strFileName,m_listflag) !=S_OK)
				break;
			
			getlistinfo(m_listflag);
			ShowCardSpace();
			m_SkinList.Invalidate();
			/*	if(getlistinfo(m_listflag)==E_FAIL)
			{
			MessageBox("连接聚乐卡失败!","错误",MB_OK);
			return;
			}
			*/		//	ShowCardSpace();
		}
		delete [] buf;
	}
	else 
	{
		m_btback.Invalidate();
		m_btnext.Invalidate();
		return;
	}
	delete [] dlg.m_ofn.lpstrFile;//release mem
	hr=getlistinfo(m_listflag);

	if (hr==E_FAIL)
	{
		//MessageBox("连接聚乐卡失败!","错误",MB_OK);
		return;
	}
	hr=ShowCardSpace();
	hr = fld.CloseDevice();
	Invalidate();
	
}

void CNcDlg::OnDelFile() 
{	
	/*	
	SetSkin("D:\\skin07\\nc\\skin\\skin.ini");
	m_freespace.SetWindowText("红色皮肤");
	Invalidate();
*/
	int selcnt=0;
	if(selcnt=m_SkinList.GetSelectedCount(),selcnt <1)
	{
		MessageBox("请选择需要删除的文件!","提示",MB_ICONINFORMATION);
		return;
	}
	
	CFlgDel dlg;
	if(dlg.DoModal()!=IDOK)//确认删除文件
		return;
	
	CNcFolder fld;
	HRESULT hr;
	CString m_filename;
	
	if(fld.OpenDevice() == E_FAIL)
	{
		MessageBox("连接聚乐卡失败，请检查USB连接是否正常!","错误",MB_OK);
		return;
	}
	POSITION pos = m_SkinList.GetFirstSelectedItemPosition();
	//int m_nIndex = m_SkinList.GetNextSelectedItem(pos); // 得到项目索引
	for (int k=0;k<selcnt;k++)
	{
		//delete selected line,and move focus to next line
		//m_filename=m_SkinList.GetItemText(m_SkinList.GetSelectionMark(),0);
		m_filename=m_SkinList.GetItemText(m_SkinList.GetSelectionMark(),0);
		//如删除当前文件，则停止播放
		if(playingmusicname==m_filename)
		{
			if (mp.MCIIsPlaying())
			{
				mp.MCIStop();
				mp.MCIClose();
				//按钮状态复位
				m_btplay.m_bHasChanged=FALSE;
				m_btplay.Invalidate();
			}
		}
		
		hr =fld.DelFile(m_filename,m_listflag);
		if(hr==E_FAIL)
		{
			MessageBox(m_filename+"不存在，可能已删除","错误",MB_OK);
			//m_filename.Empty();
			break;
		}
		
		if(hr==S_OK)
		{
			m_SkinList.DeleteItem(m_SkinList.GetSelectionMark());
			m_SkinList.SetItemState(m_SkinList.GetSelectionMark(),LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
			m_SkinList.Invalidate();
		}
		else
		{
			MessageBox(_T("删除文件失败！文件正在使用"),_T("发生异常..."),MB_OK);
			continue;
		}	
		m_SkinList.GetNextSelectedItem(pos);
	}
	hr=fld.CloseDevice();
	
	if (getlistinfo(m_listflag)==E_FAIL)
	{
		//MessageBox("连接聚乐卡失败!","错误",MB_OK);
		return;
	}
	ShowCardSpace();
	Invalidate();
}

void CNcDlg::OnRefreshList() 
{
//	m_volume.LoadSliderSkin("D:\\here\\nc\\skinblue\\blue.ini");
	/*
	CRect  rc;
	m_volume.GetClientRect(&rc);
		m_volume.InvalidateRect(&rc);*/
	//	m_volume.Invalidate(FALSE);
	//	m_volume.UpdateWindow();
	//m_volume.ShowWindow(SW_HIDE);	
	//m_volume.ShowWindow(SW_SHOWNORMAL);
	//m_volume.OnDrawItem()
	//m_volume.Invalidate();
	//::SendMessage(GetDlgItem(IDC_VOLUME)->m_hWnd,NM_CUSTOMDRAW,   0,   0);  
	//m_volume.RedrawWindow();
	//m_volume.ModifyStyle(TBS_ENABLESELRANGE,0,0);   
	//m_volume.Invalidate();
/*	change skin	 test code
	SetSkin("D:\\skin07\\nc\\skinblue\\blue.ini");
	m_freespace.SetWindowText("蓝色皮肤");
	Invalidate();

*/
	if(getlistinfo(m_listflag)==E_FAIL)
	{
		MessageBox("连接聚乐卡失败!","错误",MB_OK);
		return;
	}
	ShowCardSpace();
	Invalidate();
	
}
HRESULT CNcDlg::getlistinfo(int datatype)
{
	
	CNcFolder fld;
	ISFSError err;
	int DataType=0;
	if(!mediaFsOpened())
	{
		if(fld.OpenDevice()==E_FAIL)
			return E_FAIL;
	}
	//m_SkinList.DeleteAllItems();
	TCHAR szSubVol[MAXNAMELEN+1];
	char FileType[32];

	switch(m_listflag)
	{
	case 1:
		strcpy(szSubVol,_T("book"));
		_tcscpy(FileType,_T("电子书"));
		break;
	case 2:
		strcpy(szSubVol,_T("music"));
		_tcscpy(FileType,_T("音乐"));
		break;
	default:
		strcpy(szSubVol,_T("photo"));
		_tcscpy(FileType,_T("图片"));
		break;
	}
	TCHAR szBuf[MAX_TOTAL_SIZE];
	TCHAR * pData;
	ncfileinfo *finfo;
	finfo=(ncfileinfo *)malloc(sizeof(ncfileinfo ));
	int num;
	
	memset(szBuf,0,sizeof(TCHAR)*MAX_TOTAL_SIZE);
	if(mediaFsOpened())
		err=ISFS_ReadDir((const u8*)szSubVol,NULL, (u32*)&num);
	if(num>0)
		err=ISFS_ReadDir((const u8*)szSubVol,(u8*)szBuf, (u32*)&num);
	if(err<0)
	{
		ATLTRACE(_T("Error: _CountFilesInFolder() read directory info failed!\r\n"));
		return E_FAIL;
	}
	pData=szBuf;
	if(num>0)
	{
		m_SkinList.DeleteAllItems();
		for(int i=0;i<num;i++)
		{
			TCHAR szFileName[MAXNAMELEN];
			memset(szFileName,0,sizeof(TCHAR)*MAXNAMELEN);
			_tcscpy(szFileName,pData);
			if( _tcscmp(szFileName, _T("."))==0 ) 
				continue;
			if( _tcscmp(szFileName, _T(".."))==0 ) 
				continue;
			TCHAR szSrcFile[MAX_PATH];
			::wsprintf(szSrcFile, _T("%s/%s"), szSubVol, szFileName);
			
			IOSFd hFile=ISFS_Open((const u8*)szSrcFile, ISFS_READ_ACCESS);
			if(hFile<0)
			{
				if(mediaFsOpened())
					mediaFsClose();
				return E_FAIL;
			}
			
			fld.GetDisplayNameOf(hFile, finfo,datatype);
			err=ISFS_Close(hFile);
			if(err<0)
			{
				if(mediaFsOpened())
					mediaFsClose();
				return E_FAIL;
			}
			//insert info into  listctrl
			char filesize[15];
			sprintf(filesize,"%d",finfo->filesize);
			m_SkinList.InsertItem(i, finfo->filename);
			m_SkinList.SetItemText(i, 1, finfo->filename);
			m_SkinList.SetItemText(i, 2, filesize);
			m_SkinList.SetItemText(i,3, FileType);
			//m_SkinList.SetItemText(i, 4, timebuf);
			
			while(*pData!=0)
			{
				pData=::CharNext(pData);
			}
			*pData=_T('e');  //replace the EOF with 'e' , so the next CharNext() calling will work.
			pData=::CharNext(pData);
		}
	}
	else
	{
		m_SkinList.DeleteAllItems();
		m_SkinList.InsertItem(0,"a");
		m_SkinList.Invalidate();
	}
	
	return S_OK;
}
void CNcDlg::OnNextFile() 
{
	if(m_SkinList.GetSelectionMark() < m_SkinList.GetItemCount()-1)
	{
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark(),0,  LVIS_SELECTED);
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark()+1,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
		m_SkinList.SetSelectionMark(m_SkinList.GetSelectionMark()+1);
	}
	else
	{
		m_SkinList.SetItemState(m_SkinList.GetSelectionMark(),0,  LVIS_SELECTED);
		m_SkinList.SetItemState(0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
		m_SkinList.SetSelectionMark(0);
	}
	if(m_listflag =2 )
	{
		if (mp.MCIIsPlaying())
		{
			mp.MCIStop();
			mp.MCIClose();
			LVITEM m_item;
			m_SkinList.GetItem(&m_item);
			playmusic();
		}
		
	}
	
}
void CNcDlg::CheckNC()
{
	CNcFolder fld;
	if(!mediaFsOpened() && (checkncflag==0))
	{
		if(mediaFsOpen("127.0.0.1", 20081)<0)
		{
			if(MessageBox("未检测到连接的iQue聚乐卡,中止程序或者重试？","错误",MB_ABORTRETRYIGNORE   |MB_ICONQUESTION)==3)
			{	
				checkncflag=1;
				exit(0);
			}
			else
			{
				checkncflag=0;
				return;
			}
		}
		char devCurVol[32];
		strcpy(devCurVol,"book");
		int numEntries;
		if(ISFS_ReadDir((const u8*)devCurVol,NULL,(u32*)&numEntries)!=ISFS_ERROR_OK)
		{
			TRACE("open device failed");
			if(MessageBox("未检测到连接的iQue聚乐卡,中止程序或者重试？","错误",MB_ABORTRETRYIGNORE   |MB_ICONQUESTION)==3)
			{	
				checkncflag=1;
				exit(0);
			}
			else
			{
				checkncflag=0;
				return;
			}
		
		}
	}
}
void CNcDlg::OnTimer(UINT nIDEvent) 
{
	CDialog::OnTimer(nIDEvent);
	if(nIDEvent == 3)
	{
		m_freespace.Invalidate(FALSE);
		if(m_musicflag==1)
		{
			if(!mp.MCIIsPlaying())
			{
				m_btplay.m_bHasChanged=FALSE;
				m_btplay.Invalidate(TRUE);
				m_musicflag=0;
				//mp.MCIStop();
				//mp.MCIClose();
				//return;
			}
		}
		
		//m_btebook.Invalidate(FALSE);
		//m_volume.Invalidate(FALSE);
		//m_cardspace.Invalidate(FALSE);
		//m_btplay.Invalidate(FALSE);
		//m_btmax.Invalidate(FALSE);
	}
	if(nIDEvent == 2)
	{
		//getlistinfo(m_listflag);
		CheckNC();
	}
	
}

HRESULT CNcDlg::ShowCardSpace()
{
	int pos;
	ISFSStats stats;
	CNcFolder fld;
	char freespace[32];
	//HRESULT hr=;
	if(!mediaFsOpened())
	{
		if (fld.OpenDevice()==E_FAIL)
		{
			return E_FAIL;
		}
	}
	
	ISFSError err =ISFS_GetStats(&stats);
	if(err<0)
	{
		ATLTRACE(_T("Error: ISFS_EOF read file state failed!\r\n"));
		return E_FAIL;
	}
	pos=(int)(100*(stats.occupiedBlocks+256)/(stats.occupiedBlocks +stats.freeBlocks));//游工部保留4M不可用,不体现出来
	m_cardspace.SetPos(pos);
	m_cardspace.StepIt();
	
	sprintf(freespace,"聚乐卡剩余%dM空间",stats.freeBlocks*16/1024 -4);//游工部保留4M不可用
	m_freespace.SetWindowText(freespace);	
	//redraw control
	HWND m_vol;
	GetDlgItem(IDC_VOLUME,&m_vol);
	::SendMessage(m_vol, WM_MOUSELEAVE , TRUE, 0L);
	HWND m_but;
	GetDlgItem(IDC_BUTTON6,&m_but);
	::SendMessage(m_but, BN_CLICKED, TRUE, 0L);
	HWND m_spc;
	GetDlgItem(IDC_CARD_SPACE,&m_spc);
	::SendMessage(m_spc, WM_SETREDRAW, TRUE, 0L);
	//	fld.CloseDevice();
	return S_OK;
}
BOOL CNcDlg::OnMouseMove(UINT nFlags, CPoint pt) 
{
	redrawsomepart();
	return TRUE;
	
}
BOOL CNcDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}

void CNcDlg::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	//	redrawsomepart();
	m_btplay.Invalidate();
	m_btnext.Invalidate();
	m_btback.Invalidate();
	m_btebook.Invalidate();
	m_volume.Invalidate();
	m_cardspace.Invalidate();
	return;
}

void CNcDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();
}

void CNcDlg::OnKillFocus(CWnd* pNewWnd) 
{
	CDialog::OnKillFocus(pNewWnd);
}
void CNcDlg::OnDropFiles(HDROP hDropInfo)
{
	char   szFilePathName[_MAX_PATH+1] = {0};
	CNcFolder fld;
	HRESULT hr;
	if(fld.OpenDevice()==E_FAIL)
	{
		MessageBox("连接聚乐卡失败，请检查USB连接是否正常!","发生错误",MB_OK);
		return;
	}
	UINT  nNumOfFiles = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0); //得到文件个数
	
    for (UINT nIndex=0 ; nIndex< nNumOfFiles; ++nIndex)
    {
        DragQueryFile(hDropInfo, nIndex, szFilePathName, _MAX_PATH);  //得到文件名
		if(CheckFileType(szFilePathName,m_listflag)==E_FAIL)//check filetype
		{
			
			CString ftype;
			if(m_listflag == 1)
				ftype="不支持的电子书格式";
			if(m_listflag == 2)
				ftype="不支持的音乐格式";
			if(m_listflag == 3)
				ftype="不支持的图片格式";
			MessageBox(ftype,"错误",MB_OK);
			continue;
		}
		//---------->
		
		hr=fld.AddFile(szFilePathName,m_listflag);
		getlistinfo(m_listflag);
		ShowCardSpace();
		
		//<----------
    }
	hr=fld.CloseDevice();
	//OnRefreshList();
    DragFinish(hDropInfo);
}
void CNcDlg::OnDBclickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	if(m_listflag != 2)//only work for music
		return;
	if(m_SkinList.GetSelectedCount() ==0)
		return;
	if (mp.MCIIsPlaying())
	{
		mp.MCIStop();
		mp.MCIClose();
		LVITEM m_item;
		m_SkinList.GetItem(&m_item);
		playmusic();
	}
	else
	{
		m_btplay.SendMessage(WM_LBUTTONDOWN);
		m_btplay.SendMessage(WM_LBUTTONUP);
		m_btplay.SendMessage(WM_KILLFOCUS);
		m_btplay.m_bHasChanged=TRUE;
	}
	
	return;
}
void CNcDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CMenu menu;
	CPoint point= (0,0);
	GetCursorPos(&point);
	menu.LoadMenu(IDR_LIST_POP);
	CMenu *pPopup=menu.GetSubMenu(0);
	
	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,this);
	
}

BOOL CNcDlg::PreTranslateMessage(MSG* pMsg) 
{
	// CG: The following block was added by the ToolTips component.
	{
		// Let the ToolTip process this message.
		m_tooltip.RelayEvent(pMsg);
	}
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->wParam==VK_ESCAPE)//
	{
		return TRUE;
	}
	if(pMsg->wParam==VK_RETURN)//
	{
		return TRUE;
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}
void CNcDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);
	
	// TODO: Add your message handler code here
	
}
void CAboutDlg::OnOK() 
{
	// TODO: Add extra validation here
	CDialog::OnOK();
}
void CNcDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	m_volume.m_VControl.SetValue( m_volume.GetPos(),m_volume.GetPos());
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CNcDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

