CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Jul 2002
    Posts
    372

    tray menu leaking handles

    hi guys,

    my application has a tray icon with a tray menu.
    problem is that in the process of showing the tray
    menu and closing it, i loose about 3-6 GDI handles, consistently.

    there is nothing in the code that points to this handle lose.
    i might be wrong and really need some help here so i'm attaching the code fragment:

    Code:
    case WM_RBUTTONUP:
    		{
    			BOOL busyStatus = (BOOL)AfxGetMainWnd()->SendMessage( WM_IS_BUSY );
    			if( busyStatus ) {
    				return 0;
    			}
    
    			CMenu menu;
    			if (!menu.LoadMenu(m_niData.uID)) {
    				return 0;
    			}
    			
    			CMenu* pSubMenu = menu.GetSubMenu(0);
    			if (pSubMenu == NULL) {
    				return 0;
    			}
    
    			const int n = theApp.GetAccountsCount();
    			const DWORD flags = ( n > 0 ? MF_ENABLED : MF_DISABLED | MF_GRAYED );
    
    			pSubMenu->SetDefaultItem( ID_RESTORE );
    			pSubMenu->EnableMenuItem( ID_CHECKNOW, MF_BYCOMMAND | flags );
    			pSubMenu->EnableMenuItem( ID_REMOVE, MF_BYCOMMAND | flags );
    			pSubMenu->EnableMenuItem( ID_ADD, n == MAX_ACCOUNTS ? MF_DISABLED | MF_GRAYED : MF_ENABLED );
    
    			CPoint pos;
    			GetCursorPos(&pos);
    			::SetForegroundWindow(m_hWndNotify);
    			::TrackPopupMenu(pSubMenu->m_hMenu, 0, pos.x, pos.y, 0, m_hWndNotify, NULL);
    			::PostMessage(m_hWndNotify, WM_NULL, 0, 0);
    
    			menu.DestroyMenu();
    your help is appreciated !
    Last edited by neo_the_1; May 26th, 2009 at 02:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured