IdwThread.cpp
changeset 0 523a7dc3469f
child 1 d9a866996670
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/IdwThread.cpp	Sun Mar 16 09:11:39 2014 +0100
     1.3 @@ -0,0 +1,745 @@
     1.4 +//------------------------------------------------------------------------------
     1.5 +#include "IdwThread.h"
     1.6 +#include "iMONDisplayAPI.h"
     1.7 +//------------------------------------------------------------------------------
     1.8 +#define CLASSNAME TEXT("IDW_IMON_COM_WNDCLASS")
     1.9 +//------------------------------------------------------------------------------
    1.10 +#define WM_IDW_IMON                (WM_USER + 1)
    1.11 +#define WM_IDW_INIT                (WM_USER + 2)
    1.12 +#define WM_IDW_UNINIT              (WM_USER + 3)
    1.13 +#define WM_IDW_ISINITED            (WM_USER + 4)
    1.14 +#define WM_IDW_ISPLUGINMODEENABLED (WM_USER + 5)
    1.15 +#define WM_IDW_SETVFDTEXT          (WM_USER + 6)
    1.16 +#define WM_IDW_SETVFDEQ            (WM_USER + 7)
    1.17 +#define WM_IDW_SETLCDTEXT          (WM_USER + 8)
    1.18 +#define WM_IDW_SETLCDEQ            (WM_USER + 9)
    1.19 +#define WM_IDW_SETLCDALLICONS      (WM_USER + 10)
    1.20 +#define WM_IDW_SETLCDORANGEICON    (WM_USER + 11)
    1.21 +#define WM_IDW_SETLCDMEDIATYPEICON (WM_USER + 12)
    1.22 +#define WM_IDW_SETLCDSPEAKERICON   (WM_USER + 13)
    1.23 +#define WM_IDW_SETLCDVIDEOCODEC    (WM_USER + 14)
    1.24 +#define WM_IDW_SETLCDAUDIOCODEC    (WM_USER + 15)
    1.25 +#define WM_IDW_SETLCDASPECTRATIO   (WM_USER + 16)
    1.26 +#define WM_IDW_SETLCDETCICON       (WM_USER + 17)
    1.27 +#define WM_IDW_SETLCDPROGRESS      (WM_USER + 18)
    1.28 +#define WM_IDW_INTERRUPT           (WM_USER + 100)
    1.29 +//------------------------------------------------------------------------------
    1.30 +struct IdwImonInitResult
    1.31 +{
    1.32 +  DSPResult result;
    1.33 +  DSPNInitResult initResult;
    1.34 +  DSPType dspType;
    1.35 +};
    1.36 +struct IdwSetVfdText
    1.37 +{
    1.38 +  DSPResult result;
    1.39 +  LPCWSTR pszLine1;
    1.40 +  LPCWSTR pszLine2;
    1.41 +};
    1.42 +struct IdwSetVfdEq
    1.43 +{
    1.44 +  DSPResult result;
    1.45 +  PDSPEQDATA pEqData;
    1.46 +};
    1.47 +struct IdwSetLcdText
    1.48 +{
    1.49 +  DSPResult result;
    1.50 +  LPCWSTR pszLine1;
    1.51 +};
    1.52 +struct IdwSetLcdEq
    1.53 +{
    1.54 +  DSPResult result;
    1.55 +  PDSPEQDATA pEqDataL;
    1.56 +  PDSPEQDATA pEqDataR;
    1.57 +};
    1.58 +struct IdwSetLcdAllIcons
    1.59 +{
    1.60 +  DSPResult result;
    1.61 +  BOOL bOn;
    1.62 +};
    1.63 +struct IdwSetLcdIcons
    1.64 +{
    1.65 +  DSPResult result;
    1.66 +  BYTE btIconData;
    1.67 +};
    1.68 +struct IdwSetLcdIcons2
    1.69 +{
    1.70 +  DSPResult result;
    1.71 +  BYTE btIconData1;
    1.72 +  BYTE btIconData2;
    1.73 +};
    1.74 +struct IdwSetLcdProgress
    1.75 +{
    1.76 +  DSPResult result;
    1.77 +  int nCurPos;
    1.78 +	int nTotal;
    1.79 +};
    1.80 +//------------------------------------------------------------------------------
    1.81 +IdwThread::IdwThread(HINSTANCE hInstance)
    1.82 +: m_hInstance(hInstance)
    1.83 +, m_hWnd(NULL)
    1.84 +{
    1.85 +}
    1.86 +//------------------------------------------------------------------------------
    1.87 +IdwThread::~IdwThread()
    1.88 +{
    1.89 +}
    1.90 +//------------------------------------------------------------------------------
    1.91 +void IdwThread::Interrupt()
    1.92 +{
    1.93 +  if (!WaitForWindow())
    1.94 +    return;
    1.95 +  PostMessage(m_hWnd, WM_IDW_INTERRUPT, 0, 0);
    1.96 +}
    1.97 +//------------------------------------------------------------------------------
    1.98 +DSPResult IdwThread::Init(IDW_INITRESULT* pInitResult)
    1.99 +{
   1.100 +  if (!WaitForWindow())
   1.101 +    return DSP_E_FAIL;
   1.102 +
   1.103 +  IdwImonInitResult result;
   1.104 +  Event finished;
   1.105 +  PostMessage(m_hWnd, WM_IDW_INIT, (WPARAM)&result, (LPARAM)&finished);
   1.106 +  finished.Await();
   1.107 +  if (pInitResult != NULL)
   1.108 +  {
   1.109 +    pInitResult->initResult = result.initResult;
   1.110 +    pInitResult->dspType = result.dspType;
   1.111 +  }
   1.112 +
   1.113 +  return result.result;
   1.114 +}
   1.115 +//------------------------------------------------------------------------------
   1.116 +DSPResult IdwThread::Uninit()
   1.117 +{
   1.118 +  if (!WaitForWindow())
   1.119 +    return DSP_E_FAIL;
   1.120 +
   1.121 +  DSPResult result;  
   1.122 +  Event finished;
   1.123 +  PostMessage(m_hWnd, WM_IDW_UNINIT, (WPARAM)&result, (LPARAM)&finished);
   1.124 +  finished.Await();
   1.125 +
   1.126 +  return result;
   1.127 +}
   1.128 +//------------------------------------------------------------------------------
   1.129 +DSPResult IdwThread::IsInited()
   1.130 +{
   1.131 +  if (!WaitForWindow())
   1.132 +    return DSP_E_FAIL;
   1.133 +
   1.134 +  DSPResult result;  
   1.135 +  Event finished;
   1.136 +  PostMessage(m_hWnd, WM_IDW_ISINITED, (WPARAM)&result, (LPARAM)&finished);
   1.137 +  finished.Await();
   1.138 +
   1.139 +  return result;
   1.140 +}
   1.141 +//------------------------------------------------------------------------------
   1.142 +DSPResult IdwThread::IsPluginModeEnabled()
   1.143 +{
   1.144 +  if (!WaitForWindow())
   1.145 +    return DSP_E_FAIL;
   1.146 +
   1.147 +  DSPResult result;  
   1.148 +  Event finished;
   1.149 +  PostMessage(m_hWnd, WM_IDW_ISPLUGINMODEENABLED, (WPARAM)&result,
   1.150 +              (LPARAM)&finished);
   1.151 +  finished.Await();
   1.152 +
   1.153 +  return result;
   1.154 +}
   1.155 +//------------------------------------------------------------------------------
   1.156 +DSPResult IdwThread::SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2)
   1.157 +{
   1.158 +  if (!WaitForWindow())
   1.159 +    return DSP_E_FAIL;
   1.160 +
   1.161 +  IdwSetVfdText text;
   1.162 +  text.pszLine1 = lpszLine1;
   1.163 +  text.pszLine2 = lpszLine2;
   1.164 +  Event finished;
   1.165 +  PostMessage(m_hWnd, WM_IDW_SETVFDTEXT, (WPARAM)&text, (LPARAM)&finished);
   1.166 +  finished.Await();
   1.167 +
   1.168 +  return text.result;
   1.169 +}
   1.170 +//------------------------------------------------------------------------------
   1.171 +DSPResult IdwThread::SetVfdEqData(PDSPEQDATA pEqData)
   1.172 +{
   1.173 +  if (!WaitForWindow())
   1.174 +    return DSP_E_FAIL;
   1.175 +
   1.176 +  IdwSetVfdEq eq;
   1.177 +  eq.pEqData = pEqData;
   1.178 +  Event finished;
   1.179 +  PostMessage(m_hWnd, WM_IDW_SETVFDEQ, (WPARAM)&eq, (LPARAM)&finished);
   1.180 +  finished.Await();
   1.181 +
   1.182 +  return eq.result;
   1.183 +}
   1.184 +//------------------------------------------------------------------------------
   1.185 +DSPResult IdwThread::SetLcdText(LPCWSTR lpszLine1)
   1.186 +{
   1.187 +  if (!WaitForWindow())
   1.188 +    return DSP_E_FAIL;
   1.189 +
   1.190 +  IdwSetLcdText text;
   1.191 +  text.pszLine1 = lpszLine1;
   1.192 +  Event finished;
   1.193 +  PostMessage(m_hWnd, WM_IDW_SETLCDTEXT, (WPARAM)&text, (LPARAM)&finished);
   1.194 +  finished.Await();
   1.195 +
   1.196 +  return text.result;
   1.197 +}
   1.198 +//------------------------------------------------------------------------------
   1.199 +DSPResult IdwThread::SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR)
   1.200 +{
   1.201 +  if (!WaitForWindow())
   1.202 +    return DSP_E_FAIL;
   1.203 +
   1.204 +  IdwSetLcdEq eq;
   1.205 +  eq.pEqDataL = pEqDataL;
   1.206 +  eq.pEqDataR = pEqDataR;
   1.207 +  Event finished;
   1.208 +  PostMessage(m_hWnd, WM_IDW_SETLCDEQ, (WPARAM)&eq, (LPARAM)&finished);
   1.209 +  finished.Await();
   1.210 +
   1.211 +  return eq.result;
   1.212 +}
   1.213 +//------------------------------------------------------------------------------
   1.214 +DSPResult IdwThread::SetLcdAllIcons(BOOL bOn)
   1.215 +{
   1.216 +  if (!WaitForWindow())
   1.217 +    return DSP_E_FAIL;
   1.218 +
   1.219 +  IdwSetLcdAllIcons allIcons;
   1.220 +  allIcons.bOn = bOn;
   1.221 +  Event finished;
   1.222 +  PostMessage(m_hWnd, WM_IDW_SETLCDALLICONS, 
   1.223 +		(WPARAM)&allIcons, (LPARAM)&finished);
   1.224 +  finished.Await();
   1.225 +
   1.226 +  return allIcons.result;
   1.227 +}
   1.228 +//------------------------------------------------------------------------------
   1.229 +DSPResult IdwThread::SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2)
   1.230 +{
   1.231 +  if (!WaitForWindow())
   1.232 +    return DSP_E_FAIL;
   1.233 +
   1.234 +  IdwSetLcdIcons2 iconData;
   1.235 +  iconData.btIconData1 = btIconData1;
   1.236 +  iconData.btIconData2 = btIconData2;
   1.237 +  Event finished;
   1.238 +  PostMessage(m_hWnd, WM_IDW_SETLCDORANGEICON, 
   1.239 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.240 +  finished.Await();
   1.241 +
   1.242 +  return iconData.result;
   1.243 +}
   1.244 +//------------------------------------------------------------------------------
   1.245 +DSPResult IdwThread::SetLcdMediaTypeIcon(BYTE btIconData)
   1.246 +{
   1.247 +  if (!WaitForWindow())
   1.248 +    return DSP_E_FAIL;
   1.249 +
   1.250 +  IdwSetLcdIcons iconData;
   1.251 +  iconData.btIconData = btIconData;
   1.252 +  Event finished;
   1.253 +  PostMessage(m_hWnd, WM_IDW_SETLCDMEDIATYPEICON, 
   1.254 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.255 +  finished.Await();
   1.256 +
   1.257 +  return iconData.result;
   1.258 +}
   1.259 +//------------------------------------------------------------------------------
   1.260 +DSPResult IdwThread::SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2)
   1.261 +{
   1.262 +  if (!WaitForWindow())
   1.263 +    return DSP_E_FAIL;
   1.264 +
   1.265 +  IdwSetLcdIcons2 iconData;
   1.266 +  iconData.btIconData1 = btIconData1;
   1.267 +  iconData.btIconData2 = btIconData2;
   1.268 +  Event finished;
   1.269 +  PostMessage(m_hWnd, WM_IDW_SETLCDSPEAKERICON, 
   1.270 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.271 +  finished.Await();
   1.272 +
   1.273 +  return iconData.result;
   1.274 +}
   1.275 +//------------------------------------------------------------------------------
   1.276 +DSPResult IdwThread::SetLcdVideoCodecIcon(BYTE btIconData)
   1.277 +{
   1.278 +  if (!WaitForWindow())
   1.279 +    return DSP_E_FAIL;
   1.280 +
   1.281 +  IdwSetLcdIcons iconData;
   1.282 +  iconData.btIconData = btIconData;
   1.283 +  Event finished;
   1.284 +  PostMessage(m_hWnd, WM_IDW_SETLCDVIDEOCODEC, 
   1.285 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.286 +  finished.Await();
   1.287 +
   1.288 +  return iconData.result;
   1.289 +}
   1.290 +//------------------------------------------------------------------------------
   1.291 +DSPResult IdwThread::SetLcdAudioCodecIcon(BYTE btIconData)
   1.292 +{
   1.293 +  if (!WaitForWindow())
   1.294 +    return DSP_E_FAIL;
   1.295 +
   1.296 +  IdwSetLcdIcons iconData;
   1.297 +  iconData.btIconData = btIconData;
   1.298 +  Event finished;
   1.299 +  PostMessage(m_hWnd, WM_IDW_SETLCDAUDIOCODEC, 
   1.300 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.301 +  finished.Await();
   1.302 +
   1.303 +  return iconData.result;
   1.304 +}
   1.305 +//------------------------------------------------------------------------------
   1.306 +DSPResult IdwThread::SetLcdAspectRatioIcon(BYTE btIconData)
   1.307 +{
   1.308 +  if (!WaitForWindow())
   1.309 +    return DSP_E_FAIL;
   1.310 +
   1.311 +  IdwSetLcdIcons iconData;
   1.312 +  iconData.btIconData = btIconData;
   1.313 +  Event finished;
   1.314 +  PostMessage(m_hWnd, WM_IDW_SETLCDASPECTRATIO, 
   1.315 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.316 +  finished.Await();
   1.317 +
   1.318 +  return iconData.result;
   1.319 +}
   1.320 +//------------------------------------------------------------------------------
   1.321 +DSPResult IdwThread::SetLcdEtcIcon(BYTE btIconData)
   1.322 +{
   1.323 +  if (!WaitForWindow())
   1.324 +    return DSP_E_FAIL;
   1.325 +
   1.326 +  IdwSetLcdIcons iconData;
   1.327 +  iconData.btIconData = btIconData;
   1.328 +  Event finished;
   1.329 +  PostMessage(m_hWnd, WM_IDW_SETLCDETCICON, 
   1.330 +		(WPARAM)&iconData, (LPARAM)&finished);
   1.331 +  finished.Await();
   1.332 +
   1.333 +  return iconData.result;
   1.334 +}
   1.335 +//------------------------------------------------------------------------------
   1.336 +DSPResult IdwThread::SetLcdProgress(int nCurPos, int nTotal)
   1.337 +{
   1.338 +  if (!WaitForWindow())
   1.339 +    return DSP_E_FAIL;
   1.340 +
   1.341 +  IdwSetLcdProgress progressData;
   1.342 +  progressData.nCurPos = nCurPos;
   1.343 +	progressData.nTotal = nTotal;
   1.344 +  Event finished;
   1.345 +  PostMessage(m_hWnd, WM_IDW_SETLCDPROGRESS, 
   1.346 +		(WPARAM)&progressData, (LPARAM)&finished);
   1.347 +  finished.Await();
   1.348 +
   1.349 +  return progressData.result;
   1.350 +}
   1.351 +//------------------------------------------------------------------------------
   1.352 +void IdwThread::Run()
   1.353 +{
   1.354 +  if (!RegisterClass())
   1.355 +  {
   1.356 +    m_eventWindowCreationDone.Signal();
   1.357 +    return;
   1.358 +  }
   1.359 +  if (!CreateMessageWindow())
   1.360 +  {
   1.361 +    m_eventWindowCreationDone.Signal();
   1.362 +    return;
   1.363 +  }
   1.364 +  AllowImonMessages();
   1.365 +
   1.366 +  m_eventWindowCreationDone.Signal();
   1.367 +
   1.368 +  MSG msg;
   1.369 +  BOOL fGotMessage;
   1.370 +  while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0
   1.371 +       && fGotMessage != -1) 
   1.372 +  { 
   1.373 +    TranslateMessage(&msg); 
   1.374 +    DispatchMessage(&msg); 
   1.375 +  } 
   1.376 +}
   1.377 +//------------------------------------------------------------------------------
   1.378 +bool IdwThread::RegisterClass()
   1.379 +{
   1.380 +  WNDCLASSEX wc;
   1.381 +  if (GetClassInfoEx(m_hInstance, CLASSNAME, &wc))
   1.382 +  {
   1.383 +    return true;
   1.384 +  }
   1.385 +
   1.386 +  wc.cbSize = sizeof(wc);
   1.387 +  wc.style = CS_HREDRAW | CS_VREDRAW;
   1.388 +  wc.lpfnWndProc = IdwThread::WndProc;
   1.389 +  wc.cbClsExtra = 0;
   1.390 +  wc.cbWndExtra = 0;
   1.391 +  wc.hInstance = m_hInstance;
   1.392 +  wc.hIcon = NULL;
   1.393 +  wc.hCursor = NULL;
   1.394 +  wc.hbrBackground = NULL;
   1.395 +  wc.lpszMenuName =  NULL;
   1.396 +  wc.lpszClassName = CLASSNAME;
   1.397 +  wc.hIconSm = NULL;
   1.398 +  if (::RegisterClassEx(&wc))
   1.399 +  {
   1.400 +    return true;
   1.401 +  }
   1.402 +  return false;
   1.403 +}
   1.404 +//------------------------------------------------------------------------------
   1.405 +bool IdwThread::CreateMessageWindow()
   1.406 +{
   1.407 +  m_hWnd = CreateWindow( 
   1.408 +    CLASSNAME,
   1.409 +    TEXT("MP iMON MessageWindow"),
   1.410 +    0,
   1.411 +    0, 0, 0, 0,
   1.412 +    HWND_MESSAGE,
   1.413 +    NULL,
   1.414 +    m_hInstance,
   1.415 +    NULL);
   1.416 + 
   1.417 +  if (!m_hWnd) 
   1.418 +    return false;
   1.419 +  return true; 
   1.420 +}
   1.421 +//------------------------------------------------------------------------------
   1.422 +void IdwThread::AllowImonMessages()
   1.423 +{
   1.424 +  // Determine OS
   1.425 +  OSVERSIONINFO version;
   1.426 +  version.dwOSVersionInfoSize = sizeof(version);
   1.427 +  GetVersionEx(&version);
   1.428 +  if (version.dwMajorVersion < 6)
   1.429 +  {
   1.430 +    return;
   1.431 +  }
   1.432 +
   1.433 +  // Determine and allow iMON message number
   1.434 +  UINT iMonMsg =
   1.435 +    RegisterWindowMessage(
   1.436 +    TEXT("iMonMessage-431F1DC6-F31A-4AC6-A1FA-A4BB9C44FF10"));
   1.437 +  ChangeWindowMessageFilter(iMonMsg, MSGFLT_ADD);  
   1.438 +}
   1.439 +//------------------------------------------------------------------------------
   1.440 +bool IdwThread::WaitForWindow()
   1.441 +{
   1.442 +  m_eventWindowCreationDone.Await();
   1.443 +  if (m_hWnd == NULL)
   1.444 +    return false;
   1.445 +  return true;
   1.446 +}
   1.447 +//------------------------------------------------------------------------------
   1.448 +LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
   1.449 +                                    LPARAM lParam)
   1.450 +{
   1.451 +  static bool initing = false;
   1.452 +  static IdwImonInitResult* pInitResult = NULL;
   1.453 +  static Event* pInitFinished = NULL;
   1.454 +
   1.455 +  DSPResult* pResult;
   1.456 +  Event* pFinished;
   1.457 +
   1.458 +  switch (uMsg) 
   1.459 +  { 
   1.460 +    case WM_CREATE: 
   1.461 +      return 0; 
   1.462 + 
   1.463 +    case WM_DESTROY:
   1.464 +      PostQuitMessage(0);
   1.465 +      return 0;
   1.466 +
   1.467 +    case WM_IDW_IMON:
   1.468 +      if (initing)
   1.469 +      {
   1.470 +        initing = false;
   1.471 +        pInitResult->initResult = (DSPNInitResult)wParam;
   1.472 +        pInitResult->dspType = (DSPType)lParam;
   1.473 +        pInitFinished->Signal();
   1.474 +      }
   1.475 +      return 0;
   1.476 +
   1.477 +    case WM_IDW_INIT:
   1.478 +      initing = true;
   1.479 +      pInitResult = (IdwImonInitResult*)wParam;
   1.480 +      pInitFinished = (Event*)lParam;
   1.481 +      pInitResult->result = IMON_Display_Init(hwnd, WM_IDW_IMON);
   1.482 +      if (pInitResult->result != DSP_SUCCEEDED)
   1.483 +      {
   1.484 +        initing = false;
   1.485 +        pInitResult->initResult = DSPN_ERR_UNKNOWN;
   1.486 +        pInitResult->dspType = DSPN_DSP_NONE;
   1.487 +        pInitFinished->Signal();
   1.488 +      }
   1.489 +      return 0;
   1.490 +
   1.491 +    case WM_IDW_UNINIT:
   1.492 +      pResult = (DSPResult*)wParam;
   1.493 +      pFinished = (Event*)lParam;
   1.494 +      *pResult = IMON_Display_Uninit();
   1.495 +      pFinished->Signal();
   1.496 +      return 0;
   1.497 +
   1.498 +    case WM_IDW_ISINITED:
   1.499 +      pResult = (DSPResult*)wParam;
   1.500 +      pFinished = (Event*)lParam;
   1.501 +      *pResult = IMON_Display_IsInited();
   1.502 +      pFinished->Signal();
   1.503 +      return 0;
   1.504 +
   1.505 +    case WM_IDW_ISPLUGINMODEENABLED:
   1.506 +      pResult = (DSPResult*)wParam;
   1.507 +      pFinished = (Event*)lParam;
   1.508 +      *pResult = IMON_Display_IsPluginModeEnabled();
   1.509 +      pFinished->Signal();
   1.510 +      return 0;
   1.511 +
   1.512 +    case WM_IDW_SETVFDTEXT:
   1.513 +			{
   1.514 +				IdwSetVfdText* pSetVfdText = (IdwSetVfdText*)wParam;			
   1.515 +				WCHAR szLine1[20];
   1.516 +				WCHAR szLine2[20];
   1.517 +				pFinished = (Event*)lParam;
   1.518 +				MapChars(szLine1, pSetVfdText->pszLine1, 16);
   1.519 +				MapChars(szLine2, pSetVfdText->pszLine2, 16);
   1.520 +				pSetVfdText->result = IMON_Display_SetVfdText(szLine1, szLine2);
   1.521 +				pFinished->Signal();
   1.522 +				return 0;
   1.523 +			}
   1.524 +
   1.525 +    case WM_IDW_SETVFDEQ:
   1.526 +			{
   1.527 +				IdwSetVfdEq* pSetVfdEq = (IdwSetVfdEq*)wParam;
   1.528 +				pFinished = (Event*)lParam;
   1.529 +				pSetVfdEq->result = IMON_Display_SetVfdEqData(pSetVfdEq->pEqData);
   1.530 +				pFinished->Signal();
   1.531 +				return 0;
   1.532 +			}
   1.533 +
   1.534 +    case WM_IDW_SETLCDTEXT:
   1.535 +			{
   1.536 +				IdwSetLcdText* pSetLcdText = (IdwSetLcdText*)wParam;
   1.537 +				pFinished = (Event*)lParam;
   1.538 +				pSetLcdText->result = IMON_Display_SetLcdText(pSetLcdText->pszLine1);
   1.539 +				pFinished->Signal();
   1.540 +				return 0;
   1.541 +			}
   1.542 +
   1.543 +    case WM_IDW_SETLCDEQ:
   1.544 +			{
   1.545 +				IdwSetLcdEq* pSetLcdEq = (IdwSetLcdEq*)wParam;
   1.546 +				pFinished = (Event*)lParam;
   1.547 +				pSetLcdEq->result = 
   1.548 +					IMON_Display_SetLcdEqData(pSetLcdEq->pEqDataL, pSetLcdEq->pEqDataR);
   1.549 +				pFinished->Signal();
   1.550 +				return 0;
   1.551 +			}
   1.552 +
   1.553 +		case WM_IDW_SETLCDALLICONS:
   1.554 +			{
   1.555 +				IdwSetLcdAllIcons* pSetLcdAllIcons = (IdwSetLcdAllIcons*)wParam;
   1.556 +				pFinished = (Event*)lParam;
   1.557 +				pSetLcdAllIcons->result = 
   1.558 +					IMON_Display_SetLcdAllIcons(pSetLcdAllIcons->bOn);
   1.559 +				pFinished->Signal();
   1.560 +				return 0;
   1.561 +			}
   1.562 +
   1.563 +		case WM_IDW_SETLCDORANGEICON:
   1.564 +			{
   1.565 +				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
   1.566 +				pFinished = (Event*)lParam;
   1.567 +				pSetLcdIcons2->result = IMON_Display_SetLcdOrangeIcon(
   1.568 +					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
   1.569 +				pFinished->Signal();
   1.570 +				return 0;
   1.571 +			}
   1.572 +
   1.573 +	  case WM_IDW_SETLCDMEDIATYPEICON:
   1.574 +			{
   1.575 +				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   1.576 +				pFinished = (Event*)lParam;
   1.577 +				pSetLcdIcons->result = 
   1.578 +					IMON_Display_SetLcdMediaTypeIcon(pSetLcdIcons->btIconData);
   1.579 +				pFinished->Signal();
   1.580 +				return 0;
   1.581 +			}
   1.582 +
   1.583 +		case WM_IDW_SETLCDSPEAKERICON:
   1.584 +			{
   1.585 +				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
   1.586 +				pFinished = (Event*)lParam;
   1.587 +				pSetLcdIcons2->result = IMON_Display_SetLcdSpeakerIcon(
   1.588 +					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
   1.589 +				pFinished->Signal();
   1.590 +				return 0;
   1.591 +			}
   1.592 +
   1.593 +	  case WM_IDW_SETLCDVIDEOCODEC:
   1.594 +			{
   1.595 +				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   1.596 +				pFinished = (Event*)lParam;
   1.597 +				pSetLcdIcons->result = 
   1.598 +					IMON_Display_SetLcdVideoCodecIcon(pSetLcdIcons->btIconData);
   1.599 +				pFinished->Signal();
   1.600 +				return 0;
   1.601 +			}
   1.602 +
   1.603 +		case WM_IDW_SETLCDAUDIOCODEC:
   1.604 +			{
   1.605 +				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   1.606 +				pFinished = (Event*)lParam;
   1.607 +				pSetLcdIcons->result = 
   1.608 +					IMON_Display_SetLcdAudioCodecIcon(pSetLcdIcons->btIconData);
   1.609 +				pFinished->Signal();
   1.610 +				return 0;
   1.611 +			}
   1.612 +
   1.613 +		case WM_IDW_SETLCDASPECTRATIO:
   1.614 +			{
   1.615 +				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   1.616 +				pFinished = (Event*)lParam;
   1.617 +				pSetLcdIcons->result = 
   1.618 +					IMON_Display_SetLcdAspectRatioIcon(pSetLcdIcons->btIconData);
   1.619 +				pFinished->Signal();
   1.620 +				return 0;
   1.621 +			}
   1.622 +
   1.623 +		case WM_IDW_SETLCDETCICON:
   1.624 +			{
   1.625 +				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
   1.626 +				pFinished = (Event*)lParam;
   1.627 +				pSetLcdIcons->result = 
   1.628 +					IMON_Display_SetLcdEtcIcon(pSetLcdIcons->btIconData);
   1.629 +				pFinished->Signal();
   1.630 +				return 0;
   1.631 +			}
   1.632 +
   1.633 +		case WM_IDW_SETLCDPROGRESS:
   1.634 +			{
   1.635 +				IdwSetLcdProgress* pSetLcdProgress = (IdwSetLcdProgress*)wParam;
   1.636 +				pFinished = (Event*)lParam;
   1.637 +				pSetLcdProgress->result = IMON_Display_SetLcdProgress(
   1.638 +					pSetLcdProgress->nCurPos, pSetLcdProgress->nTotal);
   1.639 +				pFinished->Signal();
   1.640 +				return 0;
   1.641 +			}
   1.642 +
   1.643 +    case WM_IDW_INTERRUPT:
   1.644 +      DestroyWindow(hwnd);
   1.645 +      return 0;
   1.646 +	}
   1.647 +  return DefWindowProc(hwnd, uMsg, wParam, lParam);
   1.648 +}
   1.649 +//------------------------------------------------------------------------------
   1.650 +void IdwThread::MapChars(LPWSTR lpszTarget, LPCWSTR lpszSource,
   1.651 +                         int nMaxLength)
   1.652 +{
   1.653 +  int len = (int)wcslen(lpszSource);
   1.654 +  if ((nMaxLength > 0) && (len > nMaxLength))
   1.655 +    len = nMaxLength;
   1.656 +  lpszTarget[len] = 0;
   1.657 +  for (int i = 0; i < len; ++i)
   1.658 +  {
   1.659 +    wchar_t ch = lpszSource[i];
   1.660 +    lpszTarget[i] = MapChar(ch);
   1.661 +  }
   1.662 +}
   1.663 +//------------------------------------------------------------------------------
   1.664 +#define IN_RANGE(ch, s, e) ((ch >= s) && (ch <= e))
   1.665 +#define IS(ch, c) (ch == c)
   1.666 +wchar_t IdwThread::MapChar(wchar_t ch)
   1.667 +{
   1.668 +  if (IN_RANGE(ch, 0x0020, 0x005B)
   1.669 +   || IN_RANGE(ch, 0x005D, 0x007D)
   1.670 +   || IS(ch, 0x0401)
   1.671 +   || IS(ch, 0x0404)
   1.672 +   || IN_RANGE(ch, 0x0406, 0x0407)
   1.673 +   || IN_RANGE(ch, 0x0410, 0x044F)
   1.674 +   || IS(ch, 0x0451)
   1.675 +   || IS(ch, 0x0454)
   1.676 +   || IN_RANGE(ch, 0x0456, 0x0457)
   1.677 +   || IN_RANGE(ch, 0x0490, 0x0491))
   1.678 +    return ch;
   1.679 +
   1.680 +  switch (ch)
   1.681 +  {
   1.682 +  case 0x5C:
   1.683 +    return 0x8C;
   1.684 +  case 0x7E:
   1.685 +    return 0x8E;
   1.686 +  case 0x7F:
   1.687 +    return 0x20;
   1.688 +  case 0xA2:
   1.689 +    return 0xEC;
   1.690 +  case 0xA3:
   1.691 +    return 0x92;
   1.692 +  case 0xA5:
   1.693 +    return 0x5C;
   1.694 +  case 0xA6:
   1.695 +    return 0x98;
   1.696 +  case 0xA7:
   1.697 +    return 0x8F;
   1.698 +  case 0xB0:
   1.699 +    return 0xDF;
   1.700 +  case 0xB5:
   1.701 +    return 0xE4;
   1.702 +  case 0xC2:
   1.703 +    return 0x82;
   1.704 +  case 0xC4:
   1.705 +    return 0x80;
   1.706 +  case 0xC5:
   1.707 +    return 0x81;
   1.708 +  case 0xC6:
   1.709 +    return 0x90;
   1.710 +  case 0xC7:
   1.711 +    return 0x99;
   1.712 +  case 0xD1:
   1.713 +    return 0xEE;
   1.714 +  case 0xD6:
   1.715 +    return 0x86;
   1.716 +  case 0xD8:
   1.717 +    return 0x88;
   1.718 +  case 0xDC:
   1.719 +    return 0x8A;
   1.720 +  case 0xDE:
   1.721 +    return 0xF0;
   1.722 +  case 0xDF:
   1.723 +    return 0xE2;
   1.724 +  case 0xE1:
   1.725 +    return 0x83;
   1.726 +  case 0xE4:
   1.727 +    return 0xE1;
   1.728 +  case 0xE5:
   1.729 +    return 0x84;
   1.730 +  case 0xE7:
   1.731 +    return 0x99;
   1.732 +  case 0xF1:
   1.733 +    return 0xD1;
   1.734 +  case 0xF6:
   1.735 +    return 0x87;
   1.736 +  case 0xF7:
   1.737 +    return 0xFD;
   1.738 +  case 0xF8:
   1.739 +    return 0x89;
   1.740 +  case 0xFC:
   1.741 +    return 0x8B;
   1.742 +  case 0xFE:
   1.743 +    return 0xF0;
   1.744 +  default:
   1.745 +    return L'#';
   1.746 +  }
   1.747 +}
   1.748 +//------------------------------------------------------------------------------