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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Execution problem with TrackPopupMenu, help !!!

Execution problem with TrackPopupMenu, help !!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphics
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.
  • F Offline
    F Offline
    flybird
    wrote on last edited by
    #1

    here is my code: In AppView.cpp : ---------------- void CTestApplicationView::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu Menu; // Store popup point, and convert to client coordinates // for the drawing functions. Menu.LoadMenu( IDR_CONTEXTMENU ); CMenu* pPopup = Menu.GetSubMenu( 0 ); pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this ); } when i right click mouse i got an execution error on TrackPopupMenu: -------------- BOOL CMenu::TrackPopupMenu(UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect) { ASSERT(m_hMenu != NULL); <---------- PROBLEM HERE _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); HWND hWndOld = pThreadState->m_hTrackingWindow; HMENU hMenuOld = pThreadState->m_hTrackingMenu; pThreadState->m_hTrackingWindow = pWnd->GetSafeHwnd(); pThreadState->m_hTrackingMenu = m_hMenu; BOOL bOK = ::TrackPopupMenu(m_hMenu, nFlags, x, y, 0, pThreadState->m_hTrackingWindow, lpRect); pThreadState->m_hTrackingWindow = hWndOld; pThreadState->m_hTrackingMenu = hMenuOld; return bOK; } Any ideas, cause I really don't understand why ...:((

    D H 2 Replies Last reply
    0
    • F flybird

      here is my code: In AppView.cpp : ---------------- void CTestApplicationView::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu Menu; // Store popup point, and convert to client coordinates // for the drawing functions. Menu.LoadMenu( IDR_CONTEXTMENU ); CMenu* pPopup = Menu.GetSubMenu( 0 ); pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this ); } when i right click mouse i got an execution error on TrackPopupMenu: -------------- BOOL CMenu::TrackPopupMenu(UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect) { ASSERT(m_hMenu != NULL); <---------- PROBLEM HERE _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); HWND hWndOld = pThreadState->m_hTrackingWindow; HMENU hMenuOld = pThreadState->m_hTrackingMenu; pThreadState->m_hTrackingWindow = pWnd->GetSafeHwnd(); pThreadState->m_hTrackingMenu = m_hMenu; BOOL bOK = ::TrackPopupMenu(m_hMenu, nFlags, x, y, 0, pThreadState->m_hTrackingWindow, lpRect); pThreadState->m_hTrackingWindow = hWndOld; pThreadState->m_hTrackingMenu = hMenuOld; return bOK; } Any ideas, cause I really don't understand why ...:((

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      flybird wrote: Menu.LoadMenu( IDR_CONTEXTMENU ); CMenu* pPopup = Menu.GetSubMenu( 0 ); Why are you not checking the return value of either of these functions?

      1 Reply Last reply
      0
      • F flybird

        here is my code: In AppView.cpp : ---------------- void CTestApplicationView::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu Menu; // Store popup point, and convert to client coordinates // for the drawing functions. Menu.LoadMenu( IDR_CONTEXTMENU ); CMenu* pPopup = Menu.GetSubMenu( 0 ); pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this ); } when i right click mouse i got an execution error on TrackPopupMenu: -------------- BOOL CMenu::TrackPopupMenu(UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect) { ASSERT(m_hMenu != NULL); <---------- PROBLEM HERE _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); HWND hWndOld = pThreadState->m_hTrackingWindow; HMENU hMenuOld = pThreadState->m_hTrackingMenu; pThreadState->m_hTrackingWindow = pWnd->GetSafeHwnd(); pThreadState->m_hTrackingMenu = m_hMenu; BOOL bOK = ::TrackPopupMenu(m_hMenu, nFlags, x, y, 0, pThreadState->m_hTrackingWindow, lpRect); pThreadState->m_hTrackingWindow = hWndOld; pThreadState->m_hTrackingMenu = hMenuOld; return bOK; } Any ideas, cause I really don't understand why ...:((

        H Offline
        H Offline
        Hari Krishnan Noida
        wrote on last edited by
        #3

        Hi, do the following things, 1. Declare CMenu Variable as a member variable 2. Load the menu, during initialization. 3. And, try now, it should work. regards ~Hari~

        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