/**************************************************************************
 * Copyright (C) 2008 Cocha                                               *
 * http://sourceforge.jp/projects/ecodecotool/                            *
 *                                                                        *
 *  This Program is free software; you can redistribute it and/or modify  *
 *  it under the terms of the GNU General Public License as published by  *
 *  the Free Software Foundation; either version 2, or (at your option)   *
 *  any later version.                                                    *
 *                                                                        *
 *  This Program is distributed in the hope that it will be useful,       *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          *
 *  GNU General Public License for more details.                          *
 *                                                                        *
 *  You should have received a copy of the GNU General Public License     *
 *  along with GNU Make; see the file COPYING.  If not, write to          *
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. *
 *                                                                        *
 **************************************************************************/

#include "EcoDecoTooL.h"

#define DW 196 // Dialog Whdth
#define DH 328 // Dialog Height

#define DIALOG_BUTTON    0
#define DIALOG_LINKLABEL 1
#define DIALOG_EDITBOX   2

#define ERROR_REPLAYGAIN  -1
#define ERROR_MAKE_FOLDER -2


#define IDC_FOLDER_DIALOG 10


struct LOCALEDATA
{
   int nTextID;
   WCHAR *pwText[sizeof_LANGUAGE];
};

static const int g_nComboResourceID[] =
{
   IDC_MAIN_COMBO_CONTAINER, IDC_MAIN_COMBO_VOLUME,
   IDC_MAIN_AAC_COMBO_MODE, IDC_MAIN_AAC_COMBO_ADVANCED, IDC_MAIN_AAC_COMBO_ABR, IDC_MAIN_AAC_COMBO_CBR, IDC_MAIN_AAC_COMBO_VBR,
   IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE, IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR,
   IDC_MAIN_MP3_LAME_COMBO_MODE, IDC_MAIN_MP3_LAME_COMBO_ABR, IDC_MAIN_MP3_LAME_COMBO_CBR, IDC_MAIN_MP3_LAME_COMBO_VBR,
   IDC_MAIN_OGG_COMBO_MODE, IDC_MAIN_OGG_COMBO_ABR, IDC_MAIN_OGG_COMBO_CBR, IDC_MAIN_OGG_COMBO_VBR
};

static LOCALEDATA g_localeErrorMessage[] =
{
   ERROR_REPLAYGAIN,
      L"Invalid value of the volume combobox",
      L"リプレイゲインの小数値が不正です",
   ERROR_MAKE_FOLDER,
      L"Could not create the specifie folder",
      L"出力先フォルダを作成できませんでした。",
   ERROR_MAKE_FOLDER,
      L"Could not create files to the specifie folder",
      L"指定した出力先にファイルを作成できませんでした。"
};

static LOCALEDATA g_localeData[] =
{
   IDC_MAIN_COMBO_CONTAINER,
      L"Convert To Wav;Convert To Aac;Convert To Mp3(Fraunhofer);Convert To Mp3(Lame);Convert To Ogg(aoTuV);Extract Audio",
      L"出力：wav;出力：aac;出力：mp3(Fraunhofer);出力：mp3(Lame);出力：ogg(aoTuv);映像から音声のみ抽出",

   // wav
   IDC_MAIN_WAV_STATIC,
      L"Setting Wav",
      L"wav 出力音質",
   IDC_MAIN_RADIO_WAV1,
      L"Same as input",
      L"入力と同じ音質",
   IDC_MAIN_RADIO_WAV2,
      L"CD quality",
      L"CD音質",
   IDC_MAIN_RADIO_WAV3,
      L"Specify the quality",
      L"音質を指定",

   // aac
   IDC_MAIN_AAC_STATIC,
      L"Setting Aac",
      L"aac 出力設定",
   IDC_MAIN_AAC_COMBO_MODE,
      L"ABR;CBR;VBR",
      L"ABR;CBR;VBR",
   IDC_MAIN_AAC_COMBO_ADVANCED,
      L"Auto;LC-AAC;HE-AAC;HE-AACv2",
      L"自動;LC-AAC;HE-AAC;HE-AACv2",
   IDC_MAIN_AAC_COMBO_ABR,
      L" 16kbps; 20kbps; 24kbps; 28kbps; 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"平均 16kbps;平均 20kbps;平均 24kbps;平均 28kbps;平均 32kbps;平均 40kbps;平均 48kbps;平均 56kbps;平均 64kbps;平均 80kbps;平均 96kbps;平均112kbps;平均128kbps;平均160kbps;平均192kbps;平均224kbps;平均256kbps;平均320kbps",
   IDC_MAIN_AAC_COMBO_CBR,
      L" 16kbps; 20kbps; 24kbps; 28kbps; 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"固定 16kbps;固定 20kbps;固定 24kbps;固定 28kbps;固定 32kbps;固定 40kbps;固定 48kbps;固定 56kbps;固定 64kbps;固定 80kbps;固定 96kbps;固定112kbps;固定128kbps;固定160kbps;固定192kbps;固定224kbps;固定256kbps;固定320kbps",
   IDC_MAIN_AAC_COMBO_VBR,
      L"0.0 (Low bitrate);0.1;0.2;0.3;0.4;0.5;0.6;0.7;0.8;0.9;1.0 (Higi bitrate)",
      L"可変 0.0 (低ビットレート);可変 0.1;可変 0.2;可変 0.3;可変 0.4;可変 0.5;可変 0.6;可変 0.7;可変 0.8;可変 0.9;可変 1.0 (高ビットレート)",
   IDC_MAIN_AAC_STATIC_LINKLABEL,
      L"Need NeroAacEnc.exe",
      L"NeroAacEnc.exeが必要です",

   // fraunhofer
   IDC_MAIN_MP3_FRAUNHOFER_STATIC,
      L"Setting Mp3(Fraunhofer)",
      L"mp3(Fraunhofer) 出力設定",
   IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE,
      L"CBR",
      L"CBR",
   IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR,
      L"  8kbps; 16kbps; 18kbps; 20kbps; 24kbps; 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"固定　8kbps;固定 16kbps;固定 18kbps;固定 20kbps;固定 24kbps;固定 32kbps;固定 40kbps;固定 48kbps;固定 56kbps;固定 64kbps;固定 80kbps;固定 96kbps;固定112kbps;固定128kbps;固定160kbps;固定192kbps;固定224kbps;固定256kbps;固定320kbps",
   IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL,
      L"Need l3codecp.acm",
      L"l3codecp.acmが必要です",

   // lame
   IDC_MAIN_MP3_LAME_STATIC,
      L"Setting Mp3(Lame)",
      L"mp3(Lame) 出力設定",
   IDC_MAIN_MP3_LAME_COMBO_MODE,
      L"ABR;CBR;VBR",
      L"ABR;CBR;VBR",
   IDC_MAIN_MP3_LAME_COMBO_ABR,
      L" 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"平均 32kbps;平均 40kbps;平均 48kbps;平均 56kbps;平均 64kbps;平均 80kbps;平均 96kbps;平均112kbps;平均128kbps;平均160kbps;平均192kbps;平均224kbps;平均256kbps;平均320kbps",
   IDC_MAIN_MP3_LAME_COMBO_CBR,
      L" 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"固定 32kbps;固定 40kbps;固定 48kbps;固定 56kbps;固定 64kbps;固定 80kbps;固定 96kbps;固定112kbps;固定128kbps;固定160kbps;固定192kbps;固定224kbps;固定256kbps;固定320kbps",
   IDC_MAIN_MP3_LAME_COMBO_VBR,
      L" Q9 (Low bitrate); Q8; Q7; Q6; Q5; Q4; Q3; Q2; Q1; Q0 (High bitrate)",
      L"可変 Q9 (低ビットレート);可変 Q8;可変 Q7;可変 Q6;可変 Q5;可変 Q4;可変 Q3;可変 Q2;可変 Q1;可変 Q0 (高ビットレート)",
   IDC_MAIN_MP3_LAME_STATIC_LINKLABEL,
      L"Need lame_enc.dll",
      L"lame_enc.dllが必要です",

   // ogg
   IDC_MAIN_OGG_STATIC,
      L"Setting Ogg(aoTuV)",
      L"ogg(aoTuV) 出力設定",
   IDC_MAIN_OGG_COMBO_MODE,
      L"ABR;CBR;VBR",
      L"ABR;CBR;VBR",
   IDC_MAIN_OGG_COMBO_ABR,
      L" 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"平均 32kbps;平均 40kbps;平均 48kbps;平均 56kbps;平均 64kbps;平均 80kbps;平均 96kbps;平均112kbps;平均128kbps;平均160kbps;平均192kbps;平均224kbps;平均256kbps;平均320kbps",
   IDC_MAIN_OGG_COMBO_CBR,
      L" 32kbps; 40kbps; 48kbps; 56kbps; 64kbps; 80kbps; 96kbps;112kbps;128kbps;160kbps;192kbps;224kbps;256kbps;320kbps",
      L"固定 32kbps;固定 40kbps;固定 48kbps;固定 56kbps;固定 64kbps;固定 80kbps;固定 96kbps;固定112kbps;固定128kbps;固定160kbps;固定192kbps;固定224kbps;固定256kbps;固定320kbps",
   IDC_MAIN_OGG_COMBO_VBR,
      L" -0.1 (Low bitrate);　0.0;　0.1;　0.2;　0.3;　0.4;　0.5;　0.6;　0.7;　0.8;　0.9;　1.0 (High bitrate)",
      L"可変 -0.1 (低ビットレート);可変　0.0;可変　0.1;可変　0.2;可変　0.3;可変　0.4;可変　0.5;可変　0.6;可変　0.7;可変　0.8;可変　0.9;可変　1.0 (高ビットレート)",

   // raw
   IDC_MAIN_RAW_STATIC,
      L"Extract Audio",
      L"映像から音声のみ抽出",
   IDC_MAIN_RAW_STATIC1,
      L"INPUT : avi,flv,mkv,mpg,",
      L"入力可能：avi,flv,mkv,mpg",
   IDC_MAIN_RAW_STATIC2,
      L"mov,mp4,ogm,vob",
      L"mov,mp4,ogm,vob",
   IDC_MAIN_RAW_STATIC3,
      L"OUTPUT : aac,ac3,",
      L"対応音声：aac,ac3",
   IDC_MAIN_RAW_STATIC4,
      L"mp2,mp3.vorbis",
      L"mp2,mp3,vorbis",

   // volume
   IDC_MAIN_STATIC_VOLUME,
      L"Output Volume Settings",
      L"出力の音量設定",
   IDC_MAIN_COMBO_VOLUME,
      L"Same Volume Level;Normalize Tracks;Normalize Albums;Add TrackGain;Add AlbumGain",
      L"入力と同じ音量;Trackノーマライズ;Albumノーマライズ;Trackゲイン;Albumゲイン",

   // folder
   IDC_MAIN_STATIC_FOLDER,
      L"Output Folder :",
      L"出力先フォルダ",
   IDC_MAIN_RADIO_FOLDER1,
      L"Same as Input Folder",
      L"入力と同じフォルダ",
   IDC_MAIN_RADIO_FOLDER2,
      L"Specified Folder",
      L"指定したフォルダ",

   IDC_FOLDER_DIALOG,
      L"Select output folder",
      L"出力先フォルダの選択",

   // file drop
   IDC_MAIN_STATIC_DROP1,
      L"If you drop files or folders here,",
      L"ここにファイルをドロップすれば",
   IDC_MAIN_STATIC_DROP2,
      L"Conversion begins. ",
      L"変換作業が始まります",
   IDC_MAIN_STATIC_DROP3,
      L"",
      L"複数ファイル",
   IDC_MAIN_STATIC_DROP4,
      L"",
      L"フォルダドロップ可",

   // waveformat設定ダイアログ
   IDC_WAVEFORMAT_STATIC1,
      L"SamplingRate :",
      L"周波数 :",
   IDC_WAVEFORMAT_STATIC2,
      L"BitsPerSample :",
      L"ビット数 :",
   IDC_WAVEFORMAT_STATIC3,
      L"Channels :",
      L"チャンネル数 :",
   IDC_WAVEFORMAT_COMBO1,
      L"8,000Hz;11,025Hz;12,000Hz;16,000Hz;22,050Hz;24,000Hz;32,000Hz;44,100Hz;48,000Hz;88,200Hz;96,000Hz;176,400Hz;192,000Hz;Same as input",
      L"8,000Hz;11,025Hz;12,000Hz;16,000Hz;22,050Hz;24,000Hz;32,000Hz;44,100Hz;48,000Hz;88,200Hz;96,000Hz;176,400Hz;192,000Hz;入力と同じ",
   IDC_WAVEFORMAT_COMBO2,
      L" 8bit;16bit;24bit;32bit(INT);32bit(FLOAT);64bit;Same as input",
      L" 8bit;16bit;24bit;32bit(整数);32bit(小数);64bit;入力と同じ",
   IDC_WAVEFORMAT_COMBO3,
      L"Mono(1ch);Stereo(2ch);Same as input",
      L"モノラル(1ch);ステレオ(2ch);入力と同じ"
};
// ----------------------------------------------------------------------------------------------------------------------------
static const int g_nWavResourceID[] =
{ IDC_MAIN_WAV_STATIC, IDC_MAIN_WAV_RADIO1, IDC_MAIN_WAV_RADIO2, IDC_MAIN_WAV_RADIO3, IDC_MAIN_WAV_BUTTON, IDC_MAIN_WAV_STATIC_FORMAT1, IDC_MAIN_WAV_STATIC_FORMAT2};

static int g_nAacResourceID[] =
{ IDC_MAIN_AAC_STATIC, IDC_MAIN_AAC_COMBO_MODE, IDC_MAIN_AAC_COMBO_ADVANCED, IDC_MAIN_AAC_COMBO_ABR, IDC_MAIN_AAC_COMBO_CBR, IDC_MAIN_AAC_COMBO_VBR, IDC_MAIN_AAC_STATIC_LINKLABEL};

static int g_nFraunhoferResourceID[] =
{ IDC_MAIN_MP3_FRAUNHOFER_STATIC, IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE, IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL};

static int g_nLameResourceID[] =
{ IDC_MAIN_MP3_LAME_STATIC, IDC_MAIN_MP3_LAME_COMBO_MODE, IDC_MAIN_MP3_LAME_COMBO_ABR, IDC_MAIN_MP3_LAME_COMBO_CBR, IDC_MAIN_MP3_LAME_COMBO_VBR, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL};

static int g_nOggResourceID[] =
{ IDC_MAIN_OGG_STATIC, IDC_MAIN_OGG_COMBO_MODE, IDC_MAIN_OGG_COMBO_ABR, IDC_MAIN_OGG_COMBO_CBR, IDC_MAIN_OGG_COMBO_VBR};

static int g_nSonomamaResourceID[] =
{ IDC_MAIN_RAW_STATIC, IDC_MAIN_RAW_STATIC1, IDC_MAIN_RAW_STATIC2, IDC_MAIN_RAW_STATIC3, IDC_MAIN_RAW_STATIC4};
// ----------------------------------------------------------------------------------------------------------------------------
struct COMBODATA
{
   struct WAV
   {
      int nSamplingRate[14];
      int nBitsPerSample[7];
      int nFormatTag[7];
      int nChannels[3];
   } wav;

   struct AAC
   {
      int nAbr[18];
      int nCbr[18];
      float fVbr[11];
   } aac;

   struct FRAUNHOFER
   {
      int nCbr[19];
   } fraunhofer;

   struct LAME
   {
      int nAbr[14];
      int nCbr[14];
      int nVbr[10];
   } lame;

   struct OGG
   {
      int nAbr[14];
      int nCbr[14];
      float fVbr[12];
   } ogg;
};

static COMBODATA g_comboData =
{
   8000,11025,12000,16000,22050,24000,32000,44100,48000,88200,96000,176400,192000,0,
   8,16,24,32,32,64, 0,
   1, 1, 1, 1, 3, 3, 0, // 1=WAVE_FORMAT_PCM , 3=WAVE_FORMAT_IEEE_FLOAT
   1, 2, 0,

   16000, 20000, 24000, 28000, 32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   16000, 20000, 24000, 28000, 32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f,

   8000, 16000, 18000, 20000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,

   32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   9, 8, 7, 6, 5, 4, 3, 2, 1, 0,

   32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   32000, 40000, 48000, 56000, 64000, 80000, 96000,112000,128000,160000,192000,224000,256000,320000,
   -0.1f, 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f,
};
// ----------------------------------------------------------------------------------------------------------------------------
static const POINT g_apRgn[] =
{
               {   1,   7},{   1,   5},{   2,   4},{   2,   3},{   3,   2},{   4,   2},{   5,   1},{   7,   1},{   8,   0},
   {DW-8,   0},{DW-7,   1},{DW-5,   1},{DW-4,   2},{DW-3,   2},{DW-2,   3},{DW-2,   4},{DW-1,   5},{DW-1,   7},{  DW,   8},
   {  DW,DH-9},{DW-1,DH-8},{DW-1,DH-6},{DW-2,DH-5},{DW-2,DH-4},{DW-4,DH-2},{DW-5,DH-2},{DW-6,DH-1},{DW-8,DH-1},{DW-9,  DH},
   {   9,DH  },{   8,DH-1},{   6,DH-1},{   5,DH-2},{   4,DH-2},{   2,DH-4},{   2,DH-5},{   1,DH-6},{   1,DH-8},{   0,DH-9},
   {   0,   8}
};

static const POINT g_apFrame1[] =
{
               {   1,   7},{   1,   5},{   2,   4},{   2,   3},{   3,   2},{   4,   2},{   5,   1},{   7,   1},{   8,   0},
   {DW-9,   0},{DW-8,   1},{DW-6,   1},{DW-5,   2},{DW-4,   2},{DW-3,   3},{DW-3,   4},{DW-2,   5},{DW-2,   7},{DW-1,   8},
   {DW-1,DH-9},{DW-2,DH-8},{DW-2,DH-6},{DW-3,DH-5},{DW-3,DH-4},{DW-4,DH-3},{DW-5,DH-3},{DW-6,DH-2},{DW-8,DH-2},{DW-9,DH-1},
   {   8,DH-1},{   7,DH-2},{   5,DH-2},{   4,DH-3},{   3,DH-3},{   2,DH-4},{   2,DH-5},{   1,DH-6},{   1,DH-8},{   0,DH-9},
   {   0,   7}
};

static const POINT g_apFrame2[] =
{
               {   2,   7},{   2,   5},{   3,   4},{   3,   3},{   4,   3},{   5,   2},{   7,   2},{   8,   1},
   {DW-9,   1},{DW-8,   2},{DW-6,   2},{DW-5,   3},{DW-4,   3},{DW-4,   4},{DW-3,   5},{DW-3,   7},{DW-2,   8},
   {DW-2,DH-9},{DW-3,DH-8},{DW-3,DH-6},{DW-4,DH-5},{DW-4,DH-4},{DW-5,DH-4},{DW-6,DH-3},{DW-8,DH-3},{DW-9,DH-2},
   {   8,DH-2},{   7,DH-3},{   5,DH-3},{   4,DH-4},{   3,DH-4},{   3,DH-5},{   2,DH-6},{   2,DH-8},{   1,DH-9},
   {   1,   7}
};

static const POINT g_apFrame3[] =
{
               {   3,   7},{   3,   5},{   5,   3},{   7,   3},{   8,   2},
   {DW-9,   2},{DW-8,   3},{DW-6,   3},{DW-4,   5},{DW-4,   7},{DW-3,   8},
   {DW-3,DH-9},{DW-4,DH-8},{DW-4,DH-6},{DW-6,DH-4},{DW-8,DH-4},{DW-9,DH-3},
   {   8,DH-3},{   7,DH-4},{   5,DH-4},{   3,DH-6},{   3,DH-8},{   2,DH-9},
   {   2,   7}
};


CMainDialog *g_pMyClass = NULL;
// ----------------------------------------------------------------------------------------------------------------------------
CMainDialog::CMainDialog()
{  // コンストラクタ
   g_pMyClass = this;
   m_hRgn = NULL;
   m_nMinResourceID = IDB_BITMAP_MIN1;
   m_nCloseResourceID = IDB_BITMAP_CLOSE1;
   ::ZeroMemory(&m_waveFormat, sizeof(m_waveFormat));

   for(int i=0;i<sizeof_MYPROC;i++)
      m_myProc[i].proc = NULL;

   // 変数の設定
   m_myProc[ 0].nItemType = DIALOG_BUTTON;    m_myProc[ 0].nResourceID = IDC_MAIN_BUTTON_MIN;
   m_myProc[ 1].nItemType = DIALOG_BUTTON;    m_myProc[ 1].nResourceID = IDC_MAIN_BUTTON_CLOSE;
   m_myProc[ 2].nItemType = DIALOG_LINKLABEL; m_myProc[ 2].nResourceID = IDC_MAIN_BUTTON_HELP;
   m_myProc[ 3].nItemType = DIALOG_LINKLABEL; m_myProc[ 3].nResourceID = IDC_MAIN_BUTTON_DROP;
   m_myProc[ 4].nItemType = DIALOG_BUTTON;    m_myProc[ 4].nResourceID = IDC_MAIN_WAV_BUTTON;
   m_myProc[ 5].nItemType = DIALOG_BUTTON;    m_myProc[ 5].nResourceID = IDC_MAIN_BUTTON_FOLDER;
   m_myProc[ 6].nItemType = DIALOG_LINKLABEL; m_myProc[ 6].nResourceID = IDC_MAIN_AAC_STATIC_LINKLABEL;
   m_myProc[ 7].nItemType = DIALOG_LINKLABEL; m_myProc[ 7].nResourceID = IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL;
   m_myProc[ 8].nItemType = DIALOG_LINKLABEL; m_myProc[ 8].nResourceID = IDC_MAIN_MP3_LAME_STATIC_LINKLABEL;
   m_myProc[ 9].nItemType = DIALOG_EDITBOX;   m_myProc[ 9].nResourceID = IDC_MAIN_EDIT_VOLUME;
}
// ----------------------------------------------------------------------------------------------------------------------------
CMainDialog::~CMainDialog()
{  // デストラクタ

}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::ExistsNeroAAC(void)
{  // NeroAACEnc.exeが存在するかチェック

   // EcoDecoTooLフォルダをチェック
   WCHAR awFileName[MAX_PATH];
   ::GetModuleFileName(NULL, awFileName, MAX_PATH);
   ::PathRemoveFileSpec(awFileName);
   ::lstrcat(awFileName, L"\\NeroAACEnc.exe");

   if(::PathFileExists(awFileName) != FALSE)
      return true;

   // システムフォルダをチェック
   ::GetSystemDirectory(awFileName, MAX_PATH);
   ::lstrcat(awFileName, L"\\NeroAACEnc.exe");

   if(::PathFileExists(awFileName) != FALSE)
      return true;

   return false;
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::ExistsFraunhoferPro(void)
{  // l3codecp.acmが存在するかチェック

   HMODULE hDLL = NULL;
   WCHAR awFileName[MAX_PATH];

   // l3codecp.acmを読み込む
   ::GetSystemDirectory(awFileName, MAX_PATH);
   ::lstrcat(awFileName, TEXT("\\l3codecp.acm"));

   if(::PathFileExists(awFileName) != FALSE)
      hDLL = ::LoadLibrary(awFileName);

   if(hDLL == NULL)
      return false;

   SAFE_FREELIBRARY(hDLL);
   return true;
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::ExistsLameEnc(void)
{  // lame_enc.dllが存在するかチェック

   HMODULE hDLL = NULL;

   hDLL = ::LoadLibrary(TEXT("lame_enc.dll"));
   if(hDLL == NULL)
      return false;

   SAFE_FREELIBRARY(hDLL);

   return true;
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::DropFiles(HWND hWnd, HDROP hDrop)
{  // ファイルドロップの処理

   int n, nLength;
   WCHAR awFileName[MAX_PATH];
   WCHAR awOutputFolder[MAX_PATH];

   // ファイル数の取得
   int nDropFiles = (int)::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
   if(nDropFiles <= 0)
      return false;

   m_pDropLinkedList->Clear();

   n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_CONTAINER), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);

   // 出力先指定でoutputFolderのフォルダが実際に存在しないならフォルダを作成する
   if(::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_RADIO_FOLDER2), BM_GETCHECK , 0 , 0) == BST_CHECKED)
   {
      nLength = ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, (LPTSTR)awOutputFolder, MAX_PATH);

      if(nLength == 0)
      {
         ::MessageBox(hWnd, g_localeErrorMessage[1].pwText[m_nLanguage], L"EcoDecoTooL", MB_OK);
         return false;
      }

      ::lstrcat(awOutputFolder, L"\\");

      if(::PathIsDirectory(awOutputFolder) == FALSE)
      {
         if(::SHCreateDirectory(NULL, awOutputFolder) != ERROR_SUCCESS)
         {
            ::MessageBeep(MB_ICONEXCLAMATION);
            ::MessageBox(hWnd, g_localeErrorMessage[1].pwText[m_nLanguage], L"EcoDecoTooL", MB_OK);
            return false;
         }
      }
   }

   ::DragQueryFile(hDrop, 0, awFileName, MAX_PATH);

   // 出力先がCDROMならエラーを出す
   if(::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_RADIO_FOLDER1), BM_GETCHECK , 0 , 0) == BST_CHECKED)
      ::lstrcpy(awOutputFolder, awFileName);
   else
      ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, (LPTSTR)awOutputFolder, MAX_PATH);

   awOutputFolder[3] = NULL;

   if(::GetDriveType(awOutputFolder) == DRIVE_CDROM)
   {
      ::MessageBeep(MB_ICONEXCLAMATION);
      ::MessageBox(hWnd, g_localeErrorMessage[2].pwText[m_nLanguage], L"EcoDecoTooL", MB_OK);
      return false;
   }

   // DropFileをfileListに格納
   for(int i=0;i<nDropFiles;i++)
   {
      ::DragQueryFile(hDrop, i, awFileName, MAX_PATH);
      m_pDropLinkedList->AddList(awFileName);
   }

   return true;
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::GetReplaygain(HWND hWnd, int nResourceID, double *pdGain)
{  // nResourceIDのエディットボックスの内容を小数値に変換する

   WCHAR awText[32];
   ::GetDlgItemText(hWnd, nResourceID, awText, 32);

   WCHAR *pwEndPtr;

   *pdGain = ::wcstod(awText, &pwEndPtr);

   if(::lstrlen(pwEndPtr) > 0)
   {
      ::MessageBox(hWnd, g_localeErrorMessage[0].pwText[m_nLanguage], L"EcoDecoTooL", MB_OK);
      return false;
   }

   return true;
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::DrawHoverButton(DRAWITEMSTRUCT *pDrawItem, int nResourceID)
{
   HDC hmDC;
   HBITMAP hBitmap = NULL;

   hBitmap = ::LoadBitmap(::GetModuleHandle(NULL), MAKEINTRESOURCE(nResourceID));

   if(hBitmap != NULL)
   {
      hmDC = ::CreateCompatibleDC(pDrawItem->hDC);
      ::SelectObject(hmDC, hBitmap);
      ::BitBlt(pDrawItem->hDC, 0, 0, 16, 14, hmDC, 0, 0, SRCCOPY);
      ::DeleteDC(hmDC);
      ::DeleteObject(hBitmap);
   }
}
// ----------------------------------------------------------------------------------------------------------------------------
WCHAR *CMainDialog::GetLocalText(int nTextID)
{
   int nArraySize = sizeof(g_localeData) / sizeof(g_localeData[0]);

   for(int i=0;i<nArraySize;i++)
   {
      if(g_localeData[i].nTextID == nTextID)
         return g_localeData[i].pwText[m_nLanguage];
   }

   return NULL;
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::PrepareComboBox(HWND hWnd, int nResourceID)
{  // 項目をコンボボックスに登録する

   WCHAR awItem[64];
   int i, nStartPos = 0;

   // nResourceIDの項目を取得する
   WCHAR *pwText = GetLocalText(nResourceID);
   if(pwText == NULL)
      return;

   // セミコロン区切りの項目を登録する
   int nTextLength = ::lstrlen(pwText);
   if(nTextLength <= 0)
      return;

   for(i=0;i<nTextLength;i++)
   {
      if(pwText[i] != ';')
      {
         awItem[i-nStartPos] = pwText[i];
      }
      else
      {
         awItem[i-nStartPos] = '\0';
         ::SendMessage(::GetDlgItem(hWnd, nResourceID), CB_ADDSTRING, 0, (LPARAM)awItem);

         nStartPos = i+1;
      }
   }

   awItem[i-nStartPos] = '\0';
   ::SendMessage(::GetDlgItem(hWnd, nResourceID), CB_ADDSTRING, 0, (LPARAM)awItem);
}
// ----------------------------------------------------------------------------------------------------------------------------
int CMainDialog::GetPrivateProfileInt(WCHAR *pwSection, WCHAR *pwKey, int nMin, int nMax, int nDefault, WCHAR *pwIniFileName)
{  // iniファイルからintデータを読み込む。取得データがnMin～nMax以外ならnDefaultを返す
   int n;
   n = (int)::GetPrivateProfileInt(pwSection, pwKey, nDefault, pwIniFileName);

   if(n < nMin)
      n = nDefault;
   else if(nMax < n)
      n = nDefault;

   return n;
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::WriteIniFile(WCHAR *pwIniFileName, HWND hWnd, int nResourceID, WCHAR *pwSection)
{  // iniファイルに値を出力する
   int n;
   WCHAR awKey[16], awText[16];

   n = ::SendMessage(::GetDlgItem(hWnd, nResourceID), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
   ::wsprintf(awText, L"%d", n);
   ::wsprintf(awKey, L"%d", nResourceID);
   ::WritePrivateProfileString(pwSection, awKey, awText, pwIniFileName);
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::SetComboBoxCursel(WCHAR *pwIniFileName, HWND hWnd, int nResourceID)
{  // iniファイルから設定値を読み込み、コンボボックスの位置をセットする

   int n, nCount;
   WCHAR awKey[16];

   ::wsprintf(awKey, L"%d", nResourceID);
   n = (int)::GetPrivateProfileInt(L"ComboBox", awKey, 0, pwIniFileName);

   nCount = ::SendMessage(::GetDlgItem(hWnd, nResourceID), CB_GETCOUNT, (WPARAM)0, (LPARAM)0);

   if(n < 0 || nCount <= n)
      n = 0;

   ::SendMessage(::GetDlgItem(hWnd, nResourceID), CB_SETCURSEL, (WPARAM)n, (LPARAM)0);
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::LoadSetting(SETTINGDATA *pSettingData)
{  // EcoDecoTooL.iniから設定を読み込む

   int n, nArraySize;
   WCHAR awKey[16], awText[MAX_PATH], awIniFileName[MAX_PATH];

   // iniファイル名を取得する
   ::GetModuleFileName(NULL, awIniFileName, MAX_PATH);
   ::PathRemoveFileSpec(awIniFileName);
   ::lstrcat(awIniFileName, L"\\EcoDecoTooL.ini");

   // 出力先フォルダの設定
   n = ::GetPrivateProfileInt(L"Radio", L"outfolder", 1, awIniFileName);
   if(n == 1)
   {
      pSettingData->nOutputFolder = 1;
      ::GetPrivateProfileString(L"Edit", L"outfolder", L"d:\\", pSettingData->awOutputFolder, MAX_PATH, awIniFileName);
   }
   else
   {
      pSettingData->nOutputFolder = 0;
      ::lstrcpy(pSettingData->awOutputFolder, L"");
   }

   ::wsprintf(awKey, L"%d", IDC_MAIN_COMBO_CONTAINER);
   pSettingData->nContainerType = GetPrivateProfileInt(L"ComboBox", awKey, 0, sizeof_CONTAINER-1, 8, awIniFileName);

   ::ZeroMemory(&pSettingData->wf, sizeof(pSettingData->wf));

   if(pSettingData->nContainerType == CONTAINER_WAV)
   {  // wav
      n = ::GetPrivateProfileInt(L"Radio", L"wav", 0, awIniFileName);

      if(n == 1)
      {
         pSettingData->wf.nSamplesPerSec = 44100;
         pSettingData->wf.wBitsPerSample = 16;
         pSettingData->wf.nChannels = 2;
         pSettingData->wf.wFormatTag = 1;
      }
      else if(n == 2)
      {
         nArraySize = sizeof(g_comboData.wav.nSamplingRate) / sizeof(g_comboData.wav.nSamplingRate[0]);
         n = GetPrivateProfileInt(L"combo_wav", L"combo1", 0, nArraySize-1, 8, awIniFileName);
         pSettingData->wf.nSamplesPerSec = g_comboData.wav.nSamplingRate[n];

         nArraySize = sizeof(g_comboData.wav.nBitsPerSample) / sizeof(g_comboData.wav.nBitsPerSample[0]);
         n = GetPrivateProfileInt(L"combo_wav", L"combo2", 0, nArraySize-1, 8, awIniFileName);
         pSettingData->wf.wBitsPerSample = g_comboData.wav.nBitsPerSample[n];
         pSettingData->wf.wFormatTag = g_comboData.wav.nFormatTag[n];

         nArraySize = sizeof(g_comboData.wav.nChannels) / sizeof(g_comboData.wav.nChannels[0]);
         n = GetPrivateProfileInt(L"combo_wav", L"combo3", 0, nArraySize-1, 8, awIniFileName);
         pSettingData->wf.nChannels = g_comboData.wav.nChannels[n];
      }
   }
   else if(pSettingData->nContainerType == CONTAINER_AAC)
   {  // aac
      if(ExistsNeroAAC() == false)
      {
         ::MessageBox(NULL, GetLocalText(IDC_MAIN_AAC_STATIC_LINKLABEL), L"EcoDecoTooL", MB_OK);
         return false;
      }

      ::wsprintf(awKey, L"%d", IDC_MAIN_AAC_COMBO_MODE);
      pSettingData->nEncodeMode = GetPrivateProfileInt(L"ComboBox", awKey, 0, 2, 0, awIniFileName);

      ::wsprintf(awKey, L"%d", IDC_MAIN_AAC_COMBO_ADVANCED);
      pSettingData->nAdvancedMode = GetPrivateProfileInt(L"ComboBox", awKey, 0, 3, 0, awIniFileName);

      if(pSettingData->nEncodeMode == 0)
      {  // ABR
         ::wsprintf(awKey, L"%d", IDC_MAIN_AAC_COMBO_ABR);
         nArraySize = sizeof(g_comboData.aac.nAbr) / sizeof(g_comboData.aac.nAbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.aac.nAbr[n];
      }
      else if(pSettingData->nEncodeMode == 1)
      {  // CBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_AAC_COMBO_CBR);
         nArraySize = sizeof(g_comboData.aac.nCbr) / sizeof(g_comboData.aac.nCbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.aac.nCbr[n];
      }
      else
      {  // VBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_AAC_COMBO_VBR);
         nArraySize = sizeof(g_comboData.aac.fVbr) / sizeof(g_comboData.aac.fVbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->fVBR = g_comboData.aac.fVbr[n];
      }
   }
   else if(pSettingData->nContainerType == CONTAINER_MP3_FRAUNHOFER)
   {  // fraunhofer
      if(ExistsFraunhoferPro() == false)
      {
         ::MessageBox(NULL, GetLocalText(IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL), L"EcoDecoTooL", MB_OK);
         return false;
      }

      pSettingData->nEncodeMode = 1;

      // CBR
      ::wsprintf(awKey, L"%d", IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR);
      nArraySize = sizeof(g_comboData.fraunhofer.nCbr) / sizeof(g_comboData.fraunhofer.nCbr[0]);
      n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
      pSettingData->nABRCBR = g_comboData.fraunhofer.nCbr[n];
   }
   else if(pSettingData->nContainerType == CONTAINER_MP3_LAME)
   {  // Lame
      if(ExistsLameEnc() == false)
      {
         ::MessageBox(NULL, GetLocalText(IDC_MAIN_MP3_LAME_STATIC_LINKLABEL), L"EcoDecoTooL", MB_OK);
         return false;
      }

      ::wsprintf(awKey, L"%d", IDC_MAIN_MP3_LAME_COMBO_MODE);
      pSettingData->nEncodeMode = GetPrivateProfileInt(L"ComboBox", awKey, 0, 2, 0, awIniFileName);

      if(pSettingData->nEncodeMode == 0)
      {  // ABR
         ::wsprintf(awKey, L"%d", IDC_MAIN_MP3_LAME_COMBO_ABR);
         nArraySize = sizeof(g_comboData.lame.nAbr) / sizeof(g_comboData.lame.nAbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.lame.nAbr[n];
      }
      else if(pSettingData->nEncodeMode == 1)
      {  // CBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_MP3_LAME_COMBO_CBR);
         nArraySize = sizeof(g_comboData.lame.nCbr) / sizeof(g_comboData.lame.nCbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.lame.nCbr[n];
      }
      else
      {  // VBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_MP3_LAME_COMBO_VBR);
         nArraySize = sizeof(g_comboData.lame.nVbr) / sizeof(g_comboData.lame.nVbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nVBR = g_comboData.lame.nVbr[n];
      }
   }
   else if(pSettingData->nContainerType == CONTAINER_OGG)
   {  // Ogg
      ::wsprintf(awKey, L"%d", IDC_MAIN_OGG_COMBO_MODE);
      pSettingData->nEncodeMode = GetPrivateProfileInt(L"ComboBox", awKey, 0, 2, 0, awIniFileName);

      if(pSettingData->nEncodeMode == 0)
      {  // ABR
         ::wsprintf(awKey, L"%d", IDC_MAIN_OGG_COMBO_ABR);
         nArraySize = sizeof(g_comboData.ogg.nAbr) / sizeof(g_comboData.ogg.nAbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.ogg.nAbr[n];
      }
      else if(pSettingData->nEncodeMode == 1)
      {  // CBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_OGG_COMBO_CBR);
         nArraySize = sizeof(g_comboData.ogg.nCbr) / sizeof(g_comboData.ogg.nCbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->nABRCBR = g_comboData.ogg.nCbr[n];
      }
      else
      {  // VBR
         ::wsprintf(awKey, L"%d", IDC_MAIN_OGG_COMBO_VBR);
         nArraySize = sizeof(g_comboData.ogg.fVbr) / sizeof(g_comboData.ogg.fVbr[0]);
         n = GetPrivateProfileInt(L"ComboBox", awKey, 0, nArraySize-1, 0, awIniFileName);
         pSettingData->fVBR = g_comboData.ogg.fVbr[n];
      }
   }
   else  // if(pSettingData->nContainerType == CONTAINER_RAW)
   {
      pSettingData->nContainerType = CONTAINER_RAW;
   }

   if(pSettingData->nContainerType == CONTAINER_WAV || pSettingData->nContainerType == CONTAINER_MP3_FRAUNHOFER ||
      pSettingData->nContainerType == CONTAINER_MP3_LAME || pSettingData->nContainerType == CONTAINER_OGG)
   {
      ::wsprintf(awKey, L"%d", IDC_MAIN_COMBO_VOLUME);
      pSettingData->nGainMode = GetPrivateProfileInt(L"ComboBox", awKey, 0, 4, 0, awIniFileName);

      if(pSettingData->nGainMode != 0)
      {
         WCHAR *pwEndPtr = NULL;
         ::GetPrivateProfileString(L"Edit", L"volume", L"89.0", awText, MAX_PATH, awIniFileName);
         pSettingData->dGain = ::wcstod(awText, &pwEndPtr);
      }
   }

   return true;
}
// ----------------------------------------------------------------------------------------------------------------------------
bool CMainDialog::GetSettingData(HWND hWnd)
{  // 設定値をm_pSettingDataに格納する

   bool flag;
   int n;
//   int n, nArraySize;

   m_pSettingData->nContainerType = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_CONTAINER), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);

   if(::IsDlgButtonChecked(hWnd, IDC_MAIN_RADIO_FOLDER1) == BST_CHECKED)
      m_pSettingData->nOutputFolder = 0;
   else
   {
      m_pSettingData->nOutputFolder = 1;
      ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, (LPTSTR)m_pSettingData->awOutputFolder, MAX_PATH);
   }

   if(m_pSettingData->nContainerType == 0)
   {  // wav
      if(::IsDlgButtonChecked(hWnd, IDC_MAIN_WAV_RADIO1) == BST_CHECKED)
      {
         m_pSettingData->wf.nSamplesPerSec = 0;
         m_pSettingData->wf.wBitsPerSample = 0;
         m_pSettingData->wf.nChannels = 0;
         m_pSettingData->wf.wFormatTag = 0;
      }
      else if(::IsDlgButtonChecked(hWnd, IDC_MAIN_WAV_RADIO2) == BST_CHECKED)
      {
         m_pSettingData->wf.nSamplesPerSec = 44100;
         m_pSettingData->wf.wBitsPerSample = 16;
         m_pSettingData->wf.nChannels = 2;
         m_pSettingData->wf.wFormatTag = 1;
      }
      else
      {
         m_pSettingData->wf.nSamplesPerSec = m_waveFormat.nSamplesPerSec;
         m_pSettingData->wf.wBitsPerSample = m_waveFormat.wBitsPerSample;
         m_pSettingData->wf.nChannels = m_waveFormat.nChannels;
         m_pSettingData->wf.wFormatTag = m_waveFormat.wFormatTag;
      }
 
      m_pSettingData->nGainMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      if(m_pSettingData->nGainMode != 0)
      {
         flag = GetReplaygain(hWnd, IDC_MAIN_EDIT_VOLUME, &m_pSettingData->dGain);
         if(flag == false) return false;
      }

      return true;
  }
   else if(m_pSettingData->nContainerType == 1)
   {  // aac
      m_pSettingData->nEncodeMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_MODE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      m_pSettingData->nAdvancedMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_ADVANCED), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);

      if(m_pSettingData->nEncodeMode == 0)
      {  // ABR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_ABR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.aac.nAbr[n];
      }
      else if(m_pSettingData->nEncodeMode == 1)
      {  // CBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_CBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.aac.nCbr[n];
      }
      else
      {  // VBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_VBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->fVBR = g_comboData.aac.fVbr[n];
      }

      m_pSettingData->nGainMode = 0;
      return true;
   }
   else if(m_pSettingData->nContainerType == 2)
   {  // fraunhofer

      // CBR
      m_pSettingData->nEncodeMode = 1;

      n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      m_pSettingData->nABRCBR = g_comboData.fraunhofer.nCbr[n];

      m_pSettingData->nGainMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      if(m_pSettingData->nGainMode != 0)
      {
         flag = GetReplaygain(hWnd, IDC_MAIN_EDIT_VOLUME, &m_pSettingData->dGain);
         if(flag == false) return false;
      }

      return true;
   }
   else if(m_pSettingData->nContainerType == 3)
   {  // lame
      m_pSettingData->nEncodeMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_MODE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);

      if(m_pSettingData->nEncodeMode == 0)
      {  // ABR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_ABR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.lame.nAbr[n];
      }
      else if(m_pSettingData->nEncodeMode == 1)
      {  // CBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_CBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.lame.nCbr[n];
      }
      else
      {  // VBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_VBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nVBR = g_comboData.lame.nVbr[n];
      }

      m_pSettingData->nGainMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      if(m_pSettingData->nGainMode != 0)
      {
         flag = GetReplaygain(hWnd, IDC_MAIN_EDIT_VOLUME, &m_pSettingData->dGain);
         if(flag == false) return false;
      }

      return true;
   }
   else if(m_pSettingData->nContainerType == 4)
   {  // ogg
      m_pSettingData->nEncodeMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_MODE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);

      if(m_pSettingData->nEncodeMode == 0)
      {  // ABR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_ABR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.ogg.nAbr[n];
      }
      else if(m_pSettingData->nEncodeMode == 1)
      {  // CBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_CBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->nABRCBR = g_comboData.ogg.nCbr[n];
      }
      else
      {  // VBR
         n = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_VBR), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         m_pSettingData->fVBR = g_comboData.ogg.fVbr[n];
      }

      m_pSettingData->nGainMode = ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
      if(m_pSettingData->nGainMode != 0)
      {
         flag = GetReplaygain(hWnd, IDC_MAIN_EDIT_VOLUME, &m_pSettingData->dGain);
         if(flag == false) return false;
      }

      return true;
   }
   else if(m_pSettingData->nContainerType == 5)
   {  // そのまま抽出
      return true;
   }

   return false;
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::SelectMode(HWND hWnd, int nModeResourceID, int nModeIndex)
{  // ABR,CBR,VBRのコンボボックスの値が変更された場合に呼ばれる

   int nCmdShow[3] = {SW_HIDE, SW_HIDE, SW_HIDE};

   if(0 <= nModeIndex && nModeIndex <= 2)
      nCmdShow[nModeIndex] = SW_SHOW;

   if(nModeResourceID == IDC_MAIN_AAC_COMBO_MODE)
   {  // AAC
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_ABR), nCmdShow[0]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_CBR), nCmdShow[1]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_VBR), nCmdShow[2]);
   }
   else if(nModeResourceID == IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE)
   {  // FRAUNHOFER
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR), SW_SHOW);
   }
   else if(nModeResourceID == IDC_MAIN_MP3_LAME_COMBO_MODE)
   {  // LAME
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_ABR), nCmdShow[0]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_CBR), nCmdShow[1]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_VBR), nCmdShow[2]);
   }
   else if(nModeResourceID == IDC_MAIN_OGG_COMBO_MODE)
   {  // OGG
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_ABR), nCmdShow[0]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_CBR), nCmdShow[1]);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_VBR), nCmdShow[2]);
   }
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::SelectFolder(HWND hWnd)
{  // フォルダ選択ダイアログを表示してフォルダを選ばせる

   BROWSEINFO bInfo;
   LPITEMIDLIST pIDList = NULL;
   WCHAR awDisplayName[MAX_PATH];

   // BROWSEINFO構造体に値を設定
   bInfo.hwndOwner      = hWnd;
   bInfo.lpfn           = this->SHBrowseProc;
   bInfo.pidlRoot       = NULL;
   bInfo.pszDisplayName = awDisplayName;
   bInfo.lpszTitle      = GetLocalText(IDC_FOLDER_DIALOG);
   bInfo.ulFlags        = BIF_DONTGOBELOWDOMAIN | BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_NEWDIALOGSTYLE;
   bInfo.lParam         = (LPARAM)0; 

   WCHAR awFolder[MAX_PATH];
   int length = ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, (LPTSTR)awFolder, MAX_PATH);
   if(length > 0)
      bInfo.lParam = (LPARAM)awFolder; 
   else
      bInfo.lParam = (LPARAM)TEXT("c:\\"); 
    
   // フォルダ選択ダイアログを表示
   pIDList = ::SHBrowseForFolder(&bInfo);
   if(pIDList == NULL)
      return;

   // ItemIDListをパス名に変換します
   if(!::SHGetPathFromIDList(pIDList, awDisplayName))
   {
      // エラーの場合
      if(pIDList != NULL)
         ::CoTaskMemFree(pIDList);

      return;
   }

   // IDC_MAIN_EDIT_FOLDERを更新
   ::SetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, (LPCTSTR)awDisplayName);

   // メモリ解放
   ::CoTaskMemFree(pIDList);
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::SelectContainer(HWND hWnd, int nContainerIndex)
{  // 出力コンテナ形式が変更された場合に呼ばれる

   int i, nArraySize, nCmdShow;

   // wav
   if(nContainerIndex == 0) nCmdShow = SW_SHOW;
   else                     nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nWavResourceID) / sizeof(g_nWavResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nWavResourceID[i]), nCmdShow);

   // aac
   if(nContainerIndex == 1 && m_bExistsNeroAacEnc == true) nCmdShow = SW_SHOW;
   else                                                    nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nAacResourceID) / sizeof(g_nAacResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nAacResourceID[i]), nCmdShow);

   if(nContainerIndex == 1)
   {
      if(m_bExistsNeroAacEnc == true)
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC_LINKLABEL), SW_HIDE);
         SelectMode(hWnd, IDC_MAIN_AAC_COMBO_MODE, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_MODE), CB_GETCURSEL, 0, 0));
      }
      else
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC), SW_SHOW);
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC_LINKLABEL), SW_SHOW);
      }
   }

   // fraunhofer
   if(nContainerIndex == 2 && m_bExistsFraunhoferPro == true) nCmdShow = SW_SHOW;
   else                                                       nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nFraunhoferResourceID) / sizeof(g_nFraunhoferResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nFraunhoferResourceID[i]), nCmdShow);

   if(nContainerIndex == 2)
   {
      if(m_bExistsFraunhoferPro == true)
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL), SW_HIDE);
         SelectMode(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE), CB_GETCURSEL, 0, 0));
      }
      else
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC), SW_SHOW);
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL), SW_SHOW);
      }
   }

   // lame
   if(nContainerIndex == 3 && m_bExistsLameEnc == true) nCmdShow = SW_SHOW;
   else                                                 nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nLameResourceID) / sizeof(g_nLameResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nLameResourceID[i]), nCmdShow);

   if(nContainerIndex == 3)
   {
      if(m_bExistsLameEnc == true)
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL), SW_HIDE);
         SelectMode(hWnd, IDC_MAIN_MP3_LAME_COMBO_MODE, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_MODE), CB_GETCURSEL, 0, 0));
      }
      else
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC), SW_SHOW);
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL), SW_SHOW);
      }
   }

   // ogg
   if(nContainerIndex == 4) nCmdShow = SW_SHOW;
   else                     nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nOggResourceID) / sizeof(g_nOggResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nOggResourceID[i]), nCmdShow);

   if(nContainerIndex == 4)
   {
      SelectMode(hWnd, IDC_MAIN_OGG_COMBO_MODE, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_MODE), CB_GETCURSEL, 0, 0));
   }

   // そのまま抽出
   if(nContainerIndex == 5) nCmdShow = SW_SHOW;
   else                     nCmdShow = SW_HIDE;

   nArraySize = sizeof(g_nSonomamaResourceID) / sizeof(g_nSonomamaResourceID[0]);
   for(i=0;i<nArraySize;i++)
      ::ShowWindow(::GetDlgItem(hWnd, g_nSonomamaResourceID[i]), nCmdShow);

   // 音量変更の表示
   if(nContainerIndex == CONTAINER_WAV || (nContainerIndex == CONTAINER_MP3_FRAUNHOFER && m_bExistsFraunhoferPro == true) ||
      (nContainerIndex == CONTAINER_MP3_LAME && m_bExistsLameEnc == true) || nContainerIndex == CONTAINER_OGG)
   {
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_VOLUME), SW_SHOW);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), SW_SHOW);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_SHOW);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_SHOW);

      if(::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0) == 0)
      {  // 出力音量 = 入力音量の場合
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_HIDE);
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_HIDE);
      }
      else
      {
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_SHOW);
         ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_SHOW);
      }
   }
   else
   {
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_VOLUME), SW_HIDE);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), SW_HIDE);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_HIDE);
      ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_HIDE);
   }
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::OnCreate(HWND hWnd)
{  // フォーム作成時に呼ばれる

   int nArraySize;

   m_bExistsNeroAacEnc = ExistsNeroAAC();
   m_bExistsFraunhoferPro = ExistsFraunhoferPro();
   m_bExistsLameEnc = ExistsLameEnc();

/*
m_bExistsNeroAacEnc = true;
m_bExistsFraunhoferPro = true;
m_bExistsLameEnc = true;
m_bExistsThomsonEnc = true;

m_bExistsNeroAacEnc = false;
m_bExistsFraunhoferPro = false;
m_bExistsLameEnc = false;
m_bExistsThomsonEnc = false;
*/
   // リソーステキストを指定言語に変更する
   ::SetDlgItemText(hWnd, IDC_MAIN_WAV_STATIC, GetLocalText(IDC_MAIN_WAV_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_RADIO_WAV1,                      GetLocalText(IDC_MAIN_RADIO_WAV1));
   ::SetDlgItemText(hWnd, IDC_MAIN_RADIO_WAV2,                      GetLocalText(IDC_MAIN_RADIO_WAV2));
   ::SetDlgItemText(hWnd, IDC_MAIN_RADIO_WAV3,                      GetLocalText(IDC_MAIN_RADIO_WAV3));
   ::SetDlgItemText(hWnd, IDC_MAIN_AAC_STATIC,                      GetLocalText(IDC_MAIN_AAC_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_AAC_STATIC_LINKLABEL,            GetLocalText(IDC_MAIN_AAC_STATIC_LINKLABEL));
   ::SetDlgItemText(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC,           GetLocalText(IDC_MAIN_MP3_FRAUNHOFER_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL, GetLocalText(IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL));
   ::SetDlgItemText(hWnd, IDC_MAIN_MP3_LAME_STATIC,                 GetLocalText(IDC_MAIN_MP3_LAME_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL,       GetLocalText(IDC_MAIN_MP3_LAME_STATIC_LINKLABEL));
   ::SetDlgItemText(hWnd, IDC_MAIN_OGG_STATIC,                      GetLocalText(IDC_MAIN_OGG_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_RAW_STATIC,                      GetLocalText(IDC_MAIN_RAW_STATIC));
   ::SetDlgItemText(hWnd, IDC_MAIN_RAW_STATIC1,                     GetLocalText(IDC_MAIN_RAW_STATIC1));
   ::SetDlgItemText(hWnd, IDC_MAIN_RAW_STATIC2,                     GetLocalText(IDC_MAIN_RAW_STATIC2));
   ::SetDlgItemText(hWnd, IDC_MAIN_RAW_STATIC3,                     GetLocalText(IDC_MAIN_RAW_STATIC3));
   ::SetDlgItemText(hWnd, IDC_MAIN_RAW_STATIC4,                     GetLocalText(IDC_MAIN_RAW_STATIC4));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_VOLUME,                   GetLocalText(IDC_MAIN_STATIC_VOLUME));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_FOLDER,                   GetLocalText(IDC_MAIN_STATIC_FOLDER));
   ::SetDlgItemText(hWnd, IDC_MAIN_RADIO_FOLDER1,                   GetLocalText(IDC_MAIN_RADIO_FOLDER1));
   ::SetDlgItemText(hWnd, IDC_MAIN_RADIO_FOLDER2,                   GetLocalText(IDC_MAIN_RADIO_FOLDER2));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_DROP1,                    GetLocalText(IDC_MAIN_STATIC_DROP1));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_DROP2,                    GetLocalText(IDC_MAIN_STATIC_DROP2));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_DROP3,                    GetLocalText(IDC_MAIN_STATIC_DROP3));
   ::SetDlgItemText(hWnd, IDC_MAIN_STATIC_DROP4,                    GetLocalText(IDC_MAIN_STATIC_DROP4));

   // コンボボックスの高さを指定する
   nArraySize = sizeof(g_nComboResourceID) / sizeof(g_nComboResourceID[0]);

   for(int i=0;i<nArraySize;i++)
      ::SendMessage(::GetDlgItem(hWnd, g_nComboResourceID[i]), CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)13);

   // ウィンドウの位置と大きさを設定
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_MIN),           NULL, 165,   7,  11, 11, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_CLOSE),         NULL, 179,   7,  11, 11, SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_HELP),       NULL, 170,  55,  16, 16, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_DROP),       NULL, 170, 245,  16, 16, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_WAV_FORMAT), NULL, 112, 110,  16, 14, SWP_NOMOVE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_BUTTON_FOLDER),     NULL,   0,   0, 16, 14, SWP_NOMOVE|SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC),           NULL,  27,  57,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_MODE),       NULL,  30,  73,  60, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_ADVANCED),     NULL,  95,  73,  80, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_ABR),        NULL,  30,  94, 145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_CBR),        NULL,  30,  94, 145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_COMBO_VBR),        NULL,  30,  94, 145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC_LINKLABEL), NULL,  30,  80,  0,  0, SWP_NOSIZE|SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC),           NULL,  27,  57,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE),       NULL,  30,  73,  60, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_COMBO_CBR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL), NULL,  30,  80,  0, 0, SWP_NOSIZE|SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC),           NULL,  27,  57,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_MODE),       NULL,  30,  73,  60, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_ABR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_CBR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_COMBO_VBR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL), NULL,  30,  80,  0, 0, SWP_NOSIZE|SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_OGG_STATIC),           NULL,  27,  57,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_MODE),       NULL,  30,  73,  60, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_ABR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_CBR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_OGG_COMBO_VBR),        NULL,  30,  94,  145, 10, SWP_NOZORDER);

   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_RAW_STATIC),     NULL,  27,  57,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_RAW_STATIC1),     NULL,  30,  75,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_RAW_STATIC2),     NULL,  90,  87,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_RAW_STATIC3),     NULL,  30, 107,   0,  0, SWP_NOSIZE|SWP_NOZORDER);
   ::SetWindowPos(::GetDlgItem(hWnd, IDC_MAIN_RAW_STATIC4),     NULL,  90, 119,   0,  0, SWP_NOSIZE|SWP_NOZORDER);

   // iniファイルから設定情報を読み出す
   WCHAR awText[MAX_PATH], awIniFileName[MAX_PATH];
   int n;

   // iniファイル名を取得する
   ::GetModuleFileName(NULL, awIniFileName, MAX_PATH);
   ::PathRemoveFileSpec(awIniFileName);
   ::lstrcat(awIniFileName, L"\\EcoDecoTooL.ini");

   // 出力先フォルダの設定
   n = ::GetPrivateProfileInt(L"Radio", L"outfolder", 0, awIniFileName);
   if(n == 1)
      ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_FOLDER1, IDC_MAIN_RADIO_FOLDER2, IDC_MAIN_RADIO_FOLDER2);
   else
      ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_FOLDER1, IDC_MAIN_RADIO_FOLDER2, IDC_MAIN_RADIO_FOLDER1);

   ::GetPrivateProfileString(L"Edit", L"outfolder", L"d:\\", awText, MAX_PATH, awIniFileName);
   ::SetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, awText);

   // 言語に応じたコンボボックスを準備する
   nArraySize = sizeof(g_nComboResourceID) / sizeof(g_nComboResourceID[0]);

   for(int i=0;i<nArraySize;i++)
   {
      PrepareComboBox(hWnd, g_nComboResourceID[i]);

      // コンボボックスの選択位置を設定する
      SetComboBoxCursel(awIniFileName, hWnd, g_nComboResourceID[i]);
   }

   // wavラジオボタンの設定
   n = ::GetPrivateProfileInt(L"Radio", L"wav", 0, awIniFileName);
   switch(n)
   {
   case 0:  ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_WAV1, IDC_MAIN_RADIO_WAV3, IDC_MAIN_RADIO_WAV1); break;
   case 1:  ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_WAV1, IDC_MAIN_RADIO_WAV3, IDC_MAIN_RADIO_WAV2); break;
   case 2:  ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_WAV1, IDC_MAIN_RADIO_WAV3, IDC_MAIN_RADIO_WAV3); break;
   default: ::CheckRadioButton(hWnd, IDC_MAIN_RADIO_WAV1, IDC_MAIN_RADIO_WAV3, IDC_MAIN_RADIO_WAV1); break;
   }

   // コンボボックスのカーソルを指定する
   SelectContainer(hWnd, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_CONTAINER), CB_GETCURSEL, 0, 0));

   // 音量の設定
   ::GetPrivateProfileString(L"Edit", L"volume", L"89.0", awText, MAX_PATH, awIniFileName);
   ::SetDlgItemText(hWnd, IDC_MAIN_EDIT_VOLUME, awText);

   // IDC_WAV_STATIC_FORMAT1とIDC_WAV_STATIC_FORMAT2を更新する
   n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo1", 8, awIniFileName);
   if(n < 0 || 13 < n) n = 8;
   m_waveFormat.nSamplesPerSec = g_comboData.wav.nSamplingRate[n];

   n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo2", 1, awIniFileName);
   if(n < 0 || 6 < n) n = 1;
   m_waveFormat.wBitsPerSample = g_comboData.wav.nBitsPerSample[n];
   m_waveFormat.wFormatTag = g_comboData.wav.nFormatTag[n];

   n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo3", 1, awIniFileName);
   if(n < 0 || 2 < n) n = 1;
   m_waveFormat.nChannels = g_comboData.wav.nChannels[n];

   if(m_waveFormat.nSamplesPerSec == 0)
      ::lstrcpy(awText, L"");
   else
      ::wsprintf(awText, L"%3d,%03dHz", g_pMyClass->m_waveFormat.nSamplesPerSec/1000, g_pMyClass->m_waveFormat.nSamplesPerSec%1000);

   ::SetDlgItemText(hWnd, IDC_MAIN_WAV_STATIC_FORMAT1, awText);

   if(g_pMyClass->m_waveFormat.wBitsPerSample == 0 && g_pMyClass->m_waveFormat.nChannels == 0)
   {
      ::lstrcpy(awText, L"");
   }
   else
   {
      if(m_waveFormat.wBitsPerSample != 0 && m_waveFormat.nChannels != 0)
         ::wsprintf(awText, L" %2dbit %dch", m_waveFormat.wBitsPerSample, m_waveFormat.nChannels);
      else if(m_waveFormat.wBitsPerSample == 0)
         ::wsprintf(awText, L" %dch", m_waveFormat.nChannels);
      else if(m_waveFormat.nChannels == 0)
         ::wsprintf(awText, L" %2dbit", m_waveFormat.wBitsPerSample);
   }

   ::SetDlgItemText(hWnd, IDC_MAIN_WAV_STATIC_FORMAT2, awText);
//         ::InvalidateRect(hWnd, NULL, TRUE);


   // ウィンドウ位置を設定する
   RECT r1;
   POINT p;

   p.x = (int)::GetPrivateProfileInt(L"MainWindow", L"Left", 100, awIniFileName);
   p.y = (int)::GetPrivateProfileInt(L"MainWindow", L"Top", 100, awIniFileName);

   ::SystemParametersInfo(SPI_GETWORKAREA, 0, &r1, 0);

   if(p.x < 0)
      p.x = 0;
   else if( ((r1.right- r1.left) - DW) < p.x)
      p.x = (r1.right- r1.left) - DW;

   if(p.y < 0)
      p.y = 0;
   else if( ((r1.bottom- r1.top) - DH) < p.y)
      p.y = (r1.bottom- r1.top) - DH;

   // 個別のウィンドウプロシージャを設定する
   for(n=0;n<sizeof_MYPROC;n++)
   {
      m_myProc[n].proc = (WNDPROC)::GetWindowLong(::GetDlgItem(hWnd, m_myProc[n].nResourceID), GWL_WNDPROC);
      ::SetWindowLong(::GetDlgItem(hWnd, m_myProc[n].nResourceID), GWL_WNDPROC, (LONG)g_pMyClass->CustomProc);
   }

   // ウィンドウのリージョンを設定する
   m_hRgn = ::CreatePolygonRgn(g_apRgn, 40, WINDING);
   ::SetWindowRgn(hWnd, m_hRgn, TRUE);

   // ウィンドウの位置と大きさを設定する
   ::SetWindowPos(hWnd, HWND_TOPMOST, p.x, p.y, DW, DH, 0);

   // ウィンドウキャプションを更新
   ::SetWindowText(hWnd, L"EcoDecoTooL");

   // ドロップファイルを受け入れる
   ::DragAcceptFiles(hWnd, TRUE);
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::OnClose(HWND hWnd)
{  // フォームが閉じる時に呼ばれる

   // iniファイルに設定値を保存しておく
   DWORD result;
   WCHAR awText[MAX_PATH], awIniFileName[MAX_PATH];

   ::GetModuleFileName(NULL, awIniFileName, MAX_PATH);
   ::PathRemoveFileSpec(awIniFileName);
   ::lstrcat(awIniFileName, TEXT("\\EcoDecoTooL.ini"));

   // コンボボックスの選択位置を保存する
   int nArraySize = sizeof(g_nComboResourceID) / sizeof(g_nComboResourceID[0]);

   for(int i=0;i<nArraySize;i++)
      WriteIniFile(awIniFileName, hWnd, g_nComboResourceID[i], L"ComboBox");

   // ラジオボタンの選択位置を保存する
   if(::IsDlgButtonChecked(hWnd, IDC_MAIN_WAV_RADIO1) == BST_CHECKED)
      ::WritePrivateProfileString(L"Radio", L"wav", L"0", awIniFileName);
   else if(::IsDlgButtonChecked(hWnd, IDC_MAIN_WAV_RADIO2) == 1)
      ::WritePrivateProfileString(L"Radio", L"wav", L"1", awIniFileName);
   else
      ::WritePrivateProfileString(L"Radio", L"wav", L"2", awIniFileName);

   if(::IsDlgButtonChecked(hWnd, IDC_MAIN_RADIO_FOLDER1) == BST_CHECKED)
      ::WritePrivateProfileString(L"Radio", L"outfolder", L"0", awIniFileName);
   else
      ::WritePrivateProfileString(L"Radio", L"outfolder", L"1", awIniFileName);

   // 出力先フォルダを保存する
   ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_FOLDER, awText, MAX_PATH);
   ::WritePrivateProfileString(L"Edit", L"outfolder", awText, awIniFileName);

   // リプレイゲイン情報を保存する
   result = ::GetDlgItemText(hWnd, IDC_MAIN_EDIT_VOLUME, awText, MAX_PATH);
   if(result > 0)
      ::WritePrivateProfileString(L"Edit", L"volume", awText, awIniFileName);

   // ウィンドウ位置を保存する
   WINDOWPLACEMENT wndpl;
   ::GetWindowPlacement(hWnd, &wndpl);
   ::wsprintf(awText, L"%d", wndpl.rcNormalPosition.left);
   ::WritePrivateProfileString(L"MainWindow", L"Left", awText, awIniFileName);
   ::wsprintf(awText, L"%d", wndpl.rcNormalPosition.top);
   ::WritePrivateProfileString(L"MainWindow", L"Top", awText, awIniFileName);

   // WNDPROCの解除
   for(int i=0;i<sizeof_MYPROC;i++)
   {
      if(m_myProc[i].proc != NULL)
         ::SetWindowLong(::GetDlgItem(hWnd, m_myProc[i].nResourceID), GWL_WNDPROC, (LONG)m_myProc[i].proc);
   }

   // ウィンドウのリージョンを破棄する
   SAFE_DELETEOBJECT(m_hRgn);
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::OnPaint(HDC hDC)
{
   RECT r;
   int i, color;

   double dx = DW / 50.0;
   double dc = (240.0-210.0) / 50.0;

   HBRUSH hBrush;

   for(i=0;i<=50;i++)
   {
      color = 210 + (int)(i*dc);

      ::SetRect(&r, int(i*dx), 0, int((i+1)*dx), DH);
      hBrush = ::CreateSolidBrush(RGB(color,color,color));
      ::FillRect(hDC, &r, hBrush);
      ::DeleteObject(hBrush); 
   }

   ::SetRect(&r, 0, 0, DW, 20);
   hBrush = ::CreateSolidBrush(RGB(255,255,255));
   ::FillRect(hDC, &r, hBrush);
   ::DeleteObject(hBrush); 

   HPEN hPen;

   hPen = CreatePen(PS_SOLID, 1, RGB(206, 206, 206));
   ::SelectObject(hDC, hPen);
   ::Polyline(hDC, g_apFrame1, 40);
   ::Polyline(hDC, g_apFrame2, 40);
   ::DeleteObject(hPen); 

   hPen = CreatePen(PS_SOLID, 1, RGB(230, 230, 230));
   ::SelectObject(hDC, hPen);
   ::Polyline(hDC, g_apFrame3, 24);

   ::MoveToEx(hDC, 5, 4, NULL);
   ::LineTo(hDC, DW-5, 4);

   ::MoveToEx(hDC, 4, 19, NULL);
   ::LineTo(hDC, DW-4, 19);

   ::DeleteObject(hPen); 

   hPen = CreatePen(PS_SOLID, 1, RGB(239, 239, 239));
   ::SelectObject(hDC, hPen);
   ::MoveToEx(hDC, 8, 3, NULL);
   ::LineTo(hDC, DW-8, 3);

   ::MoveToEx(hDC, 3, 21, NULL);
   ::LineTo(hDC, 3, DH-9);

   ::DeleteObject(hPen); 

   hPen = CreatePen(PS_SOLID, 1, RGB(235, 235, 235));
   ::SelectObject(hDC, hPen);
   ::MoveToEx(hDC, 4, 5, NULL);
   ::LineTo(hDC, DW-4, 5);
   ::DeleteObject(hPen); 

   hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
   ::SelectObject(hDC, hPen);
   ::MoveToEx(hDC, 3, 20, NULL);
   ::LineTo(hDC, DW-3, 20);
   ::DeleteObject(hPen); 

   ::SetRect(&r, 22, 52, 190, 159);
   DrawCustomRoundRect(hDC, &r);

   ::SetRect(&r, 8, 163, 190, 238);
   DrawCustomRoundRect(hDC, &r);

   ::SetRect(&r, 8, 242, 190, 322);
   DrawCustomRoundRect(hDC, &r);
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::DrawItem(DRAWITEMSTRUCT *pDrawItem)
{
   if(pDrawItem->CtlType == ODT_COMBOBOX)
   {
      if(pDrawItem->itemState & ODS_SELECTED)
      {
         RECT r;
         int i, color;
         HBRUSH hBrush = NULL;

         double dx = (pDrawItem->rcItem.right - pDrawItem->rcItem.left - 4) / 30.0;
         double dc = (255.0-220.0) / 30.0;

         for(i=0;i<=30;i++)
         {
            color = 220 + (int)(i*dc);

            ::SetRect(&r, 2+int(i*dx), pDrawItem->rcItem.top, 2+int((i+1)*dx), pDrawItem->rcItem.bottom);

            hBrush = ::CreateSolidBrush(RGB(color,color,color));
            ::FillRect(pDrawItem->hDC, &r, hBrush);
            SAFE_DELETEOBJECT(hBrush);
         }

         HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
         ::SelectObject(pDrawItem->hDC, hPen);

         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.top, NULL);
         ::LineTo(pDrawItem->hDC, 6, pDrawItem->rcItem.top);
         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.top+1, NULL);
         ::LineTo(pDrawItem->hDC, 4, pDrawItem->rcItem.top+1);
         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.top+2, NULL);
         ::LineTo(pDrawItem->hDC, 2, pDrawItem->rcItem.top+4);

         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.bottom-4, NULL);
         ::LineTo(pDrawItem->hDC, 2, pDrawItem->rcItem.bottom-2);
         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.bottom-2, NULL);
         ::LineTo(pDrawItem->hDC, 4, pDrawItem->rcItem.bottom-2);
         ::MoveToEx(pDrawItem->hDC, 2, pDrawItem->rcItem.bottom-1, NULL);
         ::LineTo(pDrawItem->hDC, 6, pDrawItem->rcItem.bottom-1);

         SAFE_DELETEOBJECT(hPen);
      }
      else
      {
         ::FillRect(pDrawItem->hDC, &pDrawItem->rcItem, (HBRUSH)GetStockObject(WHITE_BRUSH));
      }

      ::SetBkMode(pDrawItem->hDC, TRANSPARENT);
      ::SetTextColor(pDrawItem->hDC, RGB(0,0,0));

      RECT r;
      ::SetRect(&r, pDrawItem->rcItem.left+4, pDrawItem->rcItem.top, pDrawItem->rcItem.right-2, pDrawItem->rcItem.bottom);

      WCHAR awItem[256];
      ::SendMessage(pDrawItem->hwndItem, CB_GETLBTEXT, pDrawItem->itemID, (LPARAM)awItem);
      ::DrawText(pDrawItem->hDC, awItem, -1, &r, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
   }
   else if(pDrawItem->CtlType == ODT_BUTTON)
   {
      HDC hmDC;
      HBITMAP hBitmap = NULL;

      if(pDrawItem->CtlID == IDC_MAIN_WAV_BUTTON || pDrawItem->CtlID == IDC_MAIN_BUTTON_FOLDER)
         hBitmap = ::LoadBitmap(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_BUTTON));
      else if(pDrawItem->CtlID == IDC_MAIN_BUTTON_HELP)
         hBitmap = ::LoadBitmap(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_HELP));
      else if(pDrawItem->CtlID == IDC_MAIN_BUTTON_DROP)
         hBitmap = ::LoadBitmap(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_HELP));

      if(hBitmap != NULL)
      {
         hmDC = ::CreateCompatibleDC(pDrawItem->hDC);
         ::SelectObject(hmDC, hBitmap);

         if(pDrawItem->CtlID == IDC_MAIN_WAV_BUTTON || pDrawItem->CtlID == IDC_MAIN_BUTTON_FOLDER)
            ::BitBlt(pDrawItem->hDC, 0, 0, 16, 14, hmDC, 0, 0, SRCCOPY);
         else if(pDrawItem->CtlID == IDC_MAIN_BUTTON_HELP)
            ::BitBlt(pDrawItem->hDC, 0, 0, 16, 16, hmDC, 0, 0, SRCCOPY);
         else // if(pDrawItem->CtlID == IDC_MAIN_BUTTON_DROP)
            ::BitBlt(pDrawItem->hDC, 0, 0, 16, 16, hmDC, 0, 0, SRCCOPY);

         ::DeleteDC(hmDC);
         ::DeleteObject(hBitmap);
      }
   }
}
// ----------------------------------------------------------------------------------------------------------------------------
void CMainDialog::DrawCustomRoundRect(HDC hDC, RECT *pRect)
{
   RECT r;
   HPEN hPen;

   ::SetRect(&r, pRect->left+1, pRect->top+5, pRect->right-1, pRect->bottom-4);
   ::FillRect(hDC, &r, (HBRUSH)::GetStockObject(WHITE_BRUSH));

   hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
   ::SelectObject(hDC, hPen);
   ::MoveToEx(hDC, pRect->left+5, pRect->top+1, NULL); ::LineTo(hDC, pRect->right-5, pRect->top+1);
   ::MoveToEx(hDC, pRect->left+3, pRect->top+2, NULL); ::LineTo(hDC, pRect->right-3, pRect->top+2);
   ::MoveToEx(hDC, pRect->left+2, pRect->top+3, NULL); ::LineTo(hDC, pRect->right-2, pRect->top+3);
   ::MoveToEx(hDC, pRect->left+2, pRect->top+4, NULL); ::LineTo(hDC, pRect->right-2, pRect->top+4);
   ::MoveToEx(hDC, pRect->left+2, pRect->bottom-4, NULL); ::LineTo(hDC, pRect->right-2, pRect->bottom-4);
   ::MoveToEx(hDC, pRect->left+2, pRect->bottom-3, NULL); ::LineTo(hDC, pRect->right-2, pRect->bottom-3);
   ::MoveToEx(hDC, pRect->left+3, pRect->bottom-2, NULL); ::LineTo(hDC, pRect->right-3, pRect->bottom-2);
   ::MoveToEx(hDC, pRect->left+5, pRect->bottom-1, NULL); ::LineTo(hDC, pRect->right-5, pRect->bottom-1);
   ::DeleteObject(hPen);

   hPen = CreatePen(PS_SOLID, 1, RGB(235, 235, 235));
   ::SelectObject(hDC, hPen);
   ::MoveToEx(hDC, pRect->left+5, pRect->top, NULL);

   ::LineTo(hDC, pRect->right-5, pRect->top);
   ::LineTo(hDC, pRect->right-4, pRect->top+1);
   ::LineTo(hDC, pRect->right-3, pRect->top+1);
   ::LineTo(hDC, pRect->right-1, pRect->top+3);
   ::LineTo(hDC, pRect->right-1, pRect->top+4);
   ::LineTo(hDC, pRect->right,   pRect->top+5);
   ::LineTo(hDC, pRect->right,   pRect->bottom-5);
   ::LineTo(hDC, pRect->right-1, pRect->bottom-4);
   ::LineTo(hDC, pRect->right-1, pRect->bottom-3);
   ::LineTo(hDC, pRect->right-3, pRect->bottom-1);
   ::LineTo(hDC, pRect->right-4, pRect->bottom-1);
   ::LineTo(hDC, pRect->right-5, pRect->bottom);
   ::LineTo(hDC, pRect->left+5,  pRect->bottom);
   ::LineTo(hDC, pRect->left+4,  pRect->bottom-1);
   ::LineTo(hDC, pRect->left+3,  pRect->bottom-1);
   ::LineTo(hDC, pRect->left+1,  pRect->bottom-3);
   ::LineTo(hDC, pRect->left+1,  pRect->bottom-4);
   ::LineTo(hDC, pRect->left,    pRect->bottom-5);
   ::LineTo(hDC, pRect->left,    pRect->top+5);
   ::LineTo(hDC, pRect->left+1,  pRect->top+4);
   ::LineTo(hDC, pRect->left+1,  pRect->top+3);
   ::LineTo(hDC, pRect->left+3,  pRect->top+1);
   ::LineTo(hDC, pRect->left+4,  pRect->top+1);
   ::LineTo(hDC, pRect->left+5,  pRect->top);

   ::DeleteObject(hPen); 
}
// ----------------------------------------------------------------------------------------------------------------------------
int CALLBACK CMainDialog::SHBrowseProc(HWND hWnd, UINT msg, LPARAM lParam,  LPARAM lpData)
{
   if(msg == BFFM_INITIALIZED)
   {
      // フォルダ選択ウィンドウを親ウィンドウの近くに配置する
      // フォルダ選択ウィンドウがデスクトップからはみ出る場合は、デスクトップ内に収まるように修正する
      POINT p;
      RECT r1, r2;
      WINDOWPLACEMENT wndpl;

      ::SystemParametersInfo(SPI_GETWORKAREA, 0, &r1, 0);
      ::GetWindowRect(hWnd, &r2);
      ::GetWindowPlacement(::GetParent(hWnd), &wndpl);

      p.x = wndpl.rcNormalPosition.left + 120;
      p.y = wndpl.rcNormalPosition.top + 196;

      if( (p.x + (r2.right - r2.left)) > r1.right)
         p.x = r1.right - (r2.right - r2.left);

      if( (p.y + (r2.bottom - r2.top)) > r1.bottom)
         p.y = r1.bottom - (r2.bottom - r2.top);

      if(p.x < 0)
         p.x =0;

      if(p.y < 0)
         p.y =0;

      ::SetWindowPos(hWnd, NULL, p.x, p.y, 0, 0, SWP_NOSIZE|SWP_NOZORDER);

      // 初期フォルダを指定する
      ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);
   }

   return 0;
}
// ----------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK CMainDialog::DialogWaveFormatProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{  // 「音質を指定」のウィンドウProc

   switch (msg)
   {
   case WM_INITDIALOG:

      // リソーステキストを指定言語に変更する
      ::SetDlgItemText(hWnd, IDC_WAVEFORMAT_STATIC1, g_pMyClass->GetLocalText(IDC_WAVEFORMAT_STATIC1));
      ::SetDlgItemText(hWnd, IDC_WAVEFORMAT_STATIC2, g_pMyClass->GetLocalText(IDC_WAVEFORMAT_STATIC2));
      ::SetDlgItemText(hWnd, IDC_WAVEFORMAT_STATIC3, g_pMyClass->GetLocalText(IDC_WAVEFORMAT_STATIC3));

      // コンボボックスの準備
      g_pMyClass->PrepareComboBox(hWnd, IDC_WAVEFORMAT_COMBO1);
      g_pMyClass->PrepareComboBox(hWnd, IDC_WAVEFORMAT_COMBO2);
      g_pMyClass->PrepareComboBox(hWnd, IDC_WAVEFORMAT_COMBO3);

      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO1), CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)13);
      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO2), CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)13);
      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO3), CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)13);

      // 音質設定ウィンドウを親ウィンドウの近くに配置する
      // 音質設定ウィンドウがデスクトップからはみ出る場合は、デスクトップ内に収まるように修正する
      POINT p;
      RECT r1, r2;
      WINDOWPLACEMENT wndpl;

      ::SystemParametersInfo(SPI_GETWORKAREA, 0, &r1, 0);
      ::GetWindowRect(hWnd, &r2);
      ::GetWindowPlacement(::GetWindow(hWnd, GW_OWNER), &wndpl);


      p.x = wndpl.rcNormalPosition.left + 112;
      p.y = wndpl.rcNormalPosition.top + 126;

      if( (p.x + (r2.right - r2.left)) > r1.right)
         p.x = r1.right - (r2.right - r2.left);

      if( (p.y + (r2.bottom - r2.top)) > r1.bottom)
         p.y = r1.bottom - (r2.bottom - r2.top);

      if(p.x < 0)
         p.x =0;

      if(p.y < 0)
         p.y =0;

      ::SetWindowPos(hWnd, NULL, p.x, p.y, 0, 0, SWP_NOSIZE|SWP_NOZORDER);

      // iniファイルから設定を読み込む
      int n;
      WCHAR awIniFileName[MAX_PATH];

      ::GetModuleFileName(NULL, awIniFileName, MAX_PATH);
      ::PathRemoveFileSpec(awIniFileName);
      ::lstrcat(awIniFileName, L"\\EcoDecoTooL.ini");

      n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo1", 8, awIniFileName);
      if(n < 0 || 13 < n) n = 8;
      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO1), CB_SETCURSEL, (WPARAM)n, (LPARAM)0);

      n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo2", 1, awIniFileName);
      if(n < 0 || 6 < n) n = 1;
      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO2), CB_SETCURSEL, (WPARAM)n, (LPARAM)0);

      n = (int)::GetPrivateProfileInt(L"combo_wav", L"combo3", 1, awIniFileName);
      if(n < 0 || 2 < n) n = 1;
      ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO3), CB_SETCURSEL, (WPARAM)n, (LPARAM)0);

      return TRUE;

   case WM_CTLCOLORSTATIC:
      ::SetBkMode((HDC)wParam, TRANSPARENT);
      return (BOOL)(HBRUSH)GetStockObject(NULL_BRUSH);

   case WM_PAINT:
      HDC hDC;
      PAINTSTRUCT ps;
      hDC = ::BeginPaint(hWnd , &ps);

      RECT r;
      ::SetRect(&r, 4, 4, 174, 110);
      g_pMyClass->DrawCustomRoundRect(hDC, &r);

      ::EndPaint(hWnd , &ps);
		return TRUE;

   case WM_DRAWITEM:
      // オーナードローのパーツを描画する
      g_pMyClass->DrawItem((DRAWITEMSTRUCT *)lParam);
      return TRUE;

   case WM_CTLCOLORDLG:
   // ダイアログの背景色を指定する
      return (LRESULT)::CreateSolidBrush(RGB(0xc0,0xc0,0xc0));

   case WM_COMMAND:

      const int nComboSamplingrate[14] = 
         { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0};

      const int nComboBitsPerSample[7] = { 8, 16, 24, 32, 32, 64, 0};

      switch(LOWORD(wParam))
      {
      case IDC_WAVEFORMAT_BUTTON_OK:

         // iniファイルに設定を書き込み、m_waveFormatの設定をする
         int nCursel;
         WCHAR awText[MAX_PATH], awFileName[MAX_PATH];

         ::GetModuleFileName(NULL, awFileName, MAX_PATH);
         ::PathRemoveFileSpec(awFileName);
         ::lstrcat(awFileName, L"\\EcoDecoTooL.ini");

         nCursel = ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO1), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         if(nCursel < 0 || 13 < nCursel) nCursel = 8;
         ::wsprintf(awText, L"%d", nCursel);
         ::WritePrivateProfileString(L"combo_wav", L"combo1", awText, awFileName);
         g_pMyClass->m_waveFormat.nSamplesPerSec = nComboSamplingrate[nCursel];

         nCursel = ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO2), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         if(nCursel < 0 || 6 < nCursel) nCursel = 1;
         ::wsprintf(awText, L"%d", nCursel);
         ::WritePrivateProfileString(L"combo_wav", L"combo2", awText, awFileName);
         g_pMyClass->m_waveFormat.wBitsPerSample = nComboBitsPerSample[nCursel];

         if(nCursel == 6)
            g_pMyClass->m_waveFormat.wFormatTag = 0;
         else if(nCursel == 4 || nCursel == 5)
            g_pMyClass->m_waveFormat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
         else
            g_pMyClass->m_waveFormat.wFormatTag = WAVE_FORMAT_PCM;

         nCursel = ::SendMessage(::GetDlgItem(hWnd, IDC_WAVEFORMAT_COMBO3), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         if(nCursel < 0 || 2 < nCursel) nCursel = 1;
         ::wsprintf(awText, L"%d", nCursel);
         ::WritePrivateProfileString(L"combo_wav", L"combo3", awText, awFileName);

         if(nCursel == 0)
            g_pMyClass->m_waveFormat.nChannels = 1;
         else if(nCursel == 1)
            g_pMyClass->m_waveFormat.nChannels = 2;
         else // if(nCursel == 2)
            g_pMyClass->m_waveFormat.nChannels = 0;

         ::EndDialog(hWnd, IDOK);
         return TRUE;

      case IDC_WAVEFORMAT_BUTTON_CANCEL:
         ::EndDialog(hWnd, IDCANCEL);
         return TRUE;
      case IDCANCEL:
         ::EndDialog(hWnd, IDCANCEL);
         return TRUE;
      }
   }

	return FALSE;
}
// ----------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK CMainDialog::CustomProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{  // 独自に設定したプロシージャ用

   int nIndex;

   for(nIndex=0;nIndex<sizeof_MYPROC;nIndex++)
   {
      if(g_pMyClass->m_myProc[nIndex].nResourceID == ::GetDlgCtrlID(hWnd))
         break;
   }

   switch(msg)
   {
   case WM_SETCURSOR:

      if(g_pMyClass->m_myProc[nIndex].nItemType == DIALOG_BUTTON || g_pMyClass->m_myProc[nIndex].nItemType == DIALOG_LINKLABEL)
      {  // エディットボックス以外の場合
         // マウスカーソルを手の形にする
         ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(32649)));
	      return 0;
      }

      break;

   case WM_CHAR:

      if(g_pMyClass->m_myProc[nIndex].nItemType == DIALOG_EDITBOX)
      {
         WCHAR awText[32];
         ::GetWindowText(hWnd, awText, 32);

         // 6文字以上は入力させない
         if(::lstrlen(awText) >= 5)
            return 0;

         // 受け付けるキーは数字キーと小数点とBSとDeleteキーのみ
         if(wParam == VK_BACK || wParam == VK_DELETE || wParam == '.' || ('0' <= wParam && wParam <= '9'))
            break;
         else
            return 0;
      }

      break;

   case WM_MOUSEMOVE:

      if(wParam != MK_LBUTTON)
      {
         if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_MIN || g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_CLOSE)
         {
            TRACKMOUSEEVENT tme;
            tme.cbSize = sizeof(tme);
            tme.dwFlags = TME_LEAVE;
            tme.hwndTrack = hWnd;
            ::TrackMouseEvent(&tme);

            if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_MIN)
            {
               if(g_pMyClass->m_nMinResourceID != IDB_BITMAP_MIN2)
               {
                  g_pMyClass->m_nMinResourceID = IDB_BITMAP_MIN2;
                  ::InvalidateRect(hWnd, NULL, FALSE);
                  ::UpdateWindow(hWnd);
               }
            }
            else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_CLOSE)
            {
               if(g_pMyClass->m_nCloseResourceID != IDB_BITMAP_CLOSE2)
               {
                  g_pMyClass->m_nCloseResourceID = IDB_BITMAP_CLOSE2;
                  ::InvalidateRect(hWnd, NULL, FALSE);
                  ::UpdateWindow(hWnd);
               }
            }
         }
      }

      break;

   case WM_MOUSELEAVE:

      if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_MIN)
      {
         if(g_pMyClass->m_nMinResourceID != IDB_BITMAP_MIN1)
         {
            g_pMyClass->m_nMinResourceID = IDB_BITMAP_MIN1;
            ::InvalidateRect(hWnd, NULL, FALSE);
            ::UpdateWindow(hWnd);
         }
      }
      else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_CLOSE)
      {
         if(g_pMyClass->m_nCloseResourceID != IDB_BITMAP_CLOSE1)
         {
            g_pMyClass->m_nCloseResourceID = IDB_BITMAP_CLOSE1;
            ::InvalidateRect(hWnd, NULL, FALSE);
            ::UpdateWindow(hWnd);
         }
      }

      break;

   case WM_LBUTTONDOWN:

      if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_MIN)
      {
         if(g_pMyClass->m_nMinResourceID != IDB_BITMAP_MIN3)
         {
            g_pMyClass->m_nMinResourceID = IDB_BITMAP_MIN3;
            ::InvalidateRect(hWnd, NULL, FALSE);
            ::UpdateWindow(hWnd);
         }
      }
      else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_CLOSE)
      {
         if(g_pMyClass->m_nCloseResourceID != IDB_BITMAP_CLOSE3)
         {
            g_pMyClass->m_nCloseResourceID = IDB_BITMAP_CLOSE3;
            ::InvalidateRect(hWnd, NULL, FALSE);
            ::UpdateWindow(hWnd);
         }
      }
      else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_WAV_BUTTON)
      {

      }
      else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_FOLDER)
      {

      }
      else if(g_pMyClass->m_myProc[nIndex].nItemType == DIALOG_LINKLABEL)
      {  // リンクラベルの場合
         HRESULT hr;
         DWORD dwOut = MAX_PATH + 10;
         WCHAR awExeFileName[MAX_PATH + 10], awHtmlFileName[MAX_PATH + 10], awParameters[MAX_PATH + 10];

         // 標準のブラウザを取得する
         hr = ::AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".html", L"open", awExeFileName, &dwOut);

         if(SUCCEEDED(hr))
         {
            // help.htmlのフルパスを取得する
            ::GetModuleFileName(NULL, awHtmlFileName, MAX_PATH);
            ::PathRemoveFileSpec(awHtmlFileName);
            ::lstrcat(awHtmlFileName, L"/html/help.html");

            // help.htmlの見出しを設定する
            if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_HELP)
            {
               int n;
               n = ::SendMessage(::GetDlgItem(::GetParent(hWnd), IDC_MAIN_COMBO_CONTAINER), CB_GETCURSEL, 0, 0);

               switch(n)
               {
               case 0:  ::lstrcat(awHtmlFileName, L"#container_wav"); break;
               case 1:  ::lstrcat(awHtmlFileName, L"#container_aac"); break;
               case 2:  ::lstrcat(awHtmlFileName, L"#container_fraunhofer"); break;
               case 3:  ::lstrcat(awHtmlFileName, L"#container_lame"); break;
               case 4:  ::lstrcat(awHtmlFileName, L"#container_ogg"); break;
               default: ::lstrcat(awHtmlFileName, L"#container_raw"); break;
               }
            }

            else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_DROP)
               ::lstrcat(awHtmlFileName, L"#dropfile");
            else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_AAC_STATIC_LINKLABEL)
               ::lstrcat(awHtmlFileName, L"#container_aac");
            else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL)
               ::lstrcat(awHtmlFileName, L"#container_fraunhofer");
            else
               ::lstrcat(awHtmlFileName, L"#container_lame");

            // コマンドライン引数を設定する(注：fileを先頭に付けないと、見出しの#文字が%23に変換されてURLを開けなくなってしまう)
            ::wsprintf(awParameters, L"file://%s", awHtmlFileName);

            // 標準のブラウザでhelp.htmlを開く
            ::ShellExecute(NULL, NULL, awExeFileName, awParameters, NULL, SW_SHOWNORMAL);
         }
      }

      break;

   case WM_LBUTTONUP:

      if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_MIN)
      {
         if(0 <= LOWORD(lParam) && LOWORD(lParam) < 11 && 0 <= HIWORD(lParam) && HIWORD(lParam) < 11)
            ::ShowWindow(::GetParent(hWnd), SW_MINIMIZE);
      }
      else if(g_pMyClass->m_myProc[nIndex].nResourceID == IDC_MAIN_BUTTON_CLOSE)
      {
         if(0 <= LOWORD(lParam) && LOWORD(lParam) < 11 && 0 <= HIWORD(lParam) && HIWORD(lParam) < 11)
         {
            g_pMyClass->OnClose(::GetParent(hWnd));
            ::EndDialog(::GetParent(hWnd), IDCANCEL);
            return 0;
         }
      }

      break;
   }

   return ::CallWindowProc(g_pMyClass->m_myProc[nIndex].proc, hWnd , msg , wParam , lParam);
}
// ----------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK CMainDialog::DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

   switch (msg)
   {
   case WM_INITDIALOG:
      g_pMyClass->OnCreate(hWnd);
      return TRUE;

   case WM_CTLCOLORSTATIC:

      if((HWND)lParam == ::GetDlgItem(hWnd, IDC_MAIN_AAC_STATIC_LINKLABEL) ||
         (HWND)lParam == ::GetDlgItem(hWnd, IDC_MAIN_MP3_FRAUNHOFER_STATIC_LINKLABEL) ||
         (HWND)lParam == ::GetDlgItem(hWnd, IDC_MAIN_MP3_LAME_STATIC_LINKLABEL))
      {  // 下線付きの青色文字にする
         HFONT hFont = ::CreateFont(11,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,SHIFTJIS_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,NULL);
         ::SelectObject((HDC)wParam, hFont);
         ::DeleteObject(hFont);
         ::SetTextColor((HDC)wParam, RGB(0x00, 0x00, 0xff));
         return (BOOL)(HBRUSH)GetStockObject(WHITE_BRUSH);
      }

      ::SetBkMode((HDC)wParam, TRANSPARENT);
      return (BOOL)(HBRUSH)GetStockObject(WHITE_BRUSH);

   case WM_LBUTTONDOWN:

      if(LOWORD(lParam) < 165 && HIWORD(lParam) <= 20)
      {  // タイトルバーをクリックした場合

         // ウィンドウを移動できるようにする
         ::PostMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, lParam);
         return TRUE;
      }

      return FALSE;

   case WM_DROPFILES:

      bool flag;
      flag = g_pMyClass->DropFiles(hWnd, (HDROP)wParam);
      ::DragFinish((HDROP)wParam);

      if(flag == true)
      {
         // 設定値をm_convertDataに格納する
         flag = g_pMyClass->GetSettingData(hWnd);
         if(flag == true)
         {
            // ダイアログを終了させる
            ::SendMessage(hWnd, WM_CLOSE, 0, 0);
         }
      }

      return TRUE;

   case WM_COMMAND:

      if(LOWORD(wParam) == IDC_MAIN_COMBO_CONTAINER)
      {
         if(HIWORD(wParam) == CBN_SELCHANGE)
         {
            g_pMyClass->SelectContainer(hWnd, ::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_CONTAINER), CB_GETCURSEL, 0, 0));
            return TRUE;
         }
      }
      else if(LOWORD(wParam) == IDC_MAIN_WAV_BUTTON)
      {
         // ダイアログを表示する
         ::DialogBox(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_WAVEFORMAT), hWnd, (DLGPROC)DialogWaveFormatProc);

         // IDC_WAV_STATIC_FORMATを更新する
         WCHAR awText[64];

         if(g_pMyClass->m_waveFormat.nSamplesPerSec == 0)
            ::lstrcpy(awText, L"");
         else
            ::wsprintf(awText, L"%3d,%03dHz", g_pMyClass->m_waveFormat.nSamplesPerSec/1000, g_pMyClass->m_waveFormat.nSamplesPerSec%1000);

         ::SetDlgItemText(hWnd, IDC_MAIN_WAV_STATIC_FORMAT1, awText);

         if(g_pMyClass->m_waveFormat.wBitsPerSample == 0 && g_pMyClass->m_waveFormat.nChannels == 0)
         {
            ::lstrcpy(awText, L"");
         }
         else
         {
            if(g_pMyClass->m_waveFormat.wBitsPerSample != 0 && g_pMyClass->m_waveFormat.nChannels != 0)
               ::wsprintf(awText, L" %2dbit %dch", g_pMyClass->m_waveFormat.wBitsPerSample, g_pMyClass->m_waveFormat.nChannels);
            else if(g_pMyClass->m_waveFormat.wBitsPerSample == 0)
               ::wsprintf(awText, L" %dch", g_pMyClass->m_waveFormat.nChannels);
            else if(g_pMyClass->m_waveFormat.nChannels == 0)
               ::wsprintf(awText, L" %2dbit", g_pMyClass->m_waveFormat.wBitsPerSample);
         }

         ::SetDlgItemText(hWnd, IDC_MAIN_WAV_STATIC_FORMAT2, awText);
//         ::InvalidateRect(hWnd, NULL, TRUE);

         return TRUE;
      }
      else if(LOWORD(wParam) == IDC_MAIN_BUTTON_FOLDER)
      {
         g_pMyClass->SelectFolder(hWnd);
         ::InvalidateRect(hWnd, NULL, TRUE);
         return TRUE;
      }
      else if(LOWORD(wParam) == IDC_MAIN_AAC_COMBO_MODE || LOWORD(wParam) == IDC_MAIN_MP3_FRAUNHOFER_COMBO_MODE ||
              LOWORD(wParam) == IDC_MAIN_MP3_LAME_COMBO_MODE || LOWORD(wParam) == IDC_MAIN_OGG_COMBO_MODE)
      {
         if(HIWORD(wParam) == CBN_SELCHANGE)
            g_pMyClass->SelectMode(hWnd, LOWORD(wParam), ::SendMessage(::GetDlgItem(hWnd, LOWORD(wParam)), CB_GETCURSEL, 0, 0));

         return TRUE;
      }
      else if(LOWORD(wParam) == IDC_MAIN_COMBO_VOLUME)
      {
         if(HIWORD(wParam) == CBN_SELCHANGE)
         {
            if(::SendMessage(::GetDlgItem(hWnd, IDC_MAIN_COMBO_VOLUME), CB_GETCURSEL, (WPARAM)0, (LPARAM)0) == 0)
            {
               ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_HIDE);
               ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_HIDE);
            }
            else
            {
               ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_EDIT_VOLUME), SW_SHOW);
               ::ShowWindow(::GetDlgItem(hWnd, IDC_MAIN_STATIC_DB), SW_SHOW);
            }
         }

         return TRUE;
      }

      return FALSE;

   case WM_PAINT:

      HDC hDC;
      PAINTSTRUCT ps;

      hDC = ::BeginPaint(hWnd , &ps);
      g_pMyClass->OnPaint(hDC);
      ::EndPaint(hWnd , &ps);

      return TRUE;

   case WM_DRAWITEM:
      // オーナードローのパーツを描画する
      if(wParam == IDC_MAIN_BUTTON_MIN)
         g_pMyClass->DrawHoverButton((DRAWITEMSTRUCT *)lParam, g_pMyClass->m_nMinResourceID);
      else if(wParam == IDC_MAIN_BUTTON_CLOSE)
         g_pMyClass->DrawHoverButton((DRAWITEMSTRUCT *)lParam, g_pMyClass->m_nCloseResourceID);
      else
         g_pMyClass->DrawItem((DRAWITEMSTRUCT *)lParam);

		return TRUE;

   case WM_DESTROY:
/*
      // WNDPROCの解除
      int i;
      for(i=0;i<sizeof_MYPROC;i++)
      {
         if(g_pMyClass->m_myProc[i].proc != NULL)
            ::SetWindowLong(::GetDlgItem(hWnd, g_pMyClass->m_myProc[i].nResourceID), GWL_WNDPROC, (LONG)g_pMyClass->m_myProc[i].proc);
      }
*/
      return TRUE;

   case WM_CLOSE:
      g_pMyClass->OnClose(hWnd);
      ::EndDialog(hWnd ,IDOK);
      return TRUE;
   }


   return FALSE;
}
// -------------------------------------------------------------------------------------------------------------------------------------------
void CMainDialog::ShowDialog(SETTINGDATA *pData, int nLanguage, CLinkedList *pList)
{
   m_nLanguage = nLanguage;
   m_pSettingData = pData;
   m_pDropLinkedList = pList;

   // ダイアログを表示する
   ::DialogBox(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL,(DLGPROC)DialogProc);
}
// ----------------------------------------------------------------------------------------------------------------------------
