00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include <afxpriv.h>
00027 #include "CmdUI.h"
00028
00029
00030
00031 IMPLEMENT_DYNAMIC(CCmdUIDialog, CDialog)
00032
00033 CCmdUIDialog::CCmdUIDialog()
00034 {
00035 }
00036
00037 CCmdUIDialog::CCmdUIDialog(UINT nIDTemplate, CWnd* pParent )
00038 : CDialog(nIDTemplate, pParent)
00039 {
00040 }
00041
00042 CCmdUIDialog::CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
00043 : CDialog(lpszTemplateName, pParentWnd)
00044 {
00045 }
00046
00047 CCmdUIDialog::~CCmdUIDialog()
00048 {
00049 }
00050
00051 LRESULT CCmdUIDialog::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00052 {
00053 LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
00054
00055 if(message == WM_INITDIALOG)
00056 {
00057 SendMessage(WM_KICKIDLE);
00058 }
00059
00060 return(ret);
00061 }
00062
00063 BEGIN_MESSAGE_MAP(CCmdUIDialog, CDialog)
00064 ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
00065 ON_WM_INITMENUPOPUP()
00066 END_MESSAGE_MAP()
00067
00068
00069
00070
00071 void CCmdUIDialog::OnKickIdle()
00072 {
00073 UpdateDialogControls(this, false);
00074
00075
00076 }
00077
00078
00079
00080 void CCmdUIDialog::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
00081 {
00082 ASSERT(pPopupMenu != NULL);
00083
00084
00085 CCmdUI state;
00086 state.m_pMenu = pPopupMenu;
00087 ASSERT(state.m_pOther == NULL);
00088 ASSERT(state.m_pParentMenu == NULL);
00089
00090
00091
00092 HMENU hParentMenu;
00093 if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
00094 state.m_pParentMenu = pPopupMenu;
00095 else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
00096 {
00097 CWnd* pParent = this;
00098
00099 if (pParent != NULL &&
00100 (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
00101 {
00102 int nIndexMax = ::GetMenuItemCount(hParentMenu);
00103 for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
00104 {
00105 if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
00106 {
00107
00108 state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
00109 break;
00110 }
00111 }
00112 }
00113 }
00114
00115 state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
00116 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
00117 state.m_nIndex++)
00118 {
00119 state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
00120 if (state.m_nID == 0)
00121 continue;
00122
00123 ASSERT(state.m_pOther == NULL);
00124 ASSERT(state.m_pMenu != NULL);
00125 if (state.m_nID == (UINT)-1)
00126 {
00127
00128 state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
00129 if (state.m_pSubMenu == NULL ||
00130 (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
00131 state.m_nID == (UINT)-1)
00132 {
00133 continue;
00134 }
00135 state.DoUpdate(this, TRUE);
00136 }
00137 else
00138 {
00139
00140
00141
00142 state.m_pSubMenu = NULL;
00143 state.DoUpdate(this, FALSE);
00144 }
00145
00146
00147 UINT nCount = pPopupMenu->GetMenuItemCount();
00148 if (nCount < state.m_nIndexMax)
00149 {
00150 state.m_nIndex -= (state.m_nIndexMax - nCount);
00151 while (state.m_nIndex < nCount &&
00152 pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
00153 {
00154 state.m_nIndex++;
00155 }
00156 }
00157 state.m_nIndexMax = nCount;
00158 }
00159 }
00160
00161
00162
00163 IMPLEMENT_DYNAMIC(CCmdUIPropertyPage, CPropertyPage)
00164 CCmdUIPropertyPage::CCmdUIPropertyPage(UINT nIDTemplate, UINT nIDCaption)
00165 : CPropertyPage(nIDTemplate, nIDCaption)
00166 {
00167 }
00168
00169 CCmdUIPropertyPage::~CCmdUIPropertyPage()
00170 {
00171 }
00172
00173 LRESULT CCmdUIPropertyPage::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00174 {
00175 if(message == WM_COMMAND)
00176 {
00177 switch(HIWORD(wParam))
00178 {
00179 case BN_CLICKED: case CBN_SELCHANGE: case EN_CHANGE:
00180 SetModified();
00181 default:;
00182 }
00183 }
00184
00185 LRESULT ret = __super::DefWindowProc(message, wParam, lParam);
00186
00187 if(message == WM_INITDIALOG)
00188 {
00189 SendMessage(WM_KICKIDLE);
00190 }
00191
00192 return(ret);
00193 }
00194
00195 BEGIN_MESSAGE_MAP(CCmdUIPropertyPage, CPropertyPage)
00196 ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
00197 END_MESSAGE_MAP()
00198
00199
00200
00201
00202 void CCmdUIPropertyPage::OnKickIdle()
00203 {
00204 UpdateDialogControls(this, false);
00205
00206
00207 }
00208