PsycleWTL:Win32 GUI Genericsを使用した再構築

公開:2005-01-03 18:28
更新:2020-02-15 04:36
カテゴリ:psycle wtl,windows,audio,tracker

今日は「プログラム初め」です。
DirectSound設定ダイアログをWin32 GUI Generics化しはじめました。
ダイアログの表示までは何とかできたのですが、WTLでいうExecuteDlgInit()にあたるものが見当たりません。
そういうわけでdialogクラスを少し拡張し、コンストラクタでExecuteDlgInit()にあたる処理を追加したクラスを作りました。
ExecuteDlgInit()にあたる部分はほとんどWTLのコードの「まんま」です。
とりあえずこれで動いてますが、エラー時に例外を投げるように改良しようと思います。

000001  #pragma once
000002  /* @file
000003   
  @brief 
000004     $Date: 2004/06/20 21:05:52 $
000005   
  $Revision: 1.2 $
000006   /

000007  namespace win32 {
000008      namespace gui {
000009          templateclass base > 
000010          struct ex_dialog : public win32::gui::dialog
000011          {
000012              ex_dialog(const string & title = string(), create_subdialogs_type create = do_create_subdialogs ) 
000013                  : ::win32::gui::dialog(title,create)
000014              {
000015                  init_dialog_items();
000016              };
000017          private:
000018              void init_dialog_items()
000019              {   
000020                  const HINSTANCE _res_inst = resource_instance();
000021                  const int _dialog_id = static_cast<base&>(
this).dialog_id();
000022                  const HRSRC _hrsrc = ::FindResource(_res_inst, MAKEINTRESOURCE(_dialog_id), _ATL_RT_DLGINIT);
000023                  if (_hrsrc)
000024                  {
000025                      HGLOBAL _hres_data = ::LoadResource(_res_inst, _hrsrc);
000026                      if (_hres_data)
000027                      {
000028                          UNALIGNED WORD _pdlg_init = (UNALIGNED WORD)::LockResource(_hres_data);
000029                          if (_pdlg_init)
000030                          {
000031                              BOOL bSuccess = TRUE;
000032                              while (bSuccess && NULL != _pdlg_init)
000033                              {
000034                                  WORD wID = 
_pdlg_init++;
000035                                  WORD wMsg = _pdlg_init++;
000036                                  DWORD dwSize = 
((UNALIGNED DWORD*&)_pdlg_init)++;
000037 
000038                                  // CB_ADDSTRING is stored as 0x403
000039                                  if (0x403 == wMsg)
000040                                  {
000041                                      if (-1 == ::SendDlgItemMessage(m_hwnd,wID, CB_ADDSTRING, 0, (LPARAM)((LPCTSTR)CA2T((LPSTR)_pdlg_init))))
000042                                          bSuccess = FALSE;
000043                                  }
000044                                  // CBEM_INSERTITEM is stored as 0x1234
000045                                  else if (0x1234 == wMsg)
000046                                  {
000047                                      COMBOBOXEXITEM item;
000048                                      item.mask = CBEIF_TEXT;
000049                                      item.iItem = -1;
000050                                      CA2T _text((LPSTR)(_pdlg_init));
000051                                      item.pszText = _text;
000052                                      if (-1 == ::SendDlgItemMessage(m_hwnd,wID, CBEM_INSERTITEM, 0, (LPARAM)&item))
000053                                          bSuccess = FALSE;
000054                                  }
000055                                  _pdlg_init = (LPWORD)((LPBYTE)_pdlg_init + dwSize);
000056                              }
000057                          }
000058                      }
000059                  }
000060              };
000061          };
000062      }
000063  }

例外を投げるようにしたバージョンです。 ほとんど変わりませんけどね...。

000001  #pragma once 000002  /* @file 000003     @brief  000004     $Date: 2004/06/20 21:05:52 $ 000005     $Revision: 1.2 $ 000006   / 000007  namespace win32 { 000008      namespace gui { 000009          templateclass base >  000010          struct ex_dialog : public win32::gui::dialog 000011          { 000012              ex_dialog(const string & title = string(), create_subdialogs_type create = do_create_subdialogs )  000013                  : ::win32::gui::dialog(title,create) 000014              { 000015                  init_dialog_items(); 000016              }; 000017          private: 000018              void init_dialog_items() 000019              {    000020                  const HINSTANCE _res_inst = resource_instance(); 000021                  const int _dialog_id = static_cast<base&>(this).dialog_id(); 000022                  const HRSRC _hrsrc = ::FindResource(_res_inst, MAKEINTRESOURCE(_dialog_id), _ATL_RT_DLGINIT); 000023                  if (_hrsrc) 000024                  { 000025                      HGLOBAL _hres_data = ::LoadResource(_res_inst, _hrsrc); 000026                      if (_hres_data) 000027                      { 000028                          UNALIGNED WORD _pdlg_init = (UNALIGNED WORD)::LockResource(_hres_data); 000029                          if (_pdlg_init) 000030                          { 000031                              while (NULL != _pdlg_init) 000032                              { 000033                                  WORD wID = _pdlg_init++; 000034                                  WORD wMsg = _pdlg_init++; 000035                                  DWORD dwSize = ((UNALIGNED DWORD*&)_pdlg_init)++; 000036  000037                                  // CB_ADDSTRING is stored as 0x403 000038                                  if (0x403 == wMsg) 000039                                  { 000040                                      if (-1 == ::SendDlgItemMessage(m_hwnd,wID, CB_ADDSTRING, 0, (LPARAM)((LPCTSTR)CA2T((LPSTR)_pdlg_init)))) 000041                                      { 000042                                          WIN32GUI_THROW exception((format(_T("error: file: %s  line: %d")) % FILE % LINE).str()); 000043                                      } 000044                                  } 000045                                  // CBEM_INSERTITEM is stored as 0x1234 000046                                  else if (0x1234 == wMsg) 000047                                  { 000048                                      COMBOBOXEXITEM item; 000049                                      item.mask = CBEIF_TEXT; 000050                                      item.iItem = -1; 000051                                      CA2T _text((LPSTR)(_pdlg_init)); 000052                                      item.pszText = _text; 000053                                      if (-1 == ::SendDlgItemMessage(m_hwnd,wID, CBEM_INSERTITEM, 0, (LPARAM)&item)){ 000054                                          WIN32GUI_THROW exception((format(_T("error: file: %s  line: %d")) % FILE % LINE).str()); 000055                                      } 000056                                  } 000057                                  _pdlg_init = (LPWORD)((LPBYTE)_pdlg_init + dwSize); 000058                              } 000059                          } 000060                      } 000061                  } 000062              }; 000063          }; 000064      } 000065  }