back to www.audiodesignguide.com


the Player        
(look part 1 on thePlayer.html)

I also have develop a custom software to use like Player in any conditions and able to play any music and video format compatible with Windows Media Player 10.0 and also the types compatible adding a Codec like the TTA.

To download the last version of this software [CLICK HERE].

 

This player has been develop using Microsoft Visual Studio 6.0 and Windows Media Player SDK 10.

The WMP SDK allow to create custom skins and visualizations, embed the Player in Web pages and custom applications like my player.

 

The TR3000 have enough performances to play also DVD and DIVX so I have installed this coded:

and off course the True Audio Plugins Pack to play my music.


Click here to see the source code of my player

//******************************************************************************
//* Incudes
//******************************************************************************
#include "stdafx.h"
#include <windows.h>
#include <oledlg.h>
#include "wmp.h"
#include <comutil.h>
#include <commctrl.h>


//******************************************************************************
//* WMP Interface
//******************************************************************************
CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

CComPtr<IWMPPlayer>         	m_spWMPPlayer;
CComPtr<IWMPSettings>         	m_spWMPSettings;
CComPtr<IWMPControls>         	m_spWMPControls;
CComPtr<IWMPPlayer2>         	m_spWMPPlayer2;
CComPtr<IWMPControls3>         	m_spWMPControls3;

//************ DVD interface ****************
CComPtr<IWMPCore2>         	m_spWMPCore2;
CComPtr<IWMPDVD>  		spDVD;

CAxWindow  m_wndView;  // ActiveX host window class.


//******************************************************************************
//* Functions define
//******************************************************************************
int     InsertTree(HWND hTreeView);
int     LoadImage(HWND hTreeView);
int     InsertTreeItem(HWND hTreeView, HTREEITEM hParent, char * buffer, int icon);
int     GetDrivesList();
int     GetList(HTREEITEM hParent, char * path);
int     PlayMusic(char * path);
int     check_extension(char * filename);
int     LoadDevicesList(HWND hListBox);
int     MixerOpen(HWND hMain, HINSTANCE hinstance);
int     MixerLoadValue(HWND D, HWND H, HWND N);
int     MixerSetValue(float fVal, DWORD comp);
HFONT   Set_Font (char *Font,int Size,int Bold,int Italic,int Underline,int StrikeThru);
int     CreateTitle(HWND hMain, HINSTANCE hinstance);
int     UpdateTitle();
int     CreateJog(HWND hMain, HINSTANCE hinstance);
int     ChangeButton(LPDRAWITEMSTRUCT lpdis, HBITMAP hButton, HBITMAP hButtonSel, int w, int h);
int     open_mixer();
int     set_mixer(DWORD ComponentType);
int     set_mixer_value(long lval);
int     get_mixer_value(long * lVal);
int     OpenWMP(HWND hwnd);
int 	TreeNavigation(int op);
int 	Loadlanguage();
int     LoadRate();
int	ShowAll();
int 	ChangeProc();

LRESULT APIENTRY WmpWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
LRESULT APIENTRY ButtonProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT APIENTRY TreeProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

WNDPROC wpOrigWmpProc;
WNDPROC wpOrigEditProc;
WNDPROC wpOrigButtonProc;
WNDPROC wpOrigTreeProc;
// FARPROC wpOrigEditProc;
// FARPROC wpOrigWmpProc;


//******************************************************************************
//* Global variables
//******************************************************************************
int    flag_fullview = 0;
int    flag_playing = 0;
long   WMPvol;
float  MASvol;
float  WAVvol;
double rates[20] = { 0.5, 1.0, 2.0, 4.0, 5.0, 10.0, -1 };

HINSTANCE hinst;

HWND hWMP, hDevice, hJog, hMain, hTaskBar, hLanguage, hRate, hTreeView, hTime, hTitle,
     hButtonWmpInc, hButtonMasInc, hButtonWavInc, hButtonWmpDec, hButtonMasDec, hButtonWavDec,
     hEditWmpVal, hEditMasVal, hEditWavVal,
     ButtonUp, ButtonDown, ButtonRight, ButtonLeft, ButtonCenter, hButtonFullLev,
     ButtonForward, ButtonReverse, ButtonTopMenu, ButtonTitMenu, ButtonLang, ButtonRate;


//******************************************************************************
//* Global define
//******************************************************************************
#define WIN_WIDTH         800
#define WIN_HEIGHT        570

#define JOG_QUAD_SIZE	   80
#define JOG_SHIFT	    0
#define JOG_ORIG_Y	  275
#define JOG_ORIG_X	   14

#define ICON_FOLDER	    0
#define ICON_MUSIC	    1
#define ICON_HARDDISK	    2
#define ICON_NETWORK	    3
#define ICON_CDROM	    4
#define ICON_FLOPPY	    5

#define BUTTON_MAS_INC    101
#define BUTTON_MAS_DEC    102
#define BUTTON_WAV_INC    103
#define BUTTON_WAV_DEC    104
#define BUTTON_WMP_INC    105
#define BUTTON_WMP_DEC    106
#define VALUE_WMP 	  107
#define VALUE_MAS   	  108
#define VALUE_WAV   	  109
#define TITLE   	  110
#define VALUE_TIME   	  111
#define EV_BUTTONRIGHT    112
#define EV_BUTTONLEFT     113
#define EV_BUTTONUP       114
#define EV_BUTTONDOWN     115
#define EV_BUTTONCENTER   116
#define EV_BUTTONFORWARD  117
#define EV_BUTTONREVERSE  118
#define VALUE_DEBUG   	  119
#define EV_BUTTONTOPMENU  120
#define EV_BUTTONTITMENU  121
#define IDL_RATE 	  122
#define EV_BUTTONLANG     123
#define EV_BUTTONRATE     124
#define BUTTON_FULL_LEV   125

#define MAX_STRING       1024


//******************************************************************************
//* Mixer control
//******************************************************************************
#if !defined(AFX_STDAFX_H__39694509_F4A0_11D1_9F80_006008984DF6__INCLUDED_)

#define AFX_STDAFX_H__39694509_F4A0_11D1_9F80_006008984DF6__INCLUDED_

#include <mmsystem.h>

#endif 

DWORD  m_dwControlID;
HMIXER m_hMixer;


//******************************************************************************
// Bitmaps
//******************************************************************************
HBITMAP       hBitmapButtonUp;
HBITMAP       hBitmapButtonUpSel;
HBITMAP       hBitmapButtonDown;
HBITMAP       hBitmapButtonDownSel;
HBITMAP       hBitmapButtonRight;
HBITMAP       hBitmapButtonRightSel;
HBITMAP       hBitmapButtonLeft;
HBITMAP       hBitmapButtonLeftSel;
HBITMAP       hBitmapButtonCenter;
HBITMAP       hBitmapButtonCenterSel;
HBITMAP       hBitmapButtonForward;
HBITMAP       hBitmapButtonForwardSel;
HBITMAP       hBitmapButtonReverse;
HBITMAP       hBitmapButtonReverseSel;
//******************************************************************************


bool FAILMSG(HRESULT hr)
{
    if (FAILED(hr))
    {
        TCHAR   szError[MAX_STRING];

        ::wsprintf(szError, _T("Error code = %08X"), hr);
        ::MessageBox(NULL, szError, _T("Error"), MB_OK | MB_ICONERROR);
    }

    return FAILED(hr);
}



int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                                  LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    WNDCLASS wc;
    int idTimer = -1;

    
    CoInitialize(0);

    _Module.Init( ObjectMap, hinstance, &LIBID_ATLLib );
    
    hinst = hinstance;

    wc.style         = 0 ;
    wc.lpfnWndProc   = MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = NULL;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = CreateSolidBrush(RGB(128,128, 128));
    wc.lpszMenuName  =  NULL;
    wc.lpszClassName = "MaWinClass";

    if(!RegisterClass(&wc)) return FALSE;

 
    hMain = CreateWindow("MaWinClass", 
			   "Hi-end Audio/Video Player version 2.0 beta 2005 by A. Ciuffoli",
			   WS_OVERLAPPEDWINDOW|WS_VISIBLE,
			   // WS_VISIBLE|WS_EX_CLIENTEDGE|WS_EX_TOOLWINDOW,
			   CW_USEDEFAULT,
			   CW_USEDEFAULT,
			   WIN_WIDTH,
			   WIN_HEIGHT,       
			   NULL,
			   NULL,
			   hinstance,
			   NULL);

    MoveWindow(hMain, 0, 0, WIN_WIDTH, WIN_HEIGHT, TRUE);

    hTreeView = CreateWindowEx(0 ,WC_TREEVIEW , "TV View" ,
			   WS_CHILD |
			   WS_BORDER |
			   WS_VSCROLL |
			   WS_HSCROLL |
			   TVS_HASLINES |
			   TVS_LINESATROOT |
			   TVS_HASBUTTONS  |
			   TVS_SHOWSELALWAYS |
			   TVS_SINGLEEXPAND ,
			   10,
			   10,
			   WIN_WIDTH / 2 - 10,
			   250,
			   hMain,
			   NULL, hinstance, NULL);

    hTime = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","00:00",
			   WS_CHILD |
			   ES_READONLY |
			   ES_CENTER |
			   ES_NOHIDESEL,
			   210,
			   490,
			   73,
			   20,
			   hMain,
			   (HMENU)VALUE_TIME,
			   hinstance,
			   NULL);

    hDevice = CreateWindowEx(0 ,"Listbox" , "TV View" ,
			   WS_CHILD |
			   WS_BORDER |
			   WS_VSCROLL  |
			   WS_TABSTOP,
			   WIN_WIDTH / 2 + 10 + 4,
			   270 + 20,
			   WIN_WIDTH / 2 - 90,
			   20,
			   hMain,
			   NULL, hinstance, NULL);

    hLanguage = CreateWindowEx(0 ,"Listbox" , "Language" ,
			   WS_CHILD |
			   WS_BORDER |
			   WS_VSCROLL  |
			   WS_TABSTOP,
			   WIN_WIDTH / 2 + 10 + 5 + 170,
			   320 + 4,
			   180,
			   20,
			   hMain,
			   NULL, hinstance, NULL);

    hRate = CreateWindowEx(0 ,"Listbox" , "rate" ,
			   WS_CHILD |
			   WS_BORDER |
			   WS_VSCROLL  |
			   WS_TABSTOP,
			   210,
			   458,
			   50,
			   20,
			   hMain,
			   (HMENU)IDL_RATE, hinstance, NULL);

    ButtonTopMenu = CreateWindow("BUTTON","top m.",
			   WS_CHILD|
			   BS_DEFPUSHBUTTON,
			   WIN_WIDTH / 2 + 10 + 5,
			   320 + 4 + 20,
			   60,
			   20,
			   hMain,
			   (HMENU)EV_BUTTONTOPMENU,hinstance, NULL);

    ButtonRate = CreateWindow("BUTTON","R",
			   WS_CHILD|
			   BS_DEFPUSHBUTTON,
			   265,
			   458,
			   20,
			   20,
			   hMain,
			   (HMENU)EV_BUTTONRATE,hinstance, NULL);

    ButtonTitMenu = CreateWindow("BUTTON","title",
			   WS_CHILD|
			   BS_DEFPUSHBUTTON,
			   WIN_WIDTH / 2 + 10 + 5 + 70,
			   320 + 4 + 20,
			   60,
			   20,
			   hMain,
			   (HMENU)EV_BUTTONTITMENU,hinstance, NULL);

    ButtonLang = CreateWindow("BUTTON","language sel.",
			   WS_CHILD|
			   BS_DEFPUSHBUTTON,
			   WIN_WIDTH / 2 + 10 + 5 + 230,
			   320 + 4 + 20,
			   120,
			   20,
			   hMain,
			   (HMENU)EV_BUTTONLANG,hinstance, NULL);

    LoadImage(hTreeView);

    GetDrivesList();

    CreateJog(hMain, hinstance);

    CreateTitle(hMain, hinstance);

    OpenWMP(hMain);

    LoadRate();

    LoadDevicesList(hDevice);

    MixerOpen(hMain, hinstance);

    SetTimer(hMain, idTimer = 1, 1000, NULL); 
    
    ShowAll();

    ChangeProc();

    hinst = hinstance;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

int MixerOpen(HWND hMain, HINSTANCE hinstance)
{
#define MIXER_WAV_X	(WIN_WIDTH / 2 - 100)
#define MIXER_WAV_Y	(270)
#define MIXER_MAS_X	(WIN_WIDTH / 2 - 100)
#define MIXER_MAS_Y	(340)
#define MIXER_WMP_X	(WIN_WIDTH / 2 - 100)
#define MIXER_WMP_Y	(410)
#define MIXER_QUAD_SIZE	(22)
#define MIXER_TEXT_SIZE	(20)


    hButtonWavInc = CreateWindow("BUTTON","+",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_WAV_X + 3,
	    MIXER_WAV_Y + 20,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_WAV_INC,
	    hinstance,
	    NULL);

    hButtonWavDec = CreateWindow("BUTTON","-",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_WAV_X + 3,
	    MIXER_WAV_Y + 20 + MIXER_QUAD_SIZE + 1,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_WAV_DEC,
	    hinstance,
	    NULL);


    hEditWavVal = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","100",
	    WS_CHILD|ES_READONLY|ES_CENTER|ES_NUMBER|ES_NOHIDESEL,
	    MIXER_WAV_X + MIXER_QUAD_SIZE + 4,
	    MIXER_WAV_Y + 20,
	    70,
	    MIXER_QUAD_SIZE * 2,
	    hMain,
	    (HMENU)VALUE_WAV,
	    hinstance,
	    NULL);

    SendMessage(hEditWavVal,(UINT)WM_SETFONT,(WPARAM)Set_Font("Verdana",22,1,0,0,0),1);


    hButtonMasInc = CreateWindow("BUTTON","+",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_MAS_X + 3,
	    MIXER_MAS_Y + 20,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_MAS_INC,
	    hinstance,
	    NULL);

    hButtonMasDec = CreateWindow("BUTTON","-",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_MAS_X + 3,
	    MIXER_MAS_Y + 20 + MIXER_QUAD_SIZE + 1,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_MAS_DEC,
	    hinstance,
	    NULL);


    hEditMasVal = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","100",
	    WS_CHILD|ES_READONLY|ES_CENTER|ES_NUMBER|ES_NOHIDESEL,
	    MIXER_MAS_X + MIXER_QUAD_SIZE + 4,
	    MIXER_MAS_Y + 20,
	    70,
	    MIXER_QUAD_SIZE * 2,
	    hMain,
	    (HMENU)VALUE_MAS,
	    hinstance,
	    NULL);

    SendMessage(hEditMasVal,(UINT)WM_SETFONT,(WPARAM)Set_Font("Verdana",22,1,0,0,0),1);


    hButtonWmpInc = CreateWindow("BUTTON","+",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_WMP_X + 3,
	    MIXER_WMP_Y + 20,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_WMP_INC,
	    hinstance,
	    NULL);

    hButtonWmpDec = CreateWindow("BUTTON","-",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_WMP_X + 3,
	    MIXER_WMP_Y + 20 + MIXER_QUAD_SIZE + 1,
	    MIXER_QUAD_SIZE,
	    MIXER_QUAD_SIZE,
	    hMain,
	    (HMENU)BUTTON_WMP_DEC,
	    hinstance,
	    NULL);


    hEditWmpVal = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","100",
	    WS_CHILD|ES_READONLY|ES_CENTER|ES_NUMBER|ES_NOHIDESEL,
	    MIXER_WMP_X + MIXER_QUAD_SIZE + 4,
	    MIXER_WMP_Y + 20,
	    70,
	    MIXER_QUAD_SIZE * 2,
	    hMain,
	    (HMENU)VALUE_WMP,
	    hinstance,
	    NULL);

    SendMessage(hEditWmpVal,(UINT)WM_SETFONT,(WPARAM)Set_Font("Verdana",22,1,0,0,0),1);

    hButtonFullLev = CreateWindow("BUTTON","All Full",
	    WS_CHILD | BS_DEFPUSHBUTTON, // | WS_THICKFRAME,
	    MIXER_WMP_X + 3,
	    MIXER_WMP_Y + 75,
	    93,
	    30,
	    hMain,
	    (HMENU)BUTTON_FULL_LEV,
	    hinstance,
	    NULL);

    SendMessage(hButtonFullLev,(UINT)WM_SETFONT,(WPARAM)Set_Font("Verdana",16,1,0,0,0),1);

    MixerLoadValue(hEditWavVal,hEditMasVal,hEditWmpVal);

    return 0;
}

int MixerLoadValue(HWND D, HWND H, HWND N)
{
    char  tmp[200];
    long  lVal = 0;


    m_spWMPSettings->get_volume(&WMPvol);

    sprintf(tmp, "%d", WMPvol);

    SendMessage(N,(UINT)WM_SETTEXT,0, (WPARAM)tmp);



    open_mixer();

    set_mixer(MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);

    get_mixer_value(&lVal);

    WAVvol = (float)lVal;

    sprintf(tmp, "%3.0lf", (WAVvol / 65536) * 100);

    SendMessage(D,(UINT)WM_SETTEXT,0, (WPARAM)tmp);

    set_mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);

    get_mixer_value(&lVal);

    MASvol = (float)lVal;

    sprintf(tmp, "%3.0lf", (MASvol / 65536) * 100);

    SendMessage(H,(UINT)WM_SETTEXT,0, (WPARAM)tmp);

    mixerClose(m_hMixer);

    return 0;
}

int MixerSetValue(float fVal, DWORD comp)
{
    long lVal = (long)fVal;

    open_mixer();

    set_mixer(comp);

    set_mixer_value(lVal);

    mixerClose(m_hMixer);

    return 0;
}

int LoadDevicesList(HWND hDevice)
{
    WAVEOUTCAPS     woc;
    unsigned long   iNumDevs, i;
    char	    tmp[256];



    iNumDevs = waveOutGetNumDevs();

    while((int)SendMessage(hDevice, (UINT)LB_DELETESTRING, (WPARAM)0, 0) > 0);


    // sprintf(tmp, "ret = %d", i);
    // MessageBox(hMain, tmp, "Debug", MB_OK);

    // i = SendMessage(hDevice, (UINT)LB_DELETESTRING, (WPARAM)1, 0);
    // sprintf(tmp, "ret = %d", i);
    // MessageBox(hMain, tmp, "Debug", MB_OK);


    for (i = 0; i < iNumDevs; i++)
    {
	if (!waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS)))
	{
	    sprintf(tmp, "ID #%u: %s", i, woc.szPname);

	    SendMessage(hDevice, (UINT)LB_ADDSTRING, (WPARAM)0, (LPARAM)tmp);
	}
    }
    return 0;
}

int LoadRate()
{
    int      i;
    char     tmp[100];
    double   now;


    while((int)SendMessage(hRate, (UINT)LB_DELETESTRING, (WPARAM)0, (LPARAM)0) > 0);

    if (m_spWMPSettings->get_rate(&now) != S_OK)
    {
	MessageBox(hMain, "get_rate failed!", "Debug", MB_OK);
	return 0;
    }

    // sprintf(tmp, "%lf\n", now);

    // SendMessage(hRate, (UINT)LB_ADDSTRING, (WPARAM)0, (LPARAM)tmp);
    // SendMessage(hRate, (UINT)LB_SETITEMDATA, (WPARAM)0, (LPARAM)0);


    for (i = 0; rates[i] != -1; i++)
    {
	sprintf(tmp, "%lfx\n", rates[i]);

        SendMessage(hRate, (UINT)LB_ADDSTRING,   0, (LPARAM)tmp);
        // SendMessage(hRate, (UINT)LB_SETITEMDATA, i, (LPARAM)i);

	if (now == rates[i])
            SendMessage(hRate, (UINT)LB_SETTOPINDEX,  (WPARAM)i, (LPARAM)0);
    }
    return 0;
}

int Loadlanguage()
{
    long 	Index, LangID;
    char	tmp[256];
    BSTR	bstrLangDesc;


    while((int)SendMessage(hLanguage, (UINT)LB_DELETESTRING, (WPARAM)0, 0) > 0);


    m_spWMPControls3->get_currentAudioLanguageIndex(&Index);

    m_spWMPControls3->getAudioLanguageID(Index, &LangID);

    if (m_spWMPControls3->getLanguageName(LangID, &bstrLangDesc) != S_OK)
    {
	MessageBox(hMain, "getLanguageName failed!", "Debug", MB_OK);
	return 0;
    }

    WideCharToMultiByte(CP_ACP, 0, bstrLangDesc, -1, tmp, sizeof(tmp), NULL, NULL);

    SendMessage(hLanguage, (UINT)LB_ADDSTRING, (WPARAM)0, (LPARAM)tmp);

    return 0;
}


int ChangeProc()
{
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonCenter, GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonRight,  GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonLeft,   GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonUp,     GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonDown,   GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonForward,GWL_WNDPROC,(LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(ButtonReverse,GWL_WNDPROC,(LONG)ButtonProc);

    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonWmpInc, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonWmpDec, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonWavInc, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonWavDec, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonMasInc, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonMasDec, GWL_WNDPROC, (LONG)ButtonProc);
    wpOrigButtonProc = (WNDPROC)SetWindowLong(hButtonFullLev,GWL_WNDPROC, (LONG)ButtonProc);

    wpOrigTreeProc = (WNDPROC)SetWindowLong(hTreeView,   GWL_WNDPROC, (LONG)TreeProc);

    wpOrigEditProc = (WNDPROC)SetWindowLong(hTitle,      GWL_WNDPROC, (LONG)EditProc);
    wpOrigEditProc = (WNDPROC)SetWindowLong(hEditWmpVal, GWL_WNDPROC, (LONG)EditProc);
    wpOrigEditProc = (WNDPROC)SetWindowLong(hEditMasVal, GWL_WNDPROC, (LONG)EditProc);
    wpOrigEditProc = (WNDPROC)SetWindowLong(hEditWavVal, GWL_WNDPROC, (LONG)EditProc);

    return 0;
}

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    HTREEITEM hitem, curr, next;
    TVITEM pitem;
    WMPPlayState pwmpps;
    int len, ins, ret = 0;
    char tmp[256];
    BYTE buf[256];
    WORD ch;

    HDC hDC;
    PAINTSTRUCT ps;


    LPNM_TREEVIEW pntv = (LPNM_TREEVIEW)lParam;

    LPDRAWITEMSTRUCT lpdis;

    HBRUSH BrushWhite;
    HBRUSH BrushYellow;
    HBRUSH BrushCyan;



    switch (uMsg)
    {
	// case WM_CTLCOLORSTATIC:
	// case WM_CTLCOLOREDIT:
	    // if ((HWND)lParam == hTitle)
	    // {
		// HDC hdcChild = (HDC)wParam;

	        // SetTextColor(hdcChild, RGB(255,255,255));
	        // SetBkColor(hdcChild, RGB(16,37,128));
                // SetBkMode(hdcChild,OPAQUE);

	        // return (LRESULT)CreateSolidBrush(RGB(16, 37, 128));
	    // }
	    // return (LRESULT)CreateSolidBrush(RGB(255, 255, 255));
	    
	// case WM_LBUTTONDBLCLK:
	// case WM_LBUTTONDOWN:
    	    // MessageBox(hwnd, "Mouse click!",  "Debug", MB_OK);
	    // break;


	case WM_PAINT:

	    if (flag_fullview == 1)
		    return DefWindowProc(hwnd, uMsg, wParam, lParam);

	    hDC = BeginPaint(hwnd, &ps);

            //******************************************************
            //* draw the Track selector area
            //******************************************************
	    BrushWhite  = CreateSolidBrush(RGB(255, 255, 255));
	    BrushYellow = CreateSolidBrush(RGB(255, 235, 133));
	    BrushCyan   = CreateSolidBrush(RGB( 64, 237, 227));

	    SelectObject(hDC, BrushWhite);

	    Rectangle(hDC, 10, 270, 290, 520);

            //******************************************************
            //* draw the Level controls
            //******************************************************
	    SelectObject(hDC, BrushYellow);

	    Rectangle(hDC, MIXER_WAV_X,
			   MIXER_WAV_Y,
			   MIXER_WAV_X + 100,
			   MIXER_WAV_Y + 250);

	    //Rectangle(hDC, MIXER_MAS_X,
			   //MIXER_MAS_Y,
			   //MIXER_MAS_X + 100,
			   //MIXER_MAS_Y + (MIXER_TEXT_SIZE + MIXER_QUAD_SIZE * 2 + 5));

	    //Rectangle(hDC, MIXER_WMP_X,
			   //MIXER_WMP_Y,
			   //MIXER_WMP_X + 100,
			   //MIXER_WMP_Y + (MIXER_TEXT_SIZE + MIXER_QUAD_SIZE * 2 + 5));

            //******************************************************
            //* draw the DVD controls area
            //******************************************************
	    SelectObject(hDC, BrushCyan);

	    Rectangle(hDC, WIN_WIDTH / 2 + 10,
			   320,
			   WIN_WIDTH / 2 + 10 + 370,
			   320 + 50);

            //******************************************************
            //* draw the Audio device list
            //******************************************************
	    SelectObject(hDC, BrushCyan);

	    Rectangle(hDC, WIN_WIDTH / 2 + 10,
			   270,
			   WIN_WIDTH / 2 + 10 + 370,
			   270 + 40);

            //******************************************************
            //* draw the Video Area
            //******************************************************
	    Rectangle(hDC, WIN_WIDTH / 2 + 10,
			   10,
			   WIN_WIDTH / 2 + 10 + 370,
			   260);

            //******************************************************
            //* draw static text
            //******************************************************
	    SetBkColor(hDC, RGB(255,255,255));

	    TextOut(hDC, 20, 280, "Track",    5);
	    TextOut(hDC, 20, 300, "selector", 8);

	    SetBkColor(hDC, RGB(255,235,133));

	    ExtTextOut(hDC, MIXER_WAV_X + 5,
			    MIXER_WAV_Y + 4,
			    ETO_OPAQUE, NULL, 
			    "Wave level", 10, NULL);

	    ExtTextOut(hDC, MIXER_MAS_X + 4,
			    MIXER_MAS_Y + 4,
			    ETO_OPAQUE, NULL, 
			    "Master level", 12, NULL);

	    ExtTextOut(hDC, MIXER_WMP_X + 6,
			    MIXER_WMP_Y + 4,
			    ETO_OPAQUE, NULL, 
			    "WMP level", 9, NULL);

	    SetBkColor(hDC, RGB(64,237,227));

	    ExtTextOut(hDC, WIN_WIDTH / 2 + 10 + 5,
			    320 + 4,
			    ETO_OPAQUE, NULL, 
			    "DVD controls", 12, NULL);

	    ExtTextOut(hDC, WIN_WIDTH / 2 + 10 + 5,
			    270 + 4,
			    ETO_OPAQUE, NULL, 
			    "Audio devices list", 18, NULL);

	    ExtTextOut(hDC, WIN_WIDTH / 2 + 10 + 5,
			    10 + 4,
			    ETO_OPAQUE, NULL, 
			    "Video preview (click to fullscreen)", 35, NULL);

            DeleteObject(BrushWhite);
            DeleteObject(BrushYellow);
            DeleteObject(BrushCyan);

	    EndPaint(hwnd, &ps);

            return 0;

	case WM_DRAWITEM:
	    lpdis = (DRAWITEMSTRUCT*)lParam;

	    if (lpdis->hwndItem == hJog)
	    {
    	        MessageBox(hwnd, "Drawitem hJog!",  "Debug", MB_OK);

	        if (SetBkColor(lpdis->hDC, 0x00eeeeee) == CLR_INVALID)
		    MessageBox(hwnd, "SetBkColor failed!",  "Debug", MB_OK);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonCenter)
	    {
	       ChangeButton(lpdis, hBitmapButtonCenter, hBitmapButtonCenterSel, 80, 80);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonRight)
	    {
	       ChangeButton(lpdis, hBitmapButtonRight, hBitmapButtonRightSel, 80, 80);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonDown)
	    {
	       ChangeButton(lpdis, hBitmapButtonDown, hBitmapButtonDownSel, 80, 80);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonUp)
	    {
	       ChangeButton(lpdis, hBitmapButtonUp, hBitmapButtonUpSel, 80, 80);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonLeft)
	    {
	       ChangeButton(lpdis, hBitmapButtonLeft, hBitmapButtonLeftSel, 80, 80);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonForward)
	    {
	       ChangeButton(lpdis, hBitmapButtonForward, hBitmapButtonForwardSel, 30, 30);

		return TRUE; 
	    }
	    if (lpdis->hwndItem == ButtonReverse)
	    {
	       ChangeButton(lpdis, hBitmapButtonReverse, hBitmapButtonReverseSel, 30, 30);

		return TRUE; 
	    }
	    return 0;
	
	case WM_COMMAND:

	    // ************* NEW to test *********************************
	    if (HIWORD(wParam) == LBN_SELCHANGE) 
	    {
		MessageBox(hwnd, "Listbox change sel !",  "Debug", MB_OK);

                switch (LOWORD(wParam)) 
		{
		    case IDL_RATE:
			MessageBox(hwnd, "hRate change sel !",  "Debug", MB_OK);
			break;
		}
	    }
	    // ************* end - NEW to test *********************************

	    else if (HIWORD(wParam) == BN_CLICKED) 
	    {
		long Count, Index, LangID;

                switch (LOWORD(wParam)) 
                { 
                    case EV_BUTTONRATE: 
		        int nItem;

		        nItem = (int)SendMessage(hRate, LB_GETTOPINDEX , (WPARAM)0, (LPARAM)0); 

		        if (m_spWMPSettings->put_rate(rates[nItem]) == E_INVALIDARG)
		        {
			    MessageBox(hMain, "put_rate failed!", "Debug", MB_OK);
			    return 0;
		        }
			break;

                    case EV_BUTTONLANG: 
		        m_spWMPControls3->get_audioLanguageCount(&Count);

		        m_spWMPControls3->get_currentAudioLanguageIndex(&Index);

			if (Index < Count)
			    Index++;
			else
			    Index = 1;

		        m_spWMPControls3->getAudioLanguageID(Index, &LangID);

		        m_spWMPControls3->put_currentAudioLanguage(LangID);
			break;

                    case EV_BUTTONTOPMENU: 
			spDVD->topMenu();
			break;

                    case EV_BUTTONTITMENU: 
			spDVD->titleMenu();
			break;

                    case EV_BUTTONRIGHT: 
			TreeNavigation(EV_BUTTONRIGHT);
                        break; 

                    case EV_BUTTONLEFT: 
			TreeNavigation(EV_BUTTONLEFT);
                        break; 

                    case EV_BUTTONUP: 
			TreeNavigation(EV_BUTTONUP);
                        break; 

                    case EV_BUTTONDOWN: 
			TreeNavigation(EV_BUTTONDOWN);
			// PostMessage(hMain, WM_KEYDOWN, 0, 0);
                        break; 

                    case EV_BUTTONCENTER: 
			if (flag_playing == 1)
		        {
			    m_spWMPControls->pause();
			    flag_playing = 2;
			}
			else if (flag_playing == 2)
			{
			    m_spWMPControls->play();
			    flag_playing = 1;
			}
                        break; 

                    case EV_BUTTONFORWARD: 
			if (flag_playing == 1)
			{
			    // m_spWMPControls->fastForward();

			    IWMPMedia *  ppIWMPMedia;
			    double       pos, tot;


			    if (m_spWMPControls->get_currentItem(&ppIWMPMedia) != S_OK)
				return 0;

			    ppIWMPMedia->get_duration(&tot);

			    m_spWMPControls->get_currentPosition(&pos);

			    m_spWMPControls->put_currentPosition(pos + tot / 20.0);
			}
			break;

                    case EV_BUTTONREVERSE: 
			if (flag_playing == 1)
                        {
			    // m_spWMPControls->fastReverse();

			    IWMPMedia *  ppIWMPMedia;
			    double       pos, tot;


			    if (m_spWMPControls->get_currentItem(&ppIWMPMedia) != S_OK)
				return 0;

			    ppIWMPMedia->get_duration(&tot);

			    m_spWMPControls->get_currentPosition(&pos);

			    m_spWMPControls->put_currentPosition(pos - tot / 20.0);
			}
			break;

		    case BUTTON_MAS_INC:
			if (MASvol < 64000.0)
			    MASvol += 1371;
			else
			    MASvol = 65536;

			MixerSetValue(MASvol, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
			break;

		    case BUTTON_MAS_DEC:
			if (MASvol > 1371)
			    MASvol -= 1371;
			else
			    MASvol = 0;

			MixerSetValue(MASvol, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
			break;

		    case BUTTON_WAV_INC:
			if (WAVvol < 64000.0)
			    WAVvol += 1371;
			else
			    WAVvol = 65536;

			MixerSetValue(WAVvol, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);
			break;

		    case BUTTON_WAV_DEC:
			if (WAVvol > 1371)
			    WAVvol -= 1371;
			else
			    WAVvol = 0;

			MixerSetValue(WAVvol, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);
			break;

		    case BUTTON_WMP_INC:
			if (WMPvol < 95)
			    WMPvol += 5;
			else
			    WMPvol = 100;

			m_spWMPSettings->put_volume(WMPvol);
			break;

		    case BUTTON_WMP_DEC:
			if (WMPvol > 5)
			    WMPvol -= 5;
			else
			    WMPvol = 0;

			m_spWMPSettings->put_volume(WMPvol);
			break;

		    case BUTTON_FULL_LEV:
		        m_spWMPSettings->put_balance(0l);
		        m_spWMPSettings->put_mute(FALSE);
			m_spWMPSettings->put_volume(100);

			MixerSetValue(65536, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);

			MixerSetValue(65536, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);

			break;

		    default:
			MessageBox(hwnd, "Generic click",  "Debug", MB_OK);
		}
		// sprintf(tmp, "BN_CLICKED = %d\n", LOWORD(wParam));

		// MessageBox(hwnd, tmp,  "Debug", MB_OK);
	    }
	    return 0;

        case WM_TIMER:
	    LoadDevicesList(hDevice);

	    MixerLoadValue(hEditWavVal,hEditMasVal,hEditWmpVal);

	    if (flag_playing > 0)
	    {
		BSTR       tmp;
		char       szTmp[200];


		Loadlanguage();


		m_spWMPPlayer->get_playState(&pwmpps);

		if (pwmpps != 3 && pwmpps != 9 && pwmpps != 2)
		{
		    PostMessage(hMain, WM_KEYDOWN, 0, 0);

		    flag_playing = 0;
		}


		m_spWMPControls->get_currentPositionString(&tmp);

		WideCharToMultiByte(CP_ACP, 0, tmp, -1, szTmp, sizeof(szTmp), NULL, NULL);

		SendMessage(hTime,(UINT)WM_SETTEXT,0, (WPARAM)szTmp);
	    }
	    return 0;

        case WM_KEYDOWN:
	    switch (wParam) 
            { 
		case 0:
		    // MessageBox(hwnd, "Play next", "Debug", MB_OK);

		    hitem = TreeView_GetSelection(hTreeView);

 		    if ((next = TreeView_GetNextSibling(hTreeView, hitem)) != NULL)
			    TreeView_SelectItem(hTreeView, next);

		    break;

		case VK_RETURN:
		    if (flag_playing == 1)
		    {
			m_spWMPControls->pause();
			flag_playing = 2;
		    }
		    else if (flag_playing == 2)
		    {
			m_spWMPControls->play();
			flag_playing = 1;
		    }
		    break;

		case VK_UP:
		    TreeNavigation(EV_BUTTONUP);
		    break;

		case VK_DOWN:
		    TreeNavigation(EV_BUTTONDOWN);
		    break;

		case VK_LEFT:
		    TreeNavigation(EV_BUTTONLEFT);
		    break;

		case VK_RIGHT:
		    TreeNavigation(EV_BUTTONRIGHT);
		    break;

		default:
		    GetKeyboardState (&buf[0]);

		    ToAscii (wParam, lParam, &buf[0], &ch, 0);

		    sprintf(tmp, "%c", ch);

		    // MessageBox(hwnd, tmp,  "Key down received", MB_OK);

		    switch(tmp[0])
		    { 
		    	case '0':
			    PostQuitMessage (0);
			    exit(0);
			    break;
		    }
	    }
            return 0;
		
        case WM_NOTIFY:
             if(pntv->hdr.code == TVN_SELCHANGED)
             {
		char  path[1024] = "";


	        UpdateTitle(); 	// NEW


                curr = hitem = TreeView_GetSelection(hTreeView);

	        TreeView_SelectDropTarget(hTreeView, curr);

		// MessageBox(hwnd, "load children",  "Debug", MB_OK);

	        //****************************************************
	        //* delete previous children
	        //****************************************************
		if ((next = TreeView_GetChild(hTreeView, hitem)) != NULL)
                {
		    while(1)
		    {
		        hitem = next;

 		        if ((next = TreeView_GetNextSibling(hTreeView, hitem)) == NULL) break;

		        TreeView_DeleteItem(hTreeView, hitem);
	  	    }
	            TreeView_DeleteItem(hTreeView, hitem);
		}
                hitem = curr;

		//****************************************************
	        //* create the complete path to expand
	        //****************************************************
		path[0] = '\0';

		while(1)
		{
                    pitem.mask  = TVIF_TEXT;
                    pitem.hItem = hitem;
		    pitem.pszText = (char *)malloc(256);
		    pitem.cchTextMax = 256;
                   
                    memset(pitem.pszText, '\0', 256);

   		    TreeView_GetItem(hTreeView, &pitem);

		    //memcpy(&pitem.pszText[0], &pitem.pszText[6], strlen(pitem.pszText) + 1);

                    if (strlen(path) > 2)
   		        strcat(pitem.pszText, "\\");

                    len = strlen(path);
                    ins = strlen(pitem.pszText);

                    memcpy(&path[ins], &path[0], len + 1);
                    memcpy(&path[0], pitem.pszText, ins);

                    free(pitem.pszText);

		    // MessageBox(hwnd, path,  "Debug", MB_OK);
                                       
                    if ((hitem = TreeView_GetParent(hTreeView, hitem)) == NULL)
			break;
		}

		hitem = curr;

		//***************************************************
		// Check if music file
		//***************************************************
		pitem.mask  = TVIF_IMAGE;
		pitem.hItem = hitem;

		TreeView_GetItem(hTreeView, &pitem);

		if (pitem.iImage == 1)
		{
		     PlayMusic(path);
		     return 0;
		}
		
		//****************************************************
	        //* insert children
	        //****************************************************
		hitem = curr;
		
                strcat(path, "\\*");

		GetList(hitem, path);
             }
             return 0;

        // case WM_SIZE:
            // MoveWindow(hEdit, 200, 0, LOWORD(lParam)-200, HIWORD(lParam), TRUE);
            // MoveWindow(hTreeView, 0, 0, 200, HIWORD(lParam), TRUE);
            // return 0;

        case WM_DESTROY:
	     KillTimer(hMain, 1); 
	     //***********************************************************
	     //* reset the normal windows  procedure for the modified
	     //***********************************************************
             SetWindowLong(hWMP, GWL_WNDPROC,(LONG) wpOrigWmpProc);

             PostQuitMessage(0);
	     exit(0);

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}

LRESULT APIENTRY EditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   if (uMsg == WM_SETFOCUS)
	return 0;

   if (uMsg == WM_KEYDOWN)
   {
       MainWndProc(hwnd, uMsg, wParam, lParam);
       return 0;
   }
   return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
}

LRESULT APIENTRY TreeProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   if (uMsg == WM_KEYDOWN)
   {
       MainWndProc(hwnd, uMsg, wParam, lParam);
       return 0;
   }
   return CallWindowProc(wpOrigTreeProc, hwnd, uMsg, wParam, lParam);
}

LRESULT APIENTRY ButtonProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   if (uMsg == WM_KEYDOWN)
   {
       MainWndProc(hwnd, uMsg, wParam, lParam);
       return 0;
   }
   return CallWindowProc(wpOrigButtonProc, hwnd, uMsg, wParam, lParam);
}

int TreeNavigation(int op)
{
    HTREEITEM next, hitem = TreeView_GetSelection(hTreeView);

    switch(op)
    {
	case EV_BUTTONRIGHT:
	    if ((next = TreeView_GetChild(hTreeView, hitem)) != NULL)
	    {
		TreeView_SelectItem(hTreeView, next);

		TreeView_SelectDropTarget(hTreeView, next);
	    }
	    break;

	case EV_BUTTONLEFT:
	    if ((next = TreeView_GetParent(hTreeView, hitem)) != NULL)
	    {
		TreeView_SelectItem(hTreeView, next);

		TreeView_SelectDropTarget(hTreeView, next);
	    }
	    break;

	case EV_BUTTONUP:
	    if ((next = TreeView_GetPrevSibling(hTreeView, hitem)) != NULL)
	    {
		TreeView_SelectItem(hTreeView, next);

		TreeView_SelectDropTarget(hTreeView, next);
	    }
	    break;

	case EV_BUTTONDOWN:
	    if ((next = TreeView_GetNextSibling(hTreeView, hitem)) != NULL)
	    {
		TreeView_SelectItem(hTreeView, next);

		TreeView_SelectDropTarget(hTreeView, next);
	    }
	    break;
    }
    return 0;
}

int OpenWMP(HWND hwnd)
{
    AtlAxWinInit();
	
    CComPtr<IAxWinHostWindow>           spHost;
    CComPtr<IConnectionPointContainer>  spConnectionContainer;
    CComPtr<IWMPEvents>                 spEventListener;

    RECT                                rcClient;
    HRESULT                             hr;


    GetClientRect(hMain, &rcClient);

    rcClient.left += WIN_WIDTH / 2 + 10 + 4;
    rcClient.right -= 10 + 5;
    rcClient.bottom -= 275 + 4;
    rcClient.top += 10 + 23;
    
    m_wndView.Create(hwnd, rcClient, NULL, WS_CHILD|WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);

    if (NULL == m_wndView.m_hWnd)
        return -1;

    hWMP = m_wndView.m_hWnd;

    hr = m_wndView.QueryHost(&spHost);
    if (FAILMSG(hr))
        return -1;

    hr = spHost->CreateControl(CComBSTR(_T("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")), m_wndView, 0);
    if (FAILMSG(hr))
        return -1;

    hr = m_wndView.QueryControl(&m_spWMPPlayer);
    if (FAILMSG(hr))
        return -1;

    hr = m_wndView.QueryControl(&m_spWMPSettings);
    if (FAILMSG(hr))
        return -1;

    hr = m_wndView.QueryControl(&m_spWMPControls);
    if (FAILMSG(hr))
        return -1;

    hr = m_spWMPControls.QueryInterface(&m_spWMPControls3);
    if (FAILMSG(hr))
        return -1;

    hr = m_wndView.QueryControl(&m_spWMPPlayer2);
    if (FAILMSG(hr))
        return -1;

    hr = m_wndView.QueryControl(&m_spWMPCore2);
    if (FAILMSG(hr))
        return -1;

    m_spWMPPlayer->put_uiMode(CComBSTR(_T("none")));  // NEW
    m_spWMPPlayer->put_enableContextMenu(FALSE);


    hr = m_spWMPCore2->get_dvd(&spDVD);

    if (hr != S_OK)
        MessageBox(hMain, "get_dvd failed!", "Debug", MB_OK);

#ifdef OLD
    {
	CComPtr<IWMPSyncServices>  spSyncServices;
	CComPtr<IWMPSyncDevice>    spTempDevice;

	hr = m_spWMPPlayer->QueryInterface(&spSyncServices);

	if(SUCCEEDED(hr) && spSyncServices.p)
	{  
	    long plCount;
	    char tmp[200];

	    hr = spSyncServices->get_deviceCount(&plCount);

	    sprintf(tmp, "ret = %ld", plCount);
	    MessageBox(hMain, tmp, "Debug", MB_OK);
	}
    }
#endif

    ShowWindow(m_wndView.m_hWnd, SW_SHOW);

    //***********************************************************
    //* set the new windows  procedure for this window
    //***********************************************************
    wpOrigWmpProc = (WNDPROC)SetWindowLong(m_wndView.m_hWnd, GWL_WNDPROC,(LONG)WmpWndProc);

    m_spWMPSettings->get_volume(&WMPvol);
    m_spWMPSettings->put_balance(0l);
    m_spWMPSettings->put_mute(FALSE);
    m_spWMPSettings->put_rate(1l);

    InitCommonControls();

    return 0;	
}

LRESULT APIENTRY WmpWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   int cx, cy;


   if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN )
   {
	if (flag_fullview == 0)
	{
	    ShowWindow(hTime,         SW_HIDE);
	    ShowWindow(hJog,          SW_HIDE);
	    ShowWindow(hRate,         SW_HIDE);
	    ShowWindow(hTreeView,     SW_HIDE);
	    ShowWindow(hDevice,       SW_HIDE);
	    ShowWindow(hLanguage,     SW_HIDE);
	    ShowWindow(hTitle,        SW_HIDE);
	    ShowWindow(hButtonWmpInc, SW_HIDE);
	    ShowWindow(hButtonMasInc, SW_HIDE);
	    ShowWindow(hButtonWavInc, SW_HIDE);
	    ShowWindow(hButtonWmpDec, SW_HIDE);
	    ShowWindow(hButtonMasDec, SW_HIDE);
	    ShowWindow(hButtonWavDec, SW_HIDE);
	    ShowWindow(hEditWmpVal,   SW_HIDE);
	    ShowWindow(hEditMasVal,   SW_HIDE);
	    ShowWindow(hEditWavVal,   SW_HIDE);
	    ShowWindow(ButtonUp,      SW_HIDE);
	    ShowWindow(ButtonDown,    SW_HIDE);
	    ShowWindow(ButtonRight,   SW_HIDE);
	    ShowWindow(ButtonLeft,    SW_HIDE);
	    ShowWindow(ButtonCenter,  SW_HIDE);
	    ShowWindow(ButtonForward, SW_HIDE);
	    ShowWindow(ButtonReverse, SW_HIDE);
	    ShowWindow(ButtonTopMenu, SW_HIDE);
	    ShowWindow(ButtonTitMenu, SW_HIDE);
	    ShowWindow(ButtonLang,    SW_HIDE);
	    ShowWindow(ButtonRate,    SW_HIDE);
	    ShowWindow(hButtonFullLev,SW_HIDE);

	    ShowWindow(hMain,          SW_MAXIMIZE);
	    ShowWindow(hWMP,          SW_MAXIMIZE);


	    //***********************************************
	    //* Get video size
	    //***********************************************
	    HDC dc = ::GetDC(NULL); 

	    cx = GetDeviceCaps(dc,HORZRES) + 6; //  GetSystemMetrics(SM_CXBORDER) + 1; 
	    cy = GetDeviceCaps(dc,VERTRES) + 6; //  GetSystemMetrics(SM_CYBORDER) + 1; 

	    ReleaseDC(0,dc); 

	    //***********************************************
	    //* Remove caption and border
	    //***********************************************
	    SetWindowLong(hMain, GWL_STYLE,
		          GetWindowLong(hMain, GWL_STYLE) & (~(WS_CAPTION | WS_BORDER))); 

	    //***********************************************
	    //* Maximize main window
	    //***********************************************
	    SetWindowPos(hMain, HWND_TOPMOST, 
		            -3,  // -(GetSystemMetrics(SM_CXBORDER)+1+1 ), 
			    -3,  // -(GetSystemMetrics(SM_CYBORDER)+1+1 ), 
			    cx, cy, SWP_NOZORDER); 
			    // 0, 0, cx,cy, SWP_NOZORDER); 

	    SetWindowPos(hWMP, HWND_TOPMOST, 
		            -3, // -(GetSystemMetrics(SM_CXBORDER)+1+1 ), 
			    -3, // -(GetSystemMetrics(SM_CYBORDER)+1+1 ), 
			    cx, cy, SWP_NOZORDER); 

	    //***********************************************
	    //* Hide takbar
	    //***********************************************
	    // hTaskBar = FindWindow("Shell_TrayWnd", NULL);

	    // ShowWindow(hTaskBar, SW_HIDE);
	
	    //***********************************************
	    //* Expand WMP video area
	    //***********************************************
	    // m_spWMPPlayer->put_fullScreen(TRUE);
	    m_spWMPPlayer2->put_stretchToFit(TRUE);
	    m_spWMPPlayer2->put_windowlessVideo(TRUE);

	    ShowCursor(FALSE);

            flag_fullview = 1;
	}
	else
	{
	    ShowAll();

	    //***********************************************
	    //* Restore caption and border
	    //***********************************************
	    SetWindowLong(hMain, GWL_STYLE,
			  GetWindowLong(hMain, GWL_STYLE) | ((WS_CAPTION | WS_BORDER))); 

	    ShowWindow(hMain,         SW_RESTORE);
	    ShowWindow(hWMP,          SW_RESTORE);
	
	    //***********************************************
	    //* Restore TaskBar if it is hide
	    //***********************************************
	    // ShowWindow(hTaskBar, SW_RESTORE);

	    ShowCursor(TRUE);

            flag_fullview = 0;
	}
        return TRUE;
    }
    return CallWindowProc(wpOrigWmpProc, hwnd, uMsg, wParam, lParam);
}

int LoadImage(HWND hTreeView)
{
    HIMAGELIST himgList;
    HICON hIcon;
    HINSTANCE dllhinst;


    himgList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
		                GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 , 4, 4);

    ImageList_SetBkColor(himgList, GetSysColor(COLOR_WINDOW));

    dllhinst = LoadLibrary("shell32.dll");

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(4));	// Folder
    ImageList_AddIcon(himgList, hIcon);

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(41));   // CD Audio
    ImageList_AddIcon(himgList, hIcon);

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(9));	// Harddisk
    ImageList_AddIcon(himgList, hIcon);

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(11)); // Network
    ImageList_AddIcon(himgList, hIcon);

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(12)); // CDROM
    ImageList_AddIcon(himgList, hIcon);

    hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(7)); // FLOPPY
    ImageList_AddIcon(himgList, hIcon);

    FreeLibrary(dllhinst);

    TreeView_SetImageList(hTreeView, himgList, TVSIL_NORMAL);

    return 0;
}

int InsertTreeItem(HWND hTreeView, HTREEITEM hParent, char * buffer, int icon)
{
      TV_INSERTSTRUCT tviis;

      tviis.hInsertAfter = TVI_LAST;

      ZeroMemory(&(tviis.item), sizeof(TV_ITEM));

      tviis.item.mask  = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_CHILDREN; // |TVIF_STATE ;

      tviis.hParent = hParent;
      tviis.item.iImage = 0;
      tviis.item.pszText = buffer;


      tviis.item.iImage = icon;
      tviis.item.iSelectedImage = icon;

      if (icon == ICON_MUSIC)
	  tviis.item.cChildren = 0;
      else
	  tviis.item.cChildren = 1;

      TreeView_InsertItem(hTreeView, &tviis);

      return 0;
}


int GetDrivesList()
{
    int drive, icon;
    static char path[_MAX_PATH], buffer[1024];
    int nchoice, ret;


    for( drive = nchoice = 0; drive <= 26; drive++ )
    {
	sprintf(path, "%c:", drive + 'A' );

	ret = GetDriveType(path);

	switch (ret)
	{
	    case DRIVE_CDROM:
		icon = ICON_CDROM;
		break;

	    case DRIVE_REMOVABLE:
		icon = ICON_FLOPPY;
		break;

	    case DRIVE_FIXED:
		icon = ICON_HARDDISK;
		break;

	    case DRIVE_REMOTE:
		icon = ICON_NETWORK;
		    break;

	    default:
		continue;
	}
	InsertTreeItem(hTreeView, TVI_ROOT, path, icon);

	nchoice++;
    }
    return 0;
}

int GetList(HTREEITEM hParent, char * path)
{
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    int i = 0;


    SetErrorMode(SEM_FAILCRITICALERRORS);

    hFind=FindFirstFile(path, &FindFileData);

    if (hFind == INVALID_HANDLE_VALUE)
    {
	// printf("Cannot access to drive\n");
	return -1;
    }

    i = 0;

    do 
    {
	if (strncmp(FindFileData.cFileName, ".", 1) != 0)
	{
   	     // char tmp[200];

	     // sprintf(tmp, "ret = %d", FindFileData.dwFileAttributes);
	     // MessageBox(hMain, tmp, "Debug", MB_OK);

	    // if ((FindFileData.dwFileAttributes ==
		 // (FILE_ATTRIBUTE_DIRECTORY & FILE_ATTRIBUTE_READONLY)) ||
	        // (FindFileData.dwFileAttributes ==
		 // FILE_ATTRIBUTE_DIRECTORY ))

	    if ((FindFileData.dwFileAttributes == 16) ||
                (FindFileData.dwFileAttributes == 17))
	        InsertTreeItem(hTreeView, hParent, FindFileData.cFileName, ICON_FOLDER);
	    else if (check_extension(FindFileData.cFileName) == 0)
                InsertTreeItem(hTreeView, hParent, FindFileData.cFileName, ICON_MUSIC);
	}

    } while ( FindNextFile(hFind, &FindFileData) );

    FindClose(hFind);

    return 0;
}

int PlayMusic(char * path)
{
    if (check_extension(path) == 0)
    {
	TCHAR    szFileNamep[_MAX_PATH];
	BSTR     unicodestr;
	HRESULT  hr;
	int      a;


	strcpy(szFileNamep, path); 

	a = lstrlenA(szFileNamep);

	unicodestr = SysAllocStringLen(NULL, a);

	MultiByteToWideChar(CP_ACP, 0, szFileNamep, a, unicodestr, a);

	hr = m_spWMPPlayer->put_URL(unicodestr);

	SysFreeString(unicodestr);

	flag_playing = 1;

	return 0;
    }
    return -1;
}

int  check_extension(char * filename)
{
    int i, fil_len, ext_len, st;

    char * ext[] =
	{".vob", ".ifo", ".VOB", ".IFO", ".mp3", ".mid", ".rmi", ".midi", ".mpeg", ".mpg",".mp2", ".tta", ".wma", ".wav", ".au", ".avi", NULL};


    for (i = 0; ext[i] != NULL; i++)
    {
	fil_len = strlen(filename);
	ext_len = strlen(ext[i]);

	st = fil_len - ext_len;

	// printf("<%s> <%s>\n", &filename[st], ext[i]);

	if (strncmp(&filename[st], ext[i], ext_len) == 0)
	    return 0;
    }
    return -1;
}

HFONT Set_Font (char *Font,int Size,int Bold,int Italic,int Underline,int StrikeThru)
{
        HDC hDC = GetDC(HWND_DESKTOP);
        int CyPixels = GetDeviceCaps(hDC,LOGPIXELSY);
        ReleaseDC(HWND_DESKTOP,hDC);
        return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,
        0,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font);
}

int open_mixer()
{
   UINT m_nNumMixers;
   MIXERCAPS m_mxcaps;


   m_nNumMixers  = mixerGetNumDevs();

   m_hMixer = NULL;

   // printf("MIxer number <%d>\n", m_nNumMixers);

   if (m_nNumMixers != 0)
   {
	if (mixerOpen(&m_hMixer, 0, 0, // reinterpret_cast<DWORD>(this->GetSafeHwnd()),
		    NULL, MIXER_OBJECTF_MIXER | CALLBACK_WINDOW) != MMSYSERR_NOERROR)
	{
		return FALSE;
	}

	if (mixerGetDevCaps(reinterpret_cast<UINT>(m_hMixer),
			  &m_mxcaps, sizeof(MIXERCAPS)) != MMSYSERR_NOERROR)
	{
		    return FALSE;
	}
    }
    return 0;
}


int set_mixer(DWORD ComponentType)
{
    MIXERLINE mxl;

    mxl.cbStruct = sizeof(MIXERLINE);

    // mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
    // mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
    mxl.dwComponentType = ComponentType;

    if (mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(m_hMixer), &mxl,
        MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
    {
	    return FALSE;
    }

    MIXERCONTROL mxc;
    MIXERLINECONTROLS mxlc;

    mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
    mxlc.dwLineID = mxl.dwLineID;

    // mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
    mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;

    mxlc.cControls = 1;
    mxlc.cbmxctrl = sizeof(MIXERCONTROL);
    mxlc.pamxctrl = &mxc;

    if (mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(m_hMixer), &mxlc,
	MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR)
    {
	printf("error from mixerGetLineControls\n");
        return FALSE;
    }

    printf("nam = <%s>\n", mxl.szName);
    printf("nam = <%s>\n", mxc.szName);

    m_dwControlID = mxc.dwControlID;

    return 0;
}

int get_mixer_value(long * lVal)
{
    MIXERCONTROLDETAILS_BOOLEAN mxcdMute;
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    mxcd.paDetails = &mxcdMute;

    if (mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(m_hMixer), &mxcd,
	 MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
    {
	return FALSE;
    }
    
    *lVal = mxcdMute.fValue;

    return 0;
}

int set_mixer_value(long lVal)
{
    printf("set now\n");

    MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { lVal };
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS);
    mxcd.paDetails = &mxcdMute;

    if (mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(m_hMixer),
				     &mxcd,
				     MIXER_OBJECTF_HMIXER |
				     MIXER_SETCONTROLDETAILSF_VALUE)
	    != MMSYSERR_NOERROR)
    {
	    return FALSE;
    }
    return 0;
}


int CreateJog(HWND hMain, HINSTANCE hinstance)
{

    ButtonCenter = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_ORIG_Y + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_QUAD_SIZE,
	JOG_QUAD_SIZE,
	hMain,
	(HMENU)EV_BUTTONCENTER,hinstance, NULL);

    ButtonRight = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + 2 * JOG_QUAD_SIZE + 2 * JOG_SHIFT,
	JOG_ORIG_Y + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_QUAD_SIZE,
	JOG_QUAD_SIZE,
	hMain,
	(HMENU)EV_BUTTONRIGHT,hinstance,NULL);

    ButtonLeft = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X,
	JOG_ORIG_Y + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_QUAD_SIZE,
	JOG_QUAD_SIZE,
	hMain,
	(HMENU)EV_BUTTONLEFT, hinstance, NULL);

    ButtonUp = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_ORIG_Y,
	JOG_QUAD_SIZE,
	JOG_QUAD_SIZE,
	hMain,
	(HMENU)EV_BUTTONUP, hinstance, NULL);

    ButtonDown = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + JOG_QUAD_SIZE + JOG_SHIFT,
	JOG_ORIG_Y + 2 * JOG_QUAD_SIZE + 2 * JOG_SHIFT,
	JOG_QUAD_SIZE,
	JOG_QUAD_SIZE,
	hMain,
	(HMENU)EV_BUTTONDOWN, hinstance, NULL);

    ButtonForward = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + 2 * JOG_QUAD_SIZE + JOG_SHIFT + 70,
	JOG_ORIG_Y + 10,
	30,
	30,
	hMain,
	(HMENU)EV_BUTTONFORWARD, hinstance, NULL);

    ButtonReverse = CreateWindow("BUTTON","+",
	WS_CHILD|BS_DEFPUSHBUTTON|BS_PUSHBUTTON|BS_OWNERDRAW|BS_FLAT,
	JOG_ORIG_X + 2 * JOG_QUAD_SIZE + JOG_SHIFT + 20,
	JOG_ORIG_Y + 10,
	30,
	30,
	hMain,
	(HMENU)EV_BUTTONREVERSE, hinstance, NULL);



    if ((hBitmapButtonCenter = (HBITMAP)LoadImage(NULL, "arrow_center.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonCenterSel = (HBITMAP)LoadImage(NULL, "arrow_center_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonRight     = (HBITMAP)LoadImage(NULL, "arrow_right.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonRightSel  = (HBITMAP)LoadImage(NULL, "arrow_right_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonLeft      = (HBITMAP)LoadImage(NULL, "arrow_left.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonLeftSel   = (HBITMAP)LoadImage(NULL, "arrow_left_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonUp        = (HBITMAP)LoadImage(NULL, "arrow_up.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonUpSel     = (HBITMAP)LoadImage(NULL, "arrow_up_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonDown      = (HBITMAP)LoadImage(NULL, "arrow_down.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonDownSel   = (HBITMAP)LoadImage(NULL, "arrow_down_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonForward   = (HBITMAP)LoadImage(NULL, "arrow_forward.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonReverse   = (HBITMAP)LoadImage(NULL, "arrow_reverse.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonForwardSel   = (HBITMAP)LoadImage(NULL, "arrow_forward_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    if ((hBitmapButtonReverseSel   = (HBITMAP)LoadImage(NULL, "arrow_reverse_sel.bmp",
	IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE )) == NULL)
	MessageBox(hMain, "LoadImage failed!", "Debug", MB_OK);

    return 0;
}

int ChangeButton(LPDRAWITEMSTRUCT lpdis, HBITMAP hButton, HBITMAP hButtonSel, int w, int h)
{
    HDC hdc = CreateCompatibleDC(lpdis->hDC);

    if (lpdis->itemState & ODS_SELECTED)
	    SelectObject(hdc, hButtonSel);
    else
	    SelectObject(hdc, hButton);

    StretchBlt(lpdis->hDC,
	       lpdis->rcItem.left,
	       lpdis->rcItem.top,
	       lpdis->rcItem.right  - lpdis->rcItem.left,
	       lpdis->rcItem.bottom - lpdis->rcItem.top,
	       hdc,0,0,w,h,SRCCOPY);

    DeleteDC(hdc);

    return 0;
}

int CreateTitle(HWND hMain, HINSTANCE hinstance)
{
#define TITLE_ORIG_Y	(380)
#define TITLE_ORIG_X	(WIN_WIDTH / 2 + 10)

    hTitle = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",
	    WS_CHILD|ES_READONLY|ES_LEFT|ES_NUMBER|ES_NOHIDESEL|ES_MULTILINE,
	    TITLE_ORIG_X,
	    TITLE_ORIG_Y,
	    370,
	    140,
	    hMain,
	    (HMENU)TITLE,
	    hinstance,
	    NULL);

    SendMessage(hTitle,(UINT)WM_SETFONT,(WPARAM)Set_Font("Arial",17,1,0,0,0),1);

    return 0;
}

int ConcatText(char * tmp, HTREEITEM hitem)
{
    TVITEM pitem;
    char * ptr;
    int i;

    pitem.mask       = TVIF_TEXT;
    pitem.hItem      = hitem;
    pitem.pszText    = (char *)malloc(256);
    pitem.cchTextMax = 256;
   
    memset(pitem.pszText, '\0', 256);

    TreeView_GetItem(hTreeView, &pitem);

    if ((i = strlen(tmp)) > 0)
    {
        tmp[i++] = '\r';
        tmp[i++] = '\n';
        tmp[i]   = '\0';
    }

    for (ptr = pitem.pszText; *ptr != '\0'; ptr++)
    {
        if ((*(ptr) == ' ' && *(ptr+1) == ' ') ||
            (*(ptr) == '_' && *(ptr+1) == '_'))
        {
	    tmp[i++] = '\r';
	    tmp[i++] = '\n';
	    ptr ++;
        }
	else if (*ptr == '_')
        {
	    tmp[i++] = ' ';
        }
	else
        {
	    tmp[i++] = *ptr;
        }
    }
    tmp[i] = '\0';

    return 0;
}

int UpdateTitle()
{
    HTREEITEM hitem, parent;
    char tmp[1024] = "";


    hitem = TreeView_GetSelection(hTreeView);

    if (hitem == NULL) return 0;

    if ((parent = TreeView_GetParent(hTreeView, hitem)) != NULL)
    {
	ConcatText(tmp, parent);
    }
    ConcatText(tmp, hitem);

    SendMessage(hTitle,(UINT)WM_SETTEXT,0, (WPARAM)tmp);

    return 0;
}

int ShowAll()
{
    ShowWindow(hTime,         SW_SHOW);
    ShowWindow(hJog,          SW_SHOW);
    ShowWindow(hRate,         SW_SHOW);
    ShowWindow(hTreeView,     SW_SHOW);
    ShowWindow(hDevice,       SW_SHOW);
    ShowWindow(hLanguage,     SW_SHOW);
    ShowWindow(hTitle,        SW_SHOW);
    ShowWindow(hButtonWmpInc, SW_SHOW);
    ShowWindow(hButtonMasInc, SW_SHOW);
    ShowWindow(hButtonWavInc, SW_SHOW);
    ShowWindow(hButtonWmpDec, SW_SHOW);
    ShowWindow(hButtonMasDec, SW_SHOW);
    ShowWindow(hButtonWavDec, SW_SHOW);
    ShowWindow(hEditWmpVal,   SW_SHOW);
    ShowWindow(hEditMasVal,   SW_SHOW);
    ShowWindow(hEditWavVal,   SW_SHOW);
    ShowWindow(ButtonUp,      SW_SHOW);
    ShowWindow(ButtonDown,    SW_SHOW);
    ShowWindow(ButtonRight,   SW_SHOW);
    ShowWindow(ButtonLeft,    SW_SHOW);
    ShowWindow(ButtonCenter,  SW_SHOW);
    ShowWindow(ButtonForward, SW_SHOW);
    ShowWindow(ButtonReverse, SW_SHOW);
    ShowWindow(ButtonTopMenu, SW_SHOW);
    ShowWindow(ButtonTitMenu, SW_SHOW);
    ShowWindow(ButtonLang,    SW_SHOW);
    ShowWindow(ButtonRate,    SW_SHOW);
    ShowWindow(hButtonFullLev,SW_SHOW);

    return 0;
}