Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

699 lines
20 KiB

  1. // LogUICtl.cpp : Implementation of the CLogUICtrl OLE control class.
  2. #include "stdafx.h"
  3. #include <iadmw.h>
  4. #include "cnfgprts.h"
  5. #include "LogUICtl.h"
  6. #include "LogUIPpg.h"
  7. #include "wrapmb.h"
  8. #include "metatool.h"
  9. #include <iiscnfg.h>
  10. #include "initguid.h"
  11. #include <inetcom.h>
  12. #include <logtype.h>
  13. #include <ilogobj.hxx>
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CLogUICtrl, COleControl)
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Message map
  22. BEGIN_MESSAGE_MAP(CLogUICtrl, COleControl)
  23. //{{AFX_MSG_MAP(CLogUICtrl)
  24. //}}AFX_MSG_MAP
  25. ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  26. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  27. END_MESSAGE_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Dispatch map
  30. BEGIN_DISPATCH_MAP(CLogUICtrl, COleControl)
  31. //{{AFX_DISPATCH_MAP(CLogUICtrl)
  32. DISP_FUNCTION(CLogUICtrl, "SetAdminTarget", SetAdminTarget, VT_EMPTY, VTS_BSTR VTS_BSTR)
  33. DISP_FUNCTION(CLogUICtrl, "ApplyLogSelection", ApplyLogSelection, VT_EMPTY, VTS_NONE)
  34. DISP_FUNCTION(CLogUICtrl, "SetComboBox", SetComboBox, VT_EMPTY, VTS_HANDLE)
  35. DISP_FUNCTION(CLogUICtrl, "Terminate", Terminate, VT_EMPTY, VTS_NONE)
  36. DISP_STOCKFUNC_DOCLICK()
  37. DISP_STOCKPROP_CAPTION()
  38. DISP_STOCKPROP_FONT()
  39. DISP_STOCKPROP_ENABLED()
  40. DISP_STOCKPROP_BORDERSTYLE()
  41. //}}AFX_DISPATCH_MAP
  42. END_DISPATCH_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Event map
  45. BEGIN_EVENT_MAP(CLogUICtrl, COleControl)
  46. //{{AFX_EVENT_MAP(CLogUICtrl)
  47. EVENT_STOCK_CLICK()
  48. EVENT_STOCK_KEYUP()
  49. EVENT_STOCK_KEYDOWN()
  50. EVENT_STOCK_KEYPRESS()
  51. //}}AFX_EVENT_MAP
  52. END_EVENT_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Property pages
  55. BEGIN_PROPPAGEIDS(CLogUICtrl, 2)
  56. PROPPAGEID(CLogUIPropPage::guid)
  57. PROPPAGEID(CLSID_CFontPropPage)
  58. END_PROPPAGEIDS(CLogUICtrl)
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Initialize class factory and guid
  61. IMPLEMENT_OLECREATE_EX(CLogUICtrl, "CNFGPRTS.LogUICtrl.1",
  62. 0xba634603, 0xb771, 0x11d0, 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b)
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Type library ID and version
  65. IMPLEMENT_OLETYPELIB(CLogUICtrl, _tlid, _wVerMajor, _wVerMinor)
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Interface IDs
  68. const IID BASED_CODE IID_DLogUI =
  69. { 0xba634601, 0xb771, 0x11d0, { 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  70. const IID BASED_CODE IID_DLogUIEvents =
  71. { 0xba634602, 0xb771, 0x11d0, { 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Control type information
  74. static const DWORD BASED_CODE _dwLogUIOleMisc =
  75. OLEMISC_ACTIVATEWHENVISIBLE |
  76. OLEMISC_SETCLIENTSITEFIRST |
  77. OLEMISC_INSIDEOUT |
  78. OLEMISC_CANTLINKINSIDE |
  79. OLEMISC_ACTSLIKEBUTTON |
  80. OLEMISC_RECOMPOSEONRESIZE;
  81. IMPLEMENT_OLECTLTYPE(CLogUICtrl, IDS_LOGUI, _dwLogUIOleMisc)
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CLogUICtrl::CLogUICtrlFactory::UpdateRegistry -
  84. // Adds or removes system registry entries for CLogUICtrl
  85. BOOL CLogUICtrl::CLogUICtrlFactory::UpdateRegistry(BOOL bRegister)
  86. {
  87. // TODO: Verify that your control follows apartment-model threading rules.
  88. // Refer to MFC TechNote 64 for more information.
  89. // If your control does not conform to the apartment-model rules, then
  90. // you must modify the code below, changing the 6th parameter from
  91. // afxRegApartmentThreading to 0.
  92. if (bRegister)
  93. return AfxOleRegisterControlClass(
  94. AfxGetInstanceHandle(),
  95. m_clsid,
  96. m_lpszProgID,
  97. IDS_LOGUI,
  98. IDB_LOGUI,
  99. afxRegApartmentThreading,
  100. _dwLogUIOleMisc,
  101. _tlid,
  102. _wVerMajor,
  103. _wVerMinor);
  104. else
  105. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CLogUICtrl::CLogUICtrl - Constructor
  109. CLogUICtrl::CLogUICtrl():
  110. m_fUpdateFont( FALSE ),
  111. m_fComboInit( FALSE ),
  112. m_hAccel( NULL ),
  113. m_cAccel( 0 )
  114. {
  115. InitializeIIDs(&IID_DLogUI, &IID_DLogUIEvents);
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CLogUICtrl::~CLogUICtrl - Destructor
  119. CLogUICtrl::~CLogUICtrl()
  120. {
  121. if ( m_hAccel )
  122. DestroyAcceleratorTable( m_hAccel );
  123. m_hAccel = NULL;
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CLogUICtrl::OnDraw - Drawing function
  127. void CLogUICtrl::OnDraw(
  128. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  129. {
  130. DoSuperclassPaint(pdc, rcBounds);
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CLogUICtrl::DoPropExchange - Persistence support
  134. void CLogUICtrl::DoPropExchange(CPropExchange* pPX)
  135. {
  136. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  137. COleControl::DoPropExchange(pPX);
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CLogUICtrl::OnResetState - Reset control to default state
  141. void CLogUICtrl::OnResetState()
  142. {
  143. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  144. }
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CLogUICtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  147. BOOL CLogUICtrl::PreCreateWindow(CREATESTRUCT& cs)
  148. {
  149. if ( cs.style & WS_CLIPSIBLINGS )
  150. cs.style ^= WS_CLIPSIBLINGS;
  151. cs.lpszClass = _T("BUTTON");
  152. return COleControl::PreCreateWindow(cs);
  153. }
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CLogUICtrl::IsSubclassedControl - This is a subclassed control
  156. BOOL CLogUICtrl::IsSubclassedControl()
  157. {
  158. return TRUE;
  159. }
  160. /////////////////////////////////////////////////////////////////////////////
  161. // CLogUICtrl::OnOcmCommand - Handle command messages
  162. LRESULT CLogUICtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  163. {
  164. #ifdef _WIN32
  165. WORD wNotifyCode = HIWORD(wParam);
  166. #else
  167. WORD wNotifyCode = HIWORD(lParam);
  168. #endif
  169. return 0;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CLogUICtrl message handlers
  173. //---------------------------------------------------------------------------
  174. // OLE Interfaced Routine
  175. void CLogUICtrl::OnClick(USHORT iButton)
  176. {
  177. CWaitCursor wait;
  178. IID iid;
  179. HRESULT h;
  180. OLECHAR* poch = NULL;
  181. // in case there are any errors, prepare the error string
  182. CString sz;
  183. // set the name of the application correctly
  184. sz.LoadString( IDS_LOG_ERR_TITLE );
  185. // free the existing name, and copy in the new one
  186. free((void*)AfxGetApp()->m_pszAppName);
  187. AfxGetApp()->m_pszAppName = _tcsdup(sz);
  188. // get the string IID of the current item in the combo box
  189. CString szIID;
  190. if ( GetSelectedStringIID( szIID ) )
  191. {
  192. // convert the string to an IID that we can use
  193. h = CLSIDFromString( (LPTSTR)(LPCTSTR)szIID, &iid );
  194. // do it to it
  195. ActivateLogProperties( (LPTSTR)(LPCTSTR)m_szMachine, iid );
  196. }
  197. // don't fire anything off
  198. COleControl::OnClick(iButton);
  199. }
  200. //---------------------------------------------------------------------------
  201. void CLogUICtrl::OnFontChanged()
  202. {
  203. m_fUpdateFont = TRUE;
  204. COleControl::OnFontChanged();
  205. }
  206. //---------------------------------------------------------------------------
  207. void CLogUICtrl::SetAdminTarget(LPCTSTR szMachineName, LPCTSTR szMetaTarget)
  208. {
  209. m_szMachine = szMachineName;
  210. m_szMetaObject = szMetaTarget;
  211. }
  212. //---------------------------------------------------------------------------
  213. void CLogUICtrl::ActivateLogProperties( OLECHAR* pocMachineName, REFIID clsidUI )
  214. {
  215. AFX_MANAGE_STATE(::AfxGetStaticModuleState());
  216. IClassFactory* pcsfFactory = NULL;
  217. HRESULT hresError;
  218. ILogUIPlugin* pUI;
  219. hresError = CoGetClassObject( clsidUI, CLSCTX_INPROC, NULL,
  220. IID_IClassFactory, (void**) &pcsfFactory);
  221. if (FAILED(hresError))
  222. return;
  223. // create the instance of the interface
  224. hresError = pcsfFactory->CreateInstance(NULL, IID_LOGGINGUI, (void **)&pUI);
  225. if (FAILED(hresError))
  226. {
  227. return;
  228. }
  229. // release the factory
  230. pcsfFactory->Release();
  231. // activate the logging ui
  232. hresError = pUI->OnProperties( (LPTSTR)(LPCTSTR)m_szMachine, (LPTSTR)(LPCTSTR)m_szMetaObject );
  233. // release the logging ui
  234. pUI->Release();
  235. }
  236. //---------------------------------------------------------------------------
  237. // OLE Interfaced Routine
  238. // first we get the appropriate module IID string from the logging tree. Then
  239. // we put it into place in the metabase target
  240. void CLogUICtrl::ApplyLogSelection()
  241. {
  242. TCHAR buff[MAX_PATH];
  243. BOOL fGotIt;
  244. CString szGUID;
  245. // start with the current string in the combo box
  246. CString szName;
  247. m_comboBox.GetWindowText( szName );
  248. // if nothing is selected, fail
  249. if ( szName.IsEmpty() ) return;
  250. // prep the metabase
  251. IMSAdminBase* pMB;
  252. if ( !FInitMetabaseWrapperEx( (LPTSTR)(LPCTSTR)m_szMachine, &pMB ) )
  253. return;
  254. CWrapMetaBase mbWrap;
  255. if ( !mbWrap.FInit(pMB) ) return;
  256. // open the root logging node
  257. if ( mbWrap.Open( _T("/lm/logging"), METADATA_PERMISSION_READ ) )
  258. {
  259. // get the guid ui string
  260. fGotIt = mbWrap.GetString( szName, MD_LOG_PLUGIN_MOD_ID, IIS_MD_UT_SERVER, buff, sizeof( buff ));
  261. mbWrap.Close();
  262. if ( fGotIt )
  263. szGUID = buff;
  264. }
  265. // open the target metabase location for writing
  266. if ( fGotIt )
  267. {
  268. SetMetaString(pMB, m_szMachine, m_szMetaObject, _T(""), MD_LOG_PLUGIN_ORDER,
  269. IIS_MD_UT_SERVER, szGUID, TRUE);
  270. }
  271. // clean up
  272. FCloseMetabaseWrapperEx(&pMB);
  273. }
  274. //---------------------------------------------------------------------------
  275. BOOL CLogUICtrl::GetSelectedStringIID( CString &szIID )
  276. {
  277. if ( !m_fComboInit ) return FALSE;
  278. // start with the current string in the combo box
  279. CString szName;
  280. m_comboBox.GetWindowText( szName );
  281. // if nothing is selected, fail
  282. if ( szName.IsEmpty() ) return FALSE;
  283. // prep the metabase
  284. IMSAdminBase* pMB;
  285. if ( !FInitMetabaseWrapperEx( (LPTSTR)(LPCTSTR)m_szMachine, &pMB ) )
  286. return FALSE;
  287. CWrapMetaBase mbWrap;
  288. if ( !mbWrap.FInit(pMB) ) return FALSE;
  289. // open the root logging node
  290. if ( mbWrap.Open( _T("/lm/logging"), METADATA_PERMISSION_READ ) )
  291. {
  292. // get the guid ui string
  293. TCHAR buff[MAX_PATH];
  294. if ( mbWrap.GetString( szName, MD_LOG_PLUGIN_UI_ID, IIS_MD_UT_SERVER, buff, sizeof( buff )) )
  295. szIID = buff;
  296. mbWrap.Close();
  297. }
  298. // clean up
  299. FCloseMetabaseWrapperEx(&pMB);
  300. // return the answer
  301. return !szIID.IsEmpty();
  302. }
  303. //---------------------------------------------------------------------------
  304. // OLE Interfaced Routine
  305. void CLogUICtrl::SetComboBox(HWND hComboBox)
  306. {
  307. TCHAR buff[MAX_PATH];
  308. BOOL f;
  309. DWORD dw;
  310. CString szAvailableList;
  311. CString szCurrentModGuid;
  312. CString szCurrentModName;
  313. // in case there are any errors, prepare the error string
  314. // set the name of the application correctly
  315. szAvailableList.LoadString( IDS_LOG_ERR_TITLE );
  316. // free the existing name, and copy in the new one
  317. free((void*)AfxGetApp()->m_pszAppName);
  318. AfxGetApp()->m_pszAppName = _tcsdup(szAvailableList);
  319. szAvailableList.Empty();
  320. // attach the combo box
  321. m_comboBox.Attach(hComboBox);
  322. m_fComboInit = TRUE;
  323. // fill in the combo box
  324. // prepare the metabase wrapper
  325. IMSAdminBase* pMB;
  326. if ( !FInitMetabaseWrapperEx( (LPTSTR)(LPCTSTR)m_szMachine, &pMB ) )
  327. return;
  328. CWrapMetaBase mbWrap;
  329. if ( !mbWrap.FInit(pMB) ) return;
  330. // get the guid string of the currently selected logging module
  331. if ( mbWrap.Open( m_szMetaObject, METADATA_PERMISSION_READ ) )
  332. {
  333. // start by getting the current module ID
  334. f = mbWrap.GetString( _T(""), MD_LOG_PLUGIN_ORDER, IIS_MD_UT_SERVER, buff, sizeof(buff));
  335. szCurrentModGuid = buff;
  336. // if we couldn't get the value, then there is a problem
  337. if ( !f )
  338. {
  339. DWORD err;
  340. err = GetLastError();
  341. AfxMessageBox( IDS_ERR_LOG_PLUGIN );
  342. }
  343. mbWrap.Close();
  344. }
  345. // unfortunately, we need to chop off the end to get the plugins available location
  346. DWORD chFirst = m_szMetaObject.Find(_T('/')) + 1;
  347. CString szService = m_szMetaObject.Right(m_szMetaObject.GetLength() - chFirst);
  348. // be careful of the master properties node
  349. INT iSlash = szService.Find(_T('/'));
  350. if ( iSlash < 0 )
  351. szService = m_szMetaObject; // it is the root node already
  352. else
  353. szService = m_szMetaObject.Left( szService.Find(_T('/')) + chFirst );
  354. // get the list of available modues
  355. if ( mbWrap.Open( szService, METADATA_PERMISSION_READ ) )
  356. {
  357. // get thelist of available ui modules
  358. WCHAR* pstr = (WCHAR*)mbWrap.GetData( _T("/info"), MD_LOG_PLUGINS_AVAILABLE, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  359. if ( pstr )
  360. {
  361. szAvailableList = pstr;
  362. mbWrap.FreeWrapData( (PVOID)pstr );
  363. }
  364. // close the metabase
  365. mbWrap.Close();
  366. };
  367. // open the root logging node
  368. if ( !mbWrap.Open( _T("/lm/logging"), METADATA_PERMISSION_READ ) )
  369. return;
  370. // enumerate the sub-items, adding each to the combo-box - if it is in the avail list
  371. // the reason we are checking against the logging module GUID is that is how we
  372. // can tell which is the currently selected item
  373. DWORD index = 0;
  374. BOOL fFoundCurrent = FALSE;
  375. while ( mbWrap.EnumObjects(_T(""), buff, sizeof(buff), index) )
  376. {
  377. CString szName = buff;
  378. // make sure it is in the list of available modules
  379. if ( szAvailableList.Find(szName) < 0 )
  380. {
  381. index++;
  382. continue;
  383. }
  384. // check against the current item's guid
  385. f = mbWrap.GetString( szName, MD_LOG_PLUGIN_MOD_ID, IIS_MD_UT_SERVER, buff, sizeof(buff));
  386. if ( !fFoundCurrent && f )
  387. {
  388. if ( szCurrentModGuid == buff )
  389. {
  390. szCurrentModName = szName;
  391. fFoundCurrent = TRUE;
  392. }
  393. }
  394. // add the item to the combo box
  395. m_comboBox.AddString( szName );
  396. // increment the index
  397. index++;
  398. }
  399. // select the current item in the combo box
  400. m_comboBox.SelectString( -1, szCurrentModName );
  401. // close the metabase
  402. mbWrap.Close();
  403. // clean up
  404. FCloseMetabaseWrapperEx(&pMB);
  405. }
  406. //---------------------------------------------------------------------------
  407. // OLE Interfaced Routine
  408. void CLogUICtrl::Terminate()
  409. {
  410. if ( m_fComboInit )
  411. m_comboBox.Detach();
  412. m_fComboInit = FALSE;
  413. }
  414. //------------------------------------------------------------------------
  415. // get the inetinfo path
  416. BOOL CLogUICtrl::GetServerDirectory( CString &sz )
  417. {
  418. HKEY hKey;
  419. TCHAR chBuff[MAX_PATH+1];
  420. DWORD err, type;
  421. DWORD cbBuff;
  422. // get the server install path from the registry
  423. // open the registry key, if it exists
  424. err = RegOpenKeyEx(
  425. HKEY_LOCAL_MACHINE, // handle of open key
  426. REGKEY_STP, // address of name of subkey to open
  427. 0, // reserved
  428. KEY_READ, // security access mask
  429. &hKey // address of handle of open key
  430. );
  431. // if we did not open the key for any reason (say... it doesn't exist)
  432. // then leave right away
  433. if ( err != ERROR_SUCCESS )
  434. return FALSE;
  435. cbBuff = sizeof(chBuff);
  436. type = REG_SZ;
  437. err = RegQueryValueEx(
  438. hKey, // handle of key to query
  439. REGKEY_INSTALLKEY, // address of name of value to query
  440. NULL, // reserved
  441. &type, // address of buffer for value type
  442. (PUCHAR)chBuff, // address of data buffer
  443. &cbBuff // address of data buffer size
  444. );
  445. // close the key
  446. RegCloseKey( hKey );
  447. // if we did get the key for any reason (say... it doesn't exist)
  448. // then leave right away
  449. if ( err != ERROR_SUCCESS )
  450. return FALSE;
  451. // set the string
  452. sz = chBuff;
  453. // success
  454. return TRUE;
  455. }
  456. //------------------------------------------------------------------------
  457. void CLogUICtrl::OnAmbientPropertyChange(DISPID dispid)
  458. {
  459. BOOL flag;
  460. UINT style;
  461. // do the right thing depending on the dispid
  462. switch ( dispid )
  463. {
  464. case DISPID_AMBIENT_DISPLAYASDEFAULT:
  465. if ( GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &flag ) )
  466. {
  467. style = GetWindowLong(
  468. GetSafeHwnd(), // handle of window
  469. GWL_STYLE // offset of value to retrieve
  470. );
  471. if ( flag )
  472. style |= BS_DEFPUSHBUTTON;
  473. else
  474. style ^= BS_DEFPUSHBUTTON;
  475. SetWindowLong(
  476. GetSafeHwnd(), // handle of window
  477. GWL_STYLE, // offset of value to retrieve
  478. style
  479. );
  480. Invalidate(TRUE);
  481. }
  482. break;
  483. };
  484. COleControl::OnAmbientPropertyChange(dispid);
  485. }
  486. //------------------------------------------------------------------------
  487. // an important method where we tell the container how to deal with us.
  488. // pControlInfo is passed in by the container, although we are responsible
  489. // for maintining the hAccel structure
  490. void CLogUICtrl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
  491. {
  492. // do a rudimentary check to see if we understand pControlInfo
  493. if ( !pControlInfo || pControlInfo->cb < sizeof(CONTROLINFO) )
  494. return;
  495. // set the accelerator handle into place
  496. pControlInfo->hAccel = m_hAccel;
  497. pControlInfo->cAccel = m_cAccel;
  498. // when we have focus, we do want the enter key
  499. pControlInfo->dwFlags = CTRLINFO_EATS_RETURN;
  500. }
  501. //------------------------------------------------------------------------
  502. // the ole control container object specifically filters out the space
  503. // key so we do not get it as a OnMnemonic call. Thus we need to look
  504. // for it ourselves
  505. void CLogUICtrl::OnKeyUpEvent(USHORT nChar, USHORT nShiftState)
  506. {
  507. if ( nChar == _T(' ') )
  508. {
  509. OnClick((USHORT)GetDlgCtrlID());
  510. }
  511. COleControl::OnKeyUpEvent(nChar, nShiftState);
  512. }
  513. //------------------------------------------------------------------------
  514. void CLogUICtrl::OnMnemonic(LPMSG pMsg)
  515. {
  516. OnClick((USHORT)GetDlgCtrlID());
  517. COleControl::OnMnemonic(pMsg);
  518. }
  519. //------------------------------------------------------------------------
  520. void CLogUICtrl::OnTextChanged()
  521. {
  522. // get the new text
  523. CString sz = InternalGetText();
  524. // set the accelerator table
  525. SetAccelTable((LPCTSTR)sz);
  526. if ( SetAccelTable((LPCTSTR)sz) )
  527. // make sure the new accelerator table gets loaded
  528. ControlInfoChanged();
  529. // finish with the default handling.
  530. COleControl::OnTextChanged();
  531. }
  532. //------------------------------------------------------------------------
  533. BOOL CLogUICtrl::SetAccelTable( LPCTSTR pszCaption )
  534. {
  535. BOOL fAnswer = FALSE;
  536. ACCEL accel;
  537. int iAccel;
  538. // get the new text
  539. CString sz = pszCaption;
  540. sz.MakeLower();
  541. // if the handle has already been allocated, free it
  542. if ( m_hAccel )
  543. {
  544. DestroyAcceleratorTable( m_hAccel );
  545. m_hAccel = NULL;
  546. m_cAccel = 0;
  547. }
  548. // if there is a & character, then declare the accelerator
  549. iAccel = sz.Find(_T('&'));
  550. if ( iAccel >= 0 )
  551. {
  552. // fill in the accererator record
  553. accel.fVirt = FALT;
  554. accel.key = sz.GetAt(iAccel + 1);
  555. accel.cmd = (USHORT)GetDlgCtrlID();
  556. m_hAccel = CreateAcceleratorTable( &accel, 1 );
  557. if ( m_hAccel )
  558. m_cAccel = 1;
  559. fAnswer = TRUE;
  560. }
  561. // return the answer
  562. return fAnswer;
  563. }