Click here to Skip to main content
15,890,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Dynamic popup menu Pin
mark novak26-Jul-05 3:33
mark novak26-Jul-05 3:33 
GeneralRe: Dynamic popup menu Pin
toxcct26-Jul-05 3:43
toxcct26-Jul-05 3:43 
GeneralRe: Dynamic popup menu Pin
mark novak26-Jul-05 3:50
mark novak26-Jul-05 3:50 
GeneralRe: Dynamic popup menu Pin
toxcct26-Jul-05 3:59
toxcct26-Jul-05 3:59 
GeneralRe: Dynamic popup menu Pin
mark novak26-Jul-05 4:15
mark novak26-Jul-05 4:15 
GeneralRe: Dynamic popup menu Pin
toxcct26-Jul-05 5:11
toxcct26-Jul-05 5:11 
GeneralRe: Dynamic popup menu Pin
mark novak26-Jul-05 5:30
mark novak26-Jul-05 5:30 
GeneralRe: Dynamic popup menu Pin
toxcct26-Jul-05 20:35
toxcct26-Jul-05 20:35 
hello Mark,

i ended the taff on that menu... it works now.

however, i think there might be a better to do it, but as i could find out how, here is what i did :
FactEditor.h :
<font color=blue>class</font> CFactEditorDlg : <font color=blue>public</font> CDialog {
    <font color=green>//...</font>
 
<font color=blue>protected</font>:
    <font color=green>//I added these two members in the dialog class...</font>
    std::vector<CString> m_vPersonPhoneNumbers;
    <font color=blue>bool</font>                 m_bPhonesMenuCalled;
 
    <font color=green>//...</font>
};
 
 
FactEditor.cpp :
<font color=blue>void</font> CFactEditorDlg::OnSClickShowNumbers() {
    <font color=blue>using namespace</font> std;
    m_vPersonPhoneNumbers.clear();
    map<CString, TOperatorPersonPair>::const_iterator itmPersonNumbers;
 
    <font color=green>// Populates the Person's phone numbers list</font> 
    <font color=blue>for</font> (itmPersonNumbers = m_mapPhoneWithOpPersPair.begin();
         itmPersonNumbers != m_mapPhoneWithOpPersPair.end();
         itmPersonNumbers++) {
         <font color=blue>if</font> (itmPersonNumbers->second.m_strPerson == m_strCalledPerson) {
            m_vPersonPhoneNumbers.push_back(itmPersonNumbers->first);
        }
    }
    sort(m_vPersonPhoneNumbers.begin(), m_vPersonPhoneNumbers.end());
 
    <font color=green>// Displays the popup menu from the vector</font>
    <font color=blue>if</font> (m_vPersonPhoneNumbers.size() != 0) {
        CMenu PhonesMenu;
        <font color=blue>if</font> (PhonesMenu.CreatePopupMenu()) {
            vector<CString>::const_iterator itvPhoneNumbers;
            CString strRes, strMenuTitle;
            strRes.LoadString(IDS_FACTEDITORDLGTITLE);
            strMenuTitle.Format(strRes, m_strEditorVersion);
            PhonesMenu.AppendMenu(MF_STRING, 1, strMenuTitle);
            PhonesMenu.AppendMenu(MF_SEPARATOR);
            <font color=blue>int</font> iCpt = 3;
            <font color=blue>for</font> (itvPhoneNumbers = m_vPersonPhoneNumbers.begin();
                 itvPhoneNumbers != m_vPersonPhoneNumbers.end();
                 itvPhoneNumbers++, iCpt++) {
                PhonesMenu.AppendMenu(MF_STRING, iCpt, *itvPhoneNumbers);
            }
            CRect rect;
            m_pbShowNumbers->GetWindowRect(&rect);
            PhonesMenu.EnableMenuItem(1, MF_GRAYED);
            m_bPhonesMenuCalled = <font color=blue>true</font>;
            PhonesMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top-1, AfxGetMainWnd());
        }
    }
}
 
 
BOOL CFactEditorDlg::OnCommand(WPARAM wParam, LPARAM lParam) {
    <font color=blue>if</font> (HIWORD(wParam) == (UINT)0) {    <font color=green>// Called from a menu</font>
        <font color=blue>if</font> (m_bPhonesMenuCalled) {    <font color=green>// Called from Person Phone Numbers Popup Menu</font>
            m_peCalledNumber->SetWindowText(m_vPersonPhoneNumbers[LOWORD(wParam)-3]);
            m_bPhonesMenuCalled = <font color=blue>false</font>;
        }
    }
    <font color=blue>return</font> CDialog::OnCommand(wParam, lParam);
}

as you see, i use a boolean flag to test is the WM_COMMAND is sent by my popup or another menu because i couldn't find other way to test it.
i also wanted to put the menu as a member of the class, but here again, no way to turn the new incoming exceptions off... i think i had to do with DestroyMenu() and/or Attach()/Detach(), but where to put them, and how to use them ???


well, i'd like to thank you very much for you help, it was very good, and quite fast too !!
thanks


TOXCCT >>> GEII power
[toxcct][VisualCalc]
GeneralRe: Dynamic popup menu Pin
mark novak27-Jul-05 1:54
mark novak27-Jul-05 1:54 
GeneralRe: Dynamic popup menu Pin
toxcct27-Jul-05 2:00
toxcct27-Jul-05 2:00 
GeneralRe: Dynamic popup menu Pin
mark novak27-Jul-05 2:13
mark novak27-Jul-05 2:13 
GeneralString Converstions Pin
tomek1826-Jul-05 2:59
tomek1826-Jul-05 2:59 
GeneralRe: String Converstions Pin
mark novak26-Jul-05 3:02
mark novak26-Jul-05 3:02 
GeneralRe: String Converstions Pin
tomek1826-Jul-05 3:10
tomek1826-Jul-05 3:10 
GeneralRe: String Converstions Pin
mark novak26-Jul-05 3:24
mark novak26-Jul-05 3:24 
GeneralRe: String Converstions Pin
tomek1826-Jul-05 3:18
tomek1826-Jul-05 3:18 
GeneralRe: String Converstions Pin
tomek1826-Jul-05 3:43
tomek1826-Jul-05 3:43 
GeneralRe: String Converstions Pin
mark novak26-Jul-05 4:04
mark novak26-Jul-05 4:04 
GeneralRe: String Converstions Pin
tomek1826-Jul-05 4:17
tomek1826-Jul-05 4:17 
GeneralRe: String Converstions Pin
mark novak26-Jul-05 4:25
mark novak26-Jul-05 4:25 
GeneralRe: String Converstions Pin
Tim Smith26-Jul-05 3:30
Tim Smith26-Jul-05 3:30 
GeneralRe: String Converstions Pin
tomek1826-Jul-05 4:19
tomek1826-Jul-05 4:19 
GeneralRe: String Converstions Pin
mark novak26-Jul-05 4:28
mark novak26-Jul-05 4:28 
GeneralXML parsing in C++ Pin
72arpita26-Jul-05 2:53
72arpita26-Jul-05 2:53 
GeneralRe: XML parsing in C++ Pin
David Crow26-Jul-05 2:59
David Crow26-Jul-05 2:59 

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.