occdlg.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include "occimpl.h"
  12. #ifdef AFX_OCC_SEG
  13. #pragma code_seg(AFX_OCC_SEG)
  14. #endif
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #define new DEBUG_NEW
  20. /////////////////////////////////////////////////////////////////////////////
  21. #define CH_SYSMENU ' '
  22. #define WS_TYPEMASK 0xC0000000
  23. #define BS_TYPEMASK 0x0000000F
  24. static inline DWORD TestStyle(CWnd* pWnd, DWORD dwStyle)
  25. { return GetWindowLong(pWnd->m_hWnd, GWL_STYLE) & dwStyle; }
  26. static inline DWORD TestExStyle(CWnd* pWnd, DWORD dwExStyle)
  27. { return GetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE) & dwExStyle; }
  28. static inline BOOL HasChildStyle(CWnd* pWnd)
  29. { return TestStyle(pWnd, WS_TYPEMASK) == WS_CHILD; }
  30. static inline BOOL IsControlParent(CWnd* pWnd)
  31. { return TestExStyle(pWnd, WS_EX_CONTROLPARENT); }
  32. AFX_STATIC DWORD AFXAPI _AfxGetDlgCode(CWnd* pWnd, LPMSG lpMsg=NULL)
  33. {
  34. if (pWnd == NULL)
  35. return 0;
  36. WPARAM wParam = (lpMsg == NULL) ? 0 : lpMsg->wParam;
  37. return (DWORD)SendMessage(pWnd->m_hWnd, WM_GETDLGCODE,
  38. wParam, (LPARAM)(LPMSG)lpMsg);
  39. }
  40. AFX_STATIC void AFXAPI _AfxDlgSetFocus(CWnd* pWnd)
  41. {
  42. // Select all text in an edit control.
  43. if (_AfxGetDlgCode(pWnd) & DLGC_HASSETSEL)
  44. pWnd->SendMessage(EM_SETSEL, 0, -1);
  45. // Set focus as normal.
  46. pWnd->SetFocus();
  47. }
  48. AFX_STATIC CWnd* AFXAPI _AfxGetChildControl(CWnd* pWndRoot, CWnd* pWndChild)
  49. {
  50. CWnd* pWndControl = NULL;
  51. while ((pWndChild != NULL) && HasChildStyle(pWndChild) &&
  52. (pWndChild != pWndRoot))
  53. {
  54. pWndControl = pWndChild;
  55. pWndChild = pWndChild->GetParent();
  56. if (IsControlParent(pWndChild))
  57. break;
  58. }
  59. return pWndControl;
  60. }
  61. AFX_STATIC CWnd* AFXAPI _AfxNextControl(CWnd* pWndRoot, CWnd* pWndStart, UINT uFlags)
  62. {
  63. // if pWndStart is already equal to pWndRoot, this confuses this function
  64. // badly.
  65. ASSERT(pWndRoot != pWndStart);
  66. if (pWndStart == NULL)
  67. {
  68. FirstChild:
  69. pWndStart = pWndRoot->GetTopWindow();
  70. if (pWndStart == NULL)
  71. return pWndRoot;
  72. goto Found;
  73. }
  74. else
  75. {
  76. // Are we at the last control within some parent? If so, pop back up.
  77. while (pWndStart->GetNextWindow() == NULL)
  78. {
  79. // Popup to previous real ancestor. pWndStart will be NULL,
  80. // pWndRoot, or the child of a recursive dialog.
  81. pWndStart = _AfxGetChildControl(pWndRoot, pWndStart->GetParent());
  82. if ((pWndStart == NULL) || (pWndStart == pWndRoot))
  83. {
  84. goto FirstChild;
  85. }
  86. }
  87. ASSERT(pWndStart != NULL);
  88. pWndStart = pWndStart->GetNextWindow();
  89. }
  90. Found:
  91. if (IsControlParent(pWndStart))
  92. {
  93. if (((uFlags & CWP_SKIPINVISIBLE) && !pWndStart->IsWindowVisible()) ||
  94. ((uFlags & CWP_SKIPDISABLED) && !pWndStart->IsWindowEnabled()))
  95. pWndStart = _AfxNextControl(pWndRoot, pWndStart, uFlags);
  96. else
  97. pWndStart = _AfxNextControl(pWndStart, NULL, uFlags);
  98. }
  99. return pWndStart;
  100. }
  101. BOOL AFX_CDECL COccManager::IsMatchingMnemonic(CWnd* pWnd, LPMSG lpMsg)
  102. {
  103. return (pWnd->m_pCtrlSite != NULL) &&
  104. pWnd->m_pCtrlSite->IsMatchingMnemonic(lpMsg);
  105. }
  106. AFX_STATIC CWnd* AFXAPI _AfxFindNextMnem(CWnd* pWndDlg, CWnd* pWnd, LPMSG lpMsg)
  107. {
  108. CWnd* pWndStart;
  109. CWnd* pWndT;
  110. int i = 0;
  111. // Check if we are in a group box so we can find local mnemonics.
  112. pWndStart = _AfxGetChildControl(pWndDlg, pWnd);
  113. while ((pWndT = pWndDlg->GetNextDlgGroupItem(pWndStart)) != NULL)
  114. {
  115. i++;
  116. // Avoid infinite looping.
  117. if (pWndT == pWnd || i > 60)
  118. break;
  119. pWndStart = pWndT;
  120. if (COccManager::IsMatchingMnemonic(pWndT, lpMsg))
  121. return pWndT;
  122. }
  123. pWnd = pWndStart = _AfxGetChildControl(pWndDlg, pWnd);
  124. while (TRUE)
  125. {
  126. pWnd = _AfxNextControl(pWndDlg, pWnd, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
  127. if (COccManager::IsMatchingMnemonic(pWnd, lpMsg))
  128. break;
  129. if (pWnd == pWndStart)
  130. return NULL;
  131. }
  132. return pWnd;
  133. }
  134. BOOL AFX_CDECL COccManager::IsLabelControl(CWnd* pWnd)
  135. {
  136. return pWnd->IsWindowEnabled() && (pWnd->m_pCtrlSite != NULL) &&
  137. pWnd->m_pCtrlSite->m_dwMiscStatus & OLEMISC_ACTSLIKELABEL;
  138. }
  139. AFX_STATIC CWnd* AFXAPI _AfxGetNextMnem(CWnd* pWndDlg, CWnd* pWnd, LPMSG lpMsg)
  140. {
  141. CWnd* pWndFirstFound = NULL;
  142. // Loop for a long time but not long enough so we hang...
  143. for (int count = 0; count < 256*2; count++)
  144. {
  145. // If the dialog box doesn't has the mnemonic specified, return NULL.
  146. if ((pWnd = _AfxFindNextMnem(pWndDlg, pWnd, lpMsg)) == NULL)
  147. return NULL;
  148. // If a non-disabled static item, then jump ahead to nearest tabstop.
  149. if (COccManager::IsLabelControl(pWnd))
  150. {
  151. pWnd = pWndDlg->GetNextDlgTabItem(pWnd);
  152. if (pWnd == NULL)
  153. return NULL;
  154. }
  155. if (pWnd->IsWindowEnabled())
  156. return pWnd;
  157. // Stop if we've looped back to the first item we checked
  158. if (pWnd == pWndFirstFound)
  159. return NULL;
  160. if (pWndFirstFound == NULL)
  161. pWndFirstFound = pWnd;
  162. }
  163. return NULL;
  164. }
  165. void AFX_CDECL COccManager::UIActivateControl(CWnd* pWndNewFocus)
  166. {
  167. if (pWndNewFocus == NULL)
  168. return;
  169. // Find the nearest control in the window parent chain.
  170. CWnd* pWndCtrl = pWndNewFocus;
  171. COleControlContainer* pCtrlCont = NULL;
  172. COleControlSite* pCtrlSite = NULL;
  173. while ((pWndCtrl != NULL) &&
  174. ((pCtrlCont = pWndCtrl->m_pCtrlCont) == NULL) &&
  175. ((pCtrlSite = pWndCtrl->m_pCtrlSite) == NULL))
  176. {
  177. pWndCtrl = pWndCtrl->GetParent();
  178. }
  179. if ((pWndCtrl == NULL) || (pCtrlCont != NULL))
  180. return;
  181. // This will UI Activate the control.
  182. pCtrlSite->SetFocus();
  183. // Make sure focus gets set to correct child of control, if any.
  184. if (CWnd::GetFocus() != pWndNewFocus)
  185. pWndNewFocus->SetFocus();
  186. }
  187. void AFX_CDECL COccManager::UIDeactivateIfNecessary(CWnd* pWndOldFocus,
  188. CWnd* pWndNewFocus)
  189. {
  190. if (pWndOldFocus == NULL || !::IsWindow(pWndOldFocus->m_hWnd))
  191. return;
  192. // Find the nearest control container in the window parent chain.
  193. CWnd* pWndCtrlCont = pWndOldFocus->GetParent();
  194. COleControlContainer* pCtrlCont = NULL;
  195. while ((pWndCtrlCont != NULL) &&
  196. ((pCtrlCont = pWndCtrlCont->m_pCtrlCont) == NULL))
  197. {
  198. pWndCtrlCont = pWndCtrlCont->GetParent();
  199. }
  200. if (pCtrlCont == NULL)
  201. return;
  202. // Get the current UI Active control (if any).
  203. CWnd* pWndUIActive = NULL;
  204. COleControlSite* pSite = NULL;
  205. if ((pCtrlCont != NULL) &&
  206. ((pSite = pCtrlCont->m_pSiteUIActive) != NULL))
  207. {
  208. pWndUIActive = CWnd::FromHandle(pSite->m_hWnd);
  209. }
  210. // Ignore if no control is UI Active.
  211. if (pWndUIActive == NULL)
  212. return;
  213. // Ignore if the control getting the focus is the same control.
  214. if ((pWndNewFocus == pWndUIActive) ||
  215. ((pWndNewFocus != NULL) && pWndUIActive->IsChild(pWndNewFocus)))
  216. return;
  217. // Tell the container to UI Deactivate the UI Active control.
  218. pCtrlCont->OnUIActivate(NULL);
  219. }
  220. CWnd* AFXAPI _AfxFindDlgItem(CWnd* pWndParent, DWORD id)
  221. {
  222. CWnd* pWndChild;
  223. CWnd* pWndOrig;
  224. // QUICK TRY:
  225. pWndChild = pWndParent->GetDlgItem(id);
  226. if (pWndChild != NULL)
  227. return pWndChild;
  228. pWndOrig = _AfxNextControl(pWndParent, NULL, CWP_SKIPINVISIBLE);
  229. if (pWndOrig == pWndParent)
  230. return NULL;
  231. pWndChild = pWndOrig;
  232. do
  233. {
  234. if ((DWORD)pWndChild->GetDlgCtrlID() == id)
  235. return(pWndChild);
  236. pWndChild = _AfxNextControl(pWndParent, pWndChild, CWP_SKIPINVISIBLE);
  237. }
  238. while ((pWndChild != NULL) && (pWndChild != pWndOrig));
  239. return NULL;
  240. }
  241. void COccManager::SetDefaultButton(CWnd* pWnd, BOOL bDefault)
  242. {
  243. if (pWnd->m_pCtrlSite != NULL)
  244. {
  245. pWnd->m_pCtrlSite->SetDefaultButton(bDefault);
  246. }
  247. else
  248. {
  249. DWORD code = _AfxGetDlgCode(pWnd);
  250. if (code & (bDefault ? DLGC_UNDEFPUSHBUTTON : DLGC_DEFPUSHBUTTON))
  251. pWnd->SendMessage(BM_SETSTYLE,
  252. (WPARAM)(bDefault ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON),
  253. (LPARAM)(DWORD)TRUE);
  254. }
  255. }
  256. DWORD AFX_CDECL COccManager::GetDefBtnCode(CWnd* pWnd)
  257. {
  258. if (pWnd == NULL)
  259. return 0;
  260. if (pWnd->m_pCtrlSite != NULL)
  261. return pWnd->m_pCtrlSite->GetDefBtnCode();
  262. return _AfxGetDlgCode(pWnd) & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON);
  263. }
  264. AFX_STATIC void AFXAPI _AfxRemoveDefaultButton(CWnd* pWndRoot, CWnd* pWndStart)
  265. {
  266. if ((pWndStart == NULL) || IsControlParent(pWndStart))
  267. pWndStart = _AfxNextControl(pWndRoot, NULL, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
  268. else
  269. pWndStart = _AfxGetChildControl(pWndRoot, pWndStart);
  270. if (pWndStart == NULL)
  271. return;
  272. CWnd* pWnd = pWndStart;
  273. CWnd* pWndNext;
  274. do
  275. {
  276. COccManager::SetDefaultButton(pWnd, FALSE);
  277. pWndNext = _AfxNextControl(pWndRoot, pWnd, 0);
  278. pWnd = pWndNext;
  279. }
  280. while ((pWnd != NULL) && (pWnd != pWndStart));
  281. }
  282. AFX_STATIC int AFXAPI _AfxOriginalDefButton(CWnd* pWndRoot)
  283. {
  284. LRESULT lResult = pWndRoot->SendMessage(DM_GETDEFID, 0, 0L);
  285. return HIWORD(lResult) == DC_HASDEFID ? LOWORD(lResult) : IDOK;
  286. }
  287. AFX_STATIC void AFXAPI _AfxCheckDefPushButton(CWnd* pWndRoot, CWnd* pWndOldFocus,
  288. CWnd* pWndNewFocus)
  289. {
  290. DWORD code = 0;
  291. CWnd* pWndT;
  292. // If the focus has gone to a totally separate window, bail out.
  293. if (!pWndRoot->IsChild(pWndNewFocus))
  294. return;
  295. if (pWndNewFocus != NULL)
  296. {
  297. // Do nothing if clicking on dialog background or recursive dialog
  298. // background.
  299. if (IsControlParent(pWndNewFocus))
  300. return;
  301. code = COccManager::GetDefBtnCode(pWndNewFocus);
  302. }
  303. if (pWndOldFocus == pWndNewFocus)
  304. {
  305. // Check the default ID and see if is the same as pwndOldFocus' ID.
  306. // If not, find it and use it as pwndOldFocus
  307. if (code & DLGC_UNDEFPUSHBUTTON)
  308. {
  309. if (pWndOldFocus != NULL)
  310. {
  311. pWndOldFocus = _AfxFindDlgItem(pWndRoot, _AfxOriginalDefButton(pWndRoot));
  312. if ((pWndOldFocus != NULL) && (pWndOldFocus != pWndNewFocus))
  313. {
  314. if (COccManager::GetDefBtnCode(pWndOldFocus) & DLGC_DEFPUSHBUTTON)
  315. {
  316. _AfxRemoveDefaultButton(pWndRoot, pWndOldFocus);
  317. goto SetNewDefault;
  318. }
  319. }
  320. }
  321. COccManager::SetDefaultButton(pWndNewFocus, TRUE);
  322. }
  323. return;
  324. }
  325. // If the focus is changing to or from a pushbutton, then remove the
  326. // default style from the current default button
  327. if (((pWndOldFocus != NULL) && (COccManager::GetDefBtnCode(pWndOldFocus) != 0)) ||
  328. ((pWndNewFocus != NULL) && (code != 0)))
  329. {
  330. _AfxRemoveDefaultButton(pWndRoot, pWndNewFocus);
  331. }
  332. SetNewDefault:
  333. // If moving to a button, make that button the default.
  334. if (code & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON))
  335. {
  336. COccManager::SetDefaultButton(pWndNewFocus, TRUE);
  337. }
  338. else
  339. {
  340. // Otherwise, make sure the original default button is default
  341. // Get the original default button
  342. pWndT = _AfxFindDlgItem(pWndRoot, _AfxOriginalDefButton(pWndRoot));
  343. if ((COccManager::GetDefBtnCode(pWndT) & DLGC_UNDEFPUSHBUTTON) &&
  344. pWndT->IsWindowEnabled())
  345. {
  346. COccManager::SetDefaultButton(pWndT, TRUE);
  347. }
  348. }
  349. }
  350. BOOL COccManager::IsDialogMessage(CWnd* pWndDlg, LPMSG lpMsg)
  351. {
  352. // If an OLE Control has the focus, then give it the first crack at key
  353. // and mouse messages.
  354. CWnd* pWndFocus = CWnd::GetFocus();
  355. HWND hWndFocus = pWndFocus->GetSafeHwnd();
  356. HWND hWndDlg = pWndDlg->GetSafeHwnd();
  357. UINT uMsg = lpMsg->message;
  358. if (((uMsg >= WM_KEYFIRST) && (uMsg <= WM_KEYLAST)) ||
  359. ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST)))
  360. {
  361. CWnd* pWndCtrl = pWndFocus;
  362. // Walk up the parent chain, until we find an OLE control.
  363. while ((pWndCtrl != NULL) && (pWndCtrl->m_pCtrlSite == NULL) &&
  364. (pWndCtrl->GetParent() != pWndDlg))
  365. {
  366. pWndCtrl = pWndCtrl->GetParent();
  367. }
  368. // let the control attempt to translate the message
  369. if (pWndCtrl != NULL && pWndCtrl->m_pCtrlSite != NULL &&
  370. pWndCtrl->m_pCtrlSite->m_pActiveObject != NULL &&
  371. pWndCtrl->m_pCtrlSite->m_pActiveObject->TranslateAccelerator(lpMsg) == S_OK)
  372. {
  373. return TRUE;
  374. }
  375. // handle CTRLINFO_EATS_RETURN and CTRLINFO_EATS_ESCAPE flags
  376. if ((uMsg == WM_KEYUP || uMsg == WM_KEYDOWN || uMsg == WM_CHAR) &&
  377. pWndCtrl != NULL && pWndCtrl->m_pCtrlSite != NULL &&
  378. ((LOWORD(lpMsg->wParam) == VK_RETURN &&
  379. (pWndCtrl->m_pCtrlSite->m_ctlInfo.dwFlags & CTRLINFO_EATS_RETURN)) ||
  380. (LOWORD(lpMsg->wParam) == VK_ESCAPE &&
  381. (pWndCtrl->m_pCtrlSite->m_ctlInfo.dwFlags & CTRLINFO_EATS_ESCAPE))))
  382. {
  383. return FALSE;
  384. }
  385. }
  386. BOOL bResult = FALSE;
  387. CWnd* pWndMsg = CWnd::FromHandle(lpMsg->hwnd);
  388. CWnd* pWndNext = NULL;
  389. DWORD code;
  390. BOOL bBack = FALSE;
  391. int iOK = IDCANCEL;
  392. switch (uMsg)
  393. {
  394. case WM_SYSCHAR:
  395. // If no control has focus, and Alt not down, then ignore.
  396. if ((pWndFocus == NULL) && (GetKeyState(VK_MENU) >= 0))
  397. break;
  398. // If alt+menuchar, process as menu.
  399. if (LOWORD(lpMsg->wParam) == CH_SYSMENU)
  400. break;
  401. // FALL THRU
  402. case WM_CHAR:
  403. // Ignore chars sent to the dialog box (rather than the control).
  404. if (pWndMsg == pWndDlg)
  405. return TRUE;
  406. code = _AfxGetDlgCode(pWndMsg, lpMsg);
  407. // If the control wants to process the message, then don't check
  408. // for possible mnemonic key.
  409. if (uMsg == WM_CHAR && (code & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)))
  410. break;
  411. // If the control wants tabs, then don't let tab fall thru here
  412. if (LOWORD(lpMsg->wParam) == VK_TAB && (code & DLGC_WANTTAB))
  413. break;
  414. // Don't handle space as a mnemonic
  415. if (LOWORD(lpMsg->wParam) == VK_SPACE)
  416. return TRUE;
  417. if ((pWndNext = _AfxGetNextMnem(pWndDlg, pWndMsg, lpMsg)) != NULL)
  418. {
  419. if (pWndNext->m_pCtrlSite != NULL)
  420. {
  421. // UI Activate new control, and send the mnemonic to it.
  422. pWndNext->m_pCtrlSite->SendMnemonic(lpMsg);
  423. bResult = TRUE;
  424. }
  425. }
  426. break;
  427. case WM_KEYDOWN:
  428. code = _AfxGetDlgCode(pWndMsg, lpMsg);
  429. switch (LOWORD(lpMsg->wParam))
  430. {
  431. case VK_TAB:
  432. if (code & DLGC_WANTTAB) // If control wants tabs, bail out.
  433. break;
  434. pWndNext = pWndDlg->GetNextDlgTabItem(pWndMsg,
  435. (GetKeyState(VK_SHIFT) < 0));
  436. if (pWndNext != NULL)
  437. {
  438. _AfxDlgSetFocus(pWndNext);
  439. UIDeactivateIfNecessary(pWndFocus, pWndNext);
  440. }
  441. bResult = TRUE;
  442. break;
  443. case VK_LEFT:
  444. case VK_UP:
  445. bBack = TRUE;
  446. // FALL THRU
  447. case VK_RIGHT:
  448. case VK_DOWN:
  449. if (_AfxGetDlgCode(pWndFocus, lpMsg) & DLGC_WANTARROWS)
  450. break;
  451. pWndNext = pWndDlg->GetNextDlgGroupItem(pWndFocus, bBack);
  452. if ((pWndNext != NULL) && (pWndNext->m_pCtrlSite != NULL))
  453. {
  454. _AfxDlgSetFocus(pWndNext);
  455. bResult = TRUE;
  456. }
  457. break;
  458. case VK_EXECUTE:
  459. case VK_RETURN:
  460. // Return was pressed. Find default button and click it.
  461. if (GetDefBtnCode(pWndFocus) & DLGC_DEFPUSHBUTTON)
  462. {
  463. pWndNext = pWndFocus;
  464. iOK = (DWORD)pWndNext->GetDlgCtrlID();
  465. }
  466. else
  467. {
  468. iOK = _AfxOriginalDefButton(pWndDlg);
  469. }
  470. // FALL THRU
  471. case VK_ESCAPE:
  472. case VK_CANCEL:
  473. if (pWndNext == NULL)
  474. {
  475. pWndNext = _AfxFindDlgItem(pWndDlg, iOK);
  476. if (pWndNext == NULL)
  477. break;
  478. }
  479. ASSERT(pWndNext != NULL);
  480. // Make sure button is not disabled.
  481. if (!pWndNext->IsWindowEnabled())
  482. {
  483. MessageBeep(0);
  484. }
  485. else if (pWndNext->m_pCtrlSite != NULL)
  486. {
  487. // "push" the pWndNext control.
  488. TRY
  489. {
  490. pWndNext->InvokeHelper(DISPID_DOCLICK, DISPATCH_METHOD,
  491. VT_EMPTY, NULL, VTS_NONE);
  492. }
  493. END_TRY
  494. bResult = TRUE;
  495. }
  496. break;
  497. }
  498. break;
  499. }
  500. // As a last resort, delegate to the Windows implementation
  501. if (!bResult)
  502. {
  503. bResult = ::IsDialogMessage(pWndDlg->m_hWnd, lpMsg);
  504. if (bResult && (CWnd::GetFocus() != pWndFocus))
  505. UIActivateControl(CWnd::GetFocus());
  506. }
  507. if (::IsWindow(hWndFocus))
  508. {
  509. UIDeactivateIfNecessary(pWndFocus, CWnd::GetFocus());
  510. if (::IsWindow(hWndDlg))
  511. _AfxCheckDefPushButton(pWndDlg, pWndFocus, CWnd::GetFocus());
  512. }
  513. return bResult;
  514. }
  515. /////////////////////////////////////////////////////////////////////////////