Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: how i can send text to external program Pin
David Crow15-Aug-06 5:15
David Crow15-Aug-06 5:15 
AnswerRe: how i can send text to external program Pin
ms.linuz15-Aug-06 17:27
ms.linuz15-Aug-06 17:27 
AnswerRe: how i can send text to external program Pin
ensger16-Aug-06 2:45
ensger16-Aug-06 2:45 
GeneralRe: how i can send text to external program Pin
Hamid_RT16-Aug-06 5:07
Hamid_RT16-Aug-06 5:07 
QuestionRe: how i can send text to external program Pin
Hamid_RT16-Aug-06 5:07
Hamid_RT16-Aug-06 5:07 
AnswerRe: how i can send text to external program Pin
shortwave19-Aug-06 3:08
shortwave19-Aug-06 3:08 
QuestionHas a DLL been renamed? Pin
D G McKay15-Aug-06 4:50
D G McKay15-Aug-06 4:50 
QuestionDestroying window with popup menu Pin
Johniteq15-Aug-06 4:27
Johniteq15-Aug-06 4:27 
I have a problem related to a window that in some cases owns a context/popup menu.
Here is the code for the creation and tracking of the popup menu:
LRESULT
MyWindowClass::OnCreateAndTrackPopupMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HMENU aMenu = ::LoadMenu(_Module.GetResourceInstance(),(LPCTSTR)IDR_CONTEXT_MENU);

    if(aMenu != NULL)
    {
      HMENU hSubMenu = ::GetSubMenu(aMenu,0);
      if(hSubMenu != NULL)
      {
        SetForegroundWindow(m_hWnd);
        TrackPopupMenuEx(hSubMenu,TPM_LEFTALIGN|TPM_TOPALIGN,pt.x,pt.y,m_hWnd,NULL);
        ::PostMessage(m_hWnd, WM_NULL, 0, 0); 
      }
      ::DestroyMenu(aMenu);
    }
  return 0;
}


My application response to a window message that should deal with the destruction of the window above:
LRESULT
MyMainClass::OnDestroyWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
  ::PostMessage(MyWindowClass->m_hWnd,WM_CANCELMODE,0,0);
  MyWindowClass->DestroyWindow();
  delete MyWindowClass;
  MyWindowClass= NULL;
  return 0;
}


The problem: If the popup menu is present when the destruction (DestroyWindow()) takes place, the application will crash ("ERROR - Object deleted before window was destroyed"), because the popup menu still is active (still waiting for TrackPopupMenuEx() to return because WM_CANCELMODE never reach the window before it is destroyed).

So the question is, how can I make sure that the OnCreateAndTrackPopupMenu-function return before DestroyWindow() is executed?

john
AnswerRe: Destroying window with popup menu Pin
Maximilien15-Aug-06 4:59
Maximilien15-Aug-06 4:59 
GeneralRe: Destroying window with popup menu Pin
Johniteq16-Aug-06 1:37
Johniteq16-Aug-06 1:37 
AnswerRe: Destroying window with popup menu Pin
Michael Dunn15-Aug-06 13:12
sitebuilderMichael Dunn15-Aug-06 13:12 
GeneralRe: Destroying window with popup menu Pin
Johniteq16-Aug-06 1:42
Johniteq16-Aug-06 1:42 
QuestionStill need help with FTPConnection Pin
racing5715-Aug-06 4:20
racing5715-Aug-06 4:20 
AnswerRe: Still need help with FTPConnection Pin
includeh1015-Aug-06 6:49
includeh1015-Aug-06 6:49 
GeneralRe: Still need help with FTPConnection Pin
racing5715-Aug-06 10:50
racing5715-Aug-06 10:50 
GeneralRe: Still need help with FTPConnection Pin
thangnvhl15-Aug-06 21:53
thangnvhl15-Aug-06 21:53 
GeneralRe: Still need help with FTPConnection Pin
racing5715-Aug-06 23:00
racing5715-Aug-06 23:00 
GeneralRe: Still need help with FTPConnection Pin
Justin Tay16-Aug-06 2:23
Justin Tay16-Aug-06 2:23 
GeneralRe: Still need help with FTPConnection Pin
racing5716-Aug-06 3:46
racing5716-Aug-06 3:46 
GeneralRe: Still need help with FTPConnection Pin
Justin Tay16-Aug-06 22:01
Justin Tay16-Aug-06 22:01 
Questiontimers without windows Pin
m.dietz15-Aug-06 4:09
m.dietz15-Aug-06 4:09 
AnswerRe: timers without windows Pin
led mike15-Aug-06 4:26
led mike15-Aug-06 4:26 
GeneralRe: timers without windows Pin
m.dietz15-Aug-06 5:07
m.dietz15-Aug-06 5:07 
GeneralRe: timers without windows [modified] Pin
led mike15-Aug-06 5:53
led mike15-Aug-06 5:53 
GeneralRe: timers without windows Pin
m.dietz15-Aug-06 20:24
m.dietz15-Aug-06 20:24 

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.