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.

703 lines
21 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. IClassFactory* pcsfFactory = NULL;
  216. HRESULT hresError;
  217. ILogUIPlugin* pUI;
  218. hresError = CoGetClassObject( clsidUI, CLSCTX_INPROC, NULL,
  219. IID_IClassFactory, (void**) &pcsfFactory);
  220. if (FAILED(hresError))
  221. return;
  222. // create the instance of the interface
  223. hresError = pcsfFactory->CreateInstance(NULL, IID_LOGGINGUI, (void **)&pUI);
  224. if (FAILED(hresError))
  225. {
  226. return;
  227. }
  228. // release the factory
  229. pcsfFactory->Release();
  230. // activate the logging ui
  231. hresError = pUI->OnProperties( (LPTSTR)(LPCTSTR)m_szMachine, (LPTSTR)(LPCTSTR)m_szMetaObject );
  232. // release the logging ui
  233. pUI->Release();
  234. }
  235. //---------------------------------------------------------------------------
  236. // OLE Interfaced Routine
  237. // first we get the appropriate module IID string from the logging tree. Then
  238. // we put it into place in the metabase target
  239. void CLogUICtrl::ApplyLogSelection()
  240. {
  241. TCHAR buff[MAX_PATH];
  242. DWORD dw;
  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 = FInitMetabaseWrapper( (LPTSTR)(LPCTSTR)m_szMachine );
  252. if ( !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. dw = sizeof( buff );
  261. fGotIt = mbWrap.GetString( szName, MD_LOG_PLUGIN_MOD_ID, IIS_MD_UT_SERVER, buff, &dw);
  262. mbWrap.Close();
  263. if ( fGotIt )
  264. szGUID = buff;
  265. }
  266. // open the target metabase location for writing
  267. if ( fGotIt )
  268. {
  269. SetMetaString(pMB, m_szMachine, m_szMetaObject, _T(""), MD_LOG_PLUGIN_ORDER,
  270. IIS_MD_UT_SERVER, szGUID, TRUE);
  271. }
  272. // clean up
  273. FCloseMetabaseWrapper(pMB);
  274. }
  275. //---------------------------------------------------------------------------
  276. BOOL CLogUICtrl::GetSelectedStringIID( CString &szIID )
  277. {
  278. if ( !m_fComboInit ) return FALSE;
  279. // start with the current string in the combo box
  280. CString szName;
  281. m_comboBox.GetWindowText( szName );
  282. // if nothing is selected, fail
  283. if ( szName.IsEmpty() ) return FALSE;
  284. // prep the metabase
  285. IMSAdminBase* pMB = FInitMetabaseWrapper( (LPTSTR)(LPCTSTR)m_szMachine );
  286. if ( !pMB )
  287. return FALSE;
  288. CWrapMetaBase mbWrap;
  289. if ( !mbWrap.FInit(pMB) ) return FALSE;
  290. // open the root logging node
  291. if ( mbWrap.Open( _T("/lm/logging"), METADATA_PERMISSION_READ ) )
  292. {
  293. // get the guid ui string
  294. TCHAR buff[MAX_PATH];
  295. DWORD dw;
  296. dw = sizeof( buff );
  297. if ( mbWrap.GetString( szName, MD_LOG_PLUGIN_UI_ID, IIS_MD_UT_SERVER, buff, &dw) )
  298. szIID = buff;
  299. mbWrap.Close();
  300. }
  301. // clean up
  302. FCloseMetabaseWrapper(pMB);
  303. // return the answer
  304. return !szIID.IsEmpty();
  305. }
  306. //---------------------------------------------------------------------------
  307. // OLE Interfaced Routine
  308. void CLogUICtrl::SetComboBox(HWND hComboBox)
  309. {
  310. TCHAR buff[MAX_PATH];
  311. DWORD dw;
  312. BOOL f;
  313. CString szAvailableList;
  314. CString szCurrentModGuid;
  315. CString szCurrentModName;
  316. // in case there are any errors, prepare the error string
  317. // set the name of the application correctly
  318. szAvailableList.LoadString( IDS_LOG_ERR_TITLE );
  319. // free the existing name, and copy in the new one
  320. free((void*)AfxGetApp()->m_pszAppName);
  321. AfxGetApp()->m_pszAppName = _tcsdup(szAvailableList);
  322. szAvailableList.Empty();
  323. // attach the combo box
  324. m_comboBox.Attach(hComboBox);
  325. m_fComboInit = TRUE;
  326. // fill in the combo box
  327. // prepare the metabase wrapper
  328. IMSAdminBase* pMB = FInitMetabaseWrapper( (LPTSTR)(LPCTSTR)m_szMachine );
  329. if ( !pMB )
  330. return;
  331. CWrapMetaBase mbWrap;
  332. if ( !mbWrap.FInit(pMB) ) return;
  333. // get the guid string of the currently selected logging module
  334. if ( mbWrap.Open( m_szMetaObject, METADATA_PERMISSION_READ ) )
  335. {
  336. dw = sizeof(buff);
  337. // start by getting the current module ID
  338. f = mbWrap.GetString( _T(""), MD_LOG_PLUGIN_ORDER, IIS_MD_UT_SERVER, buff, &dw);
  339. szCurrentModGuid = buff;
  340. // if we couldn't get the value, then there is a problem
  341. if ( !f )
  342. {
  343. DWORD err;
  344. err = GetLastError();
  345. AfxMessageBox( IDS_ERR_LOG_PLUGIN );
  346. }
  347. mbWrap.Close();
  348. }
  349. // unfortunately, we need to chop off the end to get the plugins available location
  350. DWORD chFirst = m_szMetaObject.Find(_T('/')) + 1;
  351. CString szService = m_szMetaObject.Right(m_szMetaObject.GetLength() - chFirst);
  352. // be careful of the master properties node
  353. INT iSlash = szService.Find(_T('/'));
  354. if ( iSlash < 0 )
  355. szService = m_szMetaObject; // it is the root node already
  356. else
  357. szService = m_szMetaObject.Left( szService.Find(_T('/')) + chFirst );
  358. // get the list of available modues
  359. if ( mbWrap.Open( szService, METADATA_PERMISSION_READ ) )
  360. {
  361. // get thelist of available ui modules
  362. WCHAR* pstr = (WCHAR*)mbWrap.GetData( _T("/info"), MD_LOG_PLUGINS_AVAILABLE, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  363. if ( pstr )
  364. {
  365. szAvailableList = pstr;
  366. mbWrap.FreeWrapData( (PVOID)pstr );
  367. }
  368. // close the metabase
  369. mbWrap.Close();
  370. };
  371. // open the root logging node
  372. if ( !mbWrap.Open( _T("/lm/logging"), METADATA_PERMISSION_READ ) )
  373. return;
  374. // enumerate the sub-items, adding each to the combo-box - if it is in the avail list
  375. // the reason we are checking against the logging module GUID is that is how we
  376. // can tell which is the currently selected item
  377. DWORD index = 0;
  378. BOOL fFoundCurrent = FALSE;
  379. while ( mbWrap.EnumObjects(_T(""), buff, index) )
  380. {
  381. CString szName = buff;
  382. // make sure it is in the list of available modules
  383. if ( szAvailableList.Find(szName) < 0 )
  384. {
  385. index++;
  386. continue;
  387. }
  388. // check against the current item's guid
  389. dw = sizeof(buff);
  390. f = mbWrap.GetString( szName, MD_LOG_PLUGIN_MOD_ID, IIS_MD_UT_SERVER, buff, &dw);
  391. if ( !fFoundCurrent && f )
  392. {
  393. if ( szCurrentModGuid == buff )
  394. {
  395. szCurrentModName = szName;
  396. fFoundCurrent = TRUE;
  397. }
  398. }
  399. // add the item to the combo box
  400. m_comboBox.AddString( szName );
  401. // increment the index
  402. index++;
  403. }
  404. // select the current item in the combo box
  405. m_comboBox.SelectString( -1, szCurrentModName );
  406. // close the metabase
  407. mbWrap.Close();
  408. // clean up
  409. FCloseMetabaseWrapper(pMB);
  410. }
  411. //---------------------------------------------------------------------------
  412. // OLE Interfaced Routine
  413. void CLogUICtrl::Terminate()
  414. {
  415. if ( m_fComboInit )
  416. m_comboBox.Detach();
  417. m_fComboInit = FALSE;
  418. }
  419. //------------------------------------------------------------------------
  420. // get the inetinfo path
  421. BOOL CLogUICtrl::GetServerDirectory( CString &sz )
  422. {
  423. HKEY hKey;
  424. TCHAR chBuff[MAX_PATH+1];
  425. DWORD err, type;
  426. DWORD cbBuff;
  427. // get the server install path from the registry
  428. // open the registry key, if it exists
  429. err = RegOpenKeyEx(
  430. HKEY_LOCAL_MACHINE, // handle of open key
  431. REGKEY_STP, // address of name of subkey to open
  432. 0, // reserved
  433. KEY_READ, // security access mask
  434. &hKey // address of handle of open key
  435. );
  436. // if we did not open the key for any reason (say... it doesn't exist)
  437. // then leave right away
  438. if ( err != ERROR_SUCCESS )
  439. return FALSE;
  440. cbBuff = sizeof(chBuff);
  441. type = REG_SZ;
  442. err = RegQueryValueEx(
  443. hKey, // handle of key to query
  444. REGKEY_INSTALLKEY, // address of name of value to query
  445. NULL, // reserved
  446. &type, // address of buffer for value type
  447. (PUCHAR)chBuff, // address of data buffer
  448. &cbBuff // address of data buffer size
  449. );
  450. // close the key
  451. RegCloseKey( hKey );
  452. // if we did get the key for any reason (say... it doesn't exist)
  453. // then leave right away
  454. if ( err != ERROR_SUCCESS )
  455. return FALSE;
  456. // set the string
  457. sz = chBuff;
  458. // success
  459. return TRUE;
  460. }
  461. //------------------------------------------------------------------------
  462. void CLogUICtrl::OnAmbientPropertyChange(DISPID dispid)
  463. {
  464. BOOL flag;
  465. UINT style;
  466. // do the right thing depending on the dispid
  467. switch ( dispid )
  468. {
  469. case DISPID_AMBIENT_DISPLAYASDEFAULT:
  470. if ( GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &flag ) )
  471. {
  472. style = GetWindowLong(
  473. GetSafeHwnd(), // handle of window
  474. GWL_STYLE // offset of value to retrieve
  475. );
  476. if ( flag )
  477. style |= BS_DEFPUSHBUTTON;
  478. else
  479. style ^= BS_DEFPUSHBUTTON;
  480. SetWindowLong(
  481. GetSafeHwnd(), // handle of window
  482. GWL_STYLE, // offset of value to retrieve
  483. style
  484. );
  485. Invalidate(TRUE);
  486. }
  487. break;
  488. };
  489. COleControl::OnAmbientPropertyChange(dispid);
  490. }
  491. //------------------------------------------------------------------------
  492. // an important method where we tell the container how to deal with us.
  493. // pControlInfo is passed in by the container, although we are responsible
  494. // for maintining the hAccel structure
  495. void CLogUICtrl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
  496. {
  497. // do a rudimentary check to see if we understand pControlInfo
  498. if ( !pControlInfo || pControlInfo->cb < sizeof(CONTROLINFO) )
  499. return;
  500. // set the accelerator handle into place
  501. pControlInfo->hAccel = m_hAccel;
  502. pControlInfo->cAccel = m_cAccel;
  503. // when we have focus, we do want the enter key
  504. pControlInfo->dwFlags = CTRLINFO_EATS_RETURN;
  505. }
  506. //------------------------------------------------------------------------
  507. // the ole control container object specifically filters out the space
  508. // key so we do not get it as a OnMnemonic call. Thus we need to look
  509. // for it ourselves
  510. void CLogUICtrl::OnKeyUpEvent(USHORT nChar, USHORT nShiftState)
  511. {
  512. if ( nChar == _T(' ') )
  513. {
  514. OnClick((USHORT)GetDlgCtrlID());
  515. }
  516. COleControl::OnKeyUpEvent(nChar, nShiftState);
  517. }
  518. //------------------------------------------------------------------------
  519. void CLogUICtrl::OnMnemonic(LPMSG pMsg)
  520. {
  521. OnClick((USHORT)GetDlgCtrlID());
  522. COleControl::OnMnemonic(pMsg);
  523. }
  524. //------------------------------------------------------------------------
  525. void CLogUICtrl::OnTextChanged()
  526. {
  527. // get the new text
  528. CString sz = InternalGetText();
  529. // set the accelerator table
  530. SetAccelTable((LPCTSTR)sz);
  531. if ( SetAccelTable((LPCTSTR)sz) )
  532. // make sure the new accelerator table gets loaded
  533. ControlInfoChanged();
  534. // finish with the default handling.
  535. COleControl::OnTextChanged();
  536. }
  537. //------------------------------------------------------------------------
  538. BOOL CLogUICtrl::SetAccelTable( LPCTSTR pszCaption )
  539. {
  540. BOOL fAnswer = FALSE;
  541. ACCEL accel;
  542. int iAccel;
  543. // get the new text
  544. CString sz = pszCaption;
  545. sz.MakeLower();
  546. // if the handle has already been allocated, free it
  547. if ( m_hAccel )
  548. {
  549. DestroyAcceleratorTable( m_hAccel );
  550. m_hAccel = NULL;
  551. m_cAccel = 0;
  552. }
  553. // if there is a & character, then declare the accelerator
  554. iAccel = sz.Find(_T('&'));
  555. if ( iAccel >= 0 )
  556. {
  557. // fill in the accererator record
  558. accel.fVirt = FALT;
  559. accel.key = sz.GetAt(iAccel + 1);
  560. accel.cmd = (USHORT)GetDlgCtrlID();
  561. m_hAccel = CreateAcceleratorTable( &accel, 1 );
  562. if ( m_hAccel )
  563. m_cAccel = 1;
  564. fAnswer = TRUE;
  565. }
  566. // return the answer
  567. return fAnswer;
  568. }