Click here to Skip to main content
16,015,594 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralGetting notifications from a menu inside a CommandBar Pin
Tommy2k28-Apr-03 12:39
Tommy2k28-Apr-03 12:39 
QuestionADO events biased to COM memory model? Pin
Chopper28-Apr-03 9:32
Chopper28-Apr-03 9:32 
Questionhow to use IE/Explorer tool band? Pin
benben28-Apr-03 2:42
benben28-Apr-03 2:42 
GeneralReturn a recordset of ADO. Pin
TianYang27-Apr-03 23:44
TianYang27-Apr-03 23:44 
GeneralRe: Return a recordset of ADO. Pin
Brian Shifrin28-Apr-03 14:06
Brian Shifrin28-Apr-03 14:06 
GeneralSet property by "=" Pin
TianYang27-Apr-03 23:36
TianYang27-Apr-03 23:36 
GeneralRe: Set property by "=" Pin
Michael Dunn1-May-03 0:32
sitebuilderMichael Dunn1-May-03 0:32 
GeneralCODE: Adding radio-checked menu item support to CUpdateUI Pin
Michael Dunn27-Apr-03 16:47
sitebuilderMichael Dunn27-Apr-03 16:47 
Sorry for posting code here, but someone asked me about a week ago for some code, but I can't find the request now (the CP comment search doesn't search for a whole phrase, so I can't narrow down the results enough to find the one I want).
Anyhoo, to add support for radio-checked menu items only takes a few lines, however if you don't want to modify atlframe.h, you need to make a CUpdateUI2 class and copy over 3 functions from CUpdateUI. Here's the entire class, my changes are marked with //*** BEGIN and //*** END
template <class T>
class CUpdateUI2 : public CUpdateUI<T>
{
public:
    BEGIN_MSG_MAP(CUpdateUI2<T> )
        MESSAGE_HANDLER(WM_INITMENUPOPUP, OnInitMenuPopup)
        if ( WM_INITMENUPOPUP != uMsg )
            { CHAIN_MSG_MAP(CUpdateUI<T> ) }
    END_MSG_MAP()
           
    LRESULT OnInitMenuPopup(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
    {
        bHandled = FALSE;
        HMENU hMenu = (HMENU)wParam;
        if(hMenu == NULL)
            return 1;
        _AtlUpdateUIData* pUIData = m_pUIData;
        if(pUIData == NULL)
            return 1;
        ::SetMenuDefaultItem(hMenu, (UINT)-1, 0);
        const _AtlUpdateUIMap* pMap = m_pUIMap;
        while(pMap->m_nID != (WORD)-1)
        {
            if(pMap->m_wType & UPDUI_MENUPOPUP)
                UIUpdateMenuBarElement(pMap->m_nID, pUIData, hMenu);
            pMap++;
            pUIData++;
        }
        return 0;
    }

// methods for updating UI
    BOOL UIUpdateMenuBar(BOOL bForceUpdate = FALSE, BOOL bMainMenu = FALSE)
    {
        if(!(m_wDirtyType & UPDUI_MENUBAR) && !bForceUpdate)
            return TRUE;
                          
        const _AtlUpdateUIMap* pMap = m_pUIMap;
        _AtlUpdateUIData* pUIData = m_pUIData;
        if(pUIData == NULL)
            return FALSE;
                        
        while(pMap->m_nID != (WORD)-1)
        {
            for(int i = 0; i < m_UIElements.GetSize(); i++)
            {
                if(m_UIElements[i].m_wType == UPDUI_MENUBAR)
                {
                    HMENU hMenu = ::GetMenu(m_UIElements[i].m_hWnd);
                    if(hMenu != NULL && (pUIData->m_wState & UPDUI_MENUBAR) && (pMap->m_wType & UPDUI_MENUBAR))
                        UIUpdateMenuBarElement(pMap->m_nID, pUIData, hMenu);
                }
                if(bMainMenu)
                    ::DrawMenuBar(m_UIElements[i].m_hWnd);
            }
            pMap++;
            pUIData->m_wState &= ~UPDUI_MENUBAR;
            if(pUIData->m_wState & UPDUI_TEXT)
            {
                free(pUIData->m_lpData);
                pUIData->m_lpData = NULL;
                pUIData->m_wState &= ~UPDUI_TEXT;
            }
            pUIData++;
        }
          
        m_wDirtyType &= ~UPDUI_MENUBAR;
        return TRUE;
    }
           
// internal element specific methods
    static void UIUpdateMenuBarElement(int nID, _AtlUpdateUIData* pUIData, HMENU hMenu)
    {
        MENUITEMINFO mii;
        memset(&mii, 0, sizeof(MENUITEMINFO));
        mii.cbSize = sizeof(MENUITEMINFO);
        mii.fMask = MIIM_STATE;
        mii.wID = nID;
        
        if(pUIData->m_wState & UPDUI_DISABLED)
            mii.fState |= MFS_DISABLED | MFS_GRAYED;
        else
            mii.fState |= MFS_ENABLED;
         
        if(pUIData->m_wState & UPDUI_CHECKED)
            mii.fState |= MFS_CHECKED;
        else
            mii.fState |= MFS_UNCHECKED;
         
        if(pUIData->m_wState & UPDUI_DEFAULT)
            mii.fState |= MFS_DEFAULT;
          
        //*** BEGIN support for radio-checked menu items
        if(pUIData->m_wState & UPDUI_RADIO)
            {
            mii.fMask |= MIIM_FTYPE;
            mii.fState |= MFS_CHECKED;
            mii.fType |= MFT_RADIOCHECK;
            }
        else
            mii.fMask |= MIIM_FTYPE;    // turns off MFT_RADIOCHECK type
        //*** END
          
        if(pUIData->m_wState & UPDUI_TEXT)
        {
            MENUITEMINFO miiNow;
            memset(&miiNow, 0, sizeof(MENUITEMINFO));
            miiNow.cbSize = sizeof(MENUITEMINFO);
            miiNow.fMask = MIIM_TYPE;
            miiNow.wID = nID;
            if(::GetMenuItemInfo(hMenu, nID, FALSE, &miiNow))
            {
                mii.fMask |= MIIM_TYPE;
                // MFT_BITMAP and MFT_SEPARATOR don't go together with MFT_STRING
                mii.fType |= (miiNow.fType & ~(MFT_BITMAP | MFT_SEPARATOR)) | MFT_STRING;
                mii.dwTypeData = (LPTSTR)pUIData->m_lpData;
            }
        }
       
        ::SetMenuItemInfo(hMenu, nID, FALSE, &mii);
    }
};


--Mike--
Yeah, payin' the bills with my mad programming skillz.
Defraggin' my hard drive for thrills.

Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me

GeneralHttp connection via Proxy Pin
Sam197925-Apr-03 21:37
Sam197925-Apr-03 21:37 
GeneralRe: Http connection via Proxy Pin
geo_m26-Apr-03 22:00
geo_m26-Apr-03 22:00 
GeneralRe: Http connection via Proxy Pin
Sam197930-Apr-03 0:56
Sam197930-Apr-03 0:56 
GeneralRe: Http connection via Proxy Pin
geo_m30-Apr-03 3:18
geo_m30-Apr-03 3:18 
QuestionHow to do this in WTL Pin
User 1605525-Apr-03 3:41
User 1605525-Apr-03 3:41 
AnswerRe: How to do this in WTL Pin
Michael Dunn25-Apr-03 16:52
sitebuilderMichael Dunn25-Apr-03 16:52 
GeneralLike a Toolbar. Pin
Leandro H. Delamare23-Apr-03 6:01
Leandro H. Delamare23-Apr-03 6:01 
GeneralSTL weirdness Pin
#realJSOP21-Apr-03 4:20
professional#realJSOP21-Apr-03 4:20 
GeneralRe: STL weirdness Pin
Joaquín M López Muñoz21-Apr-03 4:53
Joaquín M López Muñoz21-Apr-03 4:53 
GeneralRe: STL weirdness Pin
#realJSOP21-Apr-03 8:08
professional#realJSOP21-Apr-03 8:08 
GeneralRe: STL weirdness Pin
Tim Smith21-Apr-03 8:57
Tim Smith21-Apr-03 8:57 
GeneralRe: STL weirdness Pin
Paul M Watt2-May-03 20:19
mentorPaul M Watt2-May-03 20:19 
GeneralAnother problem with maps Pin
The Unknown20-Apr-03 8:12
The Unknown20-Apr-03 8:12 
GeneralRe: Another problem with maps Pin
Tim Smith20-Apr-03 8:21
Tim Smith20-Apr-03 8:21 
GeneralRe: Another problem with maps Pin
The Unknown20-Apr-03 8:41
The Unknown20-Apr-03 8:41 
GeneralRe: Another problem with maps Pin
Joaquín M López Muñoz20-Apr-03 20:09
Joaquín M López Muñoz20-Apr-03 20:09 
GeneralRe: Another problem with maps Pin
The Unknown21-Apr-03 3:27
The Unknown21-Apr-03 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.