Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Menu :o)

Menu :o)

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MemLeak
    wrote on last edited by
    #1

    Hi, I have a DlgApp that launch other applications. When the user click on a button, a popup menu is created with some data that I have collected in my database. The user then need to select an item into the menu. The selected info is used as parameters to launch the other app. This is my click button handler: void CmyDlg::OnBnClickedBtnDbmanager() { CMenu myMenu; CRect rect; m_wndDBBtn.GetWindowRect(&rect); monMenu.CreatePopupMenu(); monMenu.AppendMenu(MF_STRING, 0, "Name1"); monMenu.AppendMenu(MF_STRING, 0, "Name2"); monMenu.AppendMenu(MF_STRING, 0, "Name3"); monMenu.AppendMenu(MF_STRING, 0, "Name4"); myMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON, rect.left+20, rect.top+20, AfxGetMainWnd()); } I would like to know how I can get the index of the menu. For example, if I select name4 into the menu, I would like something to tell me that the fourth item is selected... After that, I can use GetMenuString() to retrieve my data and launch my other App. As you can see, unstead of ID as second parameter into AppendMenu() I have 0. The reason of this is that I dont know how many info I will have to put into my menu, so i can't provide ID for each of them. Any Ideas? Everything's beautiful if you look at it long enough...

    P M 2 Replies Last reply
    0
    • M MemLeak

      Hi, I have a DlgApp that launch other applications. When the user click on a button, a popup menu is created with some data that I have collected in my database. The user then need to select an item into the menu. The selected info is used as parameters to launch the other app. This is my click button handler: void CmyDlg::OnBnClickedBtnDbmanager() { CMenu myMenu; CRect rect; m_wndDBBtn.GetWindowRect(&rect); monMenu.CreatePopupMenu(); monMenu.AppendMenu(MF_STRING, 0, "Name1"); monMenu.AppendMenu(MF_STRING, 0, "Name2"); monMenu.AppendMenu(MF_STRING, 0, "Name3"); monMenu.AppendMenu(MF_STRING, 0, "Name4"); myMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON, rect.left+20, rect.top+20, AfxGetMainWnd()); } I would like to know how I can get the index of the menu. For example, if I select name4 into the menu, I would like something to tell me that the fourth item is selected... After that, I can use GetMenuString() to retrieve my data and launch my other App. As you can see, unstead of ID as second parameter into AppendMenu() I have 0. The reason of this is that I dont know how many info I will have to put into my menu, so i can't provide ID for each of them. Any Ideas? Everything's beautiful if you look at it long enough...

      P Offline
      P Offline
      peterchen
      wrote on last edited by
      #2

      a) Specify the index as second parameter in AppendMenu b) use TrackPopupmenuEx, and specify TPM_RETURNCMD in the flags. The return value will contain the value passed as second parameter to AppendMenu c) NEVER EVER use an User Interface String (such as the one displayed in the menu) directly for further processing. Don't do that. Never. it is not done.


      "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
      sighist | Agile Programming | doxygen

      1 Reply Last reply
      0
      • M MemLeak

        Hi, I have a DlgApp that launch other applications. When the user click on a button, a popup menu is created with some data that I have collected in my database. The user then need to select an item into the menu. The selected info is used as parameters to launch the other app. This is my click button handler: void CmyDlg::OnBnClickedBtnDbmanager() { CMenu myMenu; CRect rect; m_wndDBBtn.GetWindowRect(&rect); monMenu.CreatePopupMenu(); monMenu.AppendMenu(MF_STRING, 0, "Name1"); monMenu.AppendMenu(MF_STRING, 0, "Name2"); monMenu.AppendMenu(MF_STRING, 0, "Name3"); monMenu.AppendMenu(MF_STRING, 0, "Name4"); myMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON, rect.left+20, rect.top+20, AfxGetMainWnd()); } I would like to know how I can get the index of the menu. For example, if I select name4 into the menu, I would like something to tell me that the fourth item is selected... After that, I can use GetMenuString() to retrieve my data and launch my other App. As you can see, unstead of ID as second parameter into AppendMenu() I have 0. The reason of this is that I dont know how many info I will have to put into my menu, so i can't provide ID for each of them. Any Ideas? Everything's beautiful if you look at it long enough...

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        MemLeak wrote: I would like to know how I can get the index of the menu. Assign the menu items unique IDs starting with 1 and incrementing. Add the TPM_RETURNCMD flag to TrackPopupMenu() and it will return the ID of the item the user selected, or 0 if he cancelled the menu. --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups