|
-
May 26th, 2009, 01:58 AM
#1
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.
-
May 26th, 2009, 02:12 AM
#2
Re: tray menu leaking handles
Hi,
Just a guess, but maybe the removal of the menu item is causing a problem.
Do you still get the leak without the EnableMenuItems calls?
Alan
-
May 26th, 2009, 02:46 AM
#3
Re: tray menu leaking handles
 Originally Posted by neo_the_1
... 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.
I see nothing in the posted code snippet that might cause handle leaks. I use almost the same code without any problem.
Perhaps, something wrong happens somewhere outside this code, for instance, in this call:
Code:
const int n = theApp.GetAccountsCount();
or somewhere else.
Last edited by VictorN; May 26th, 2009 at 03:30 AM.
Victor Nijegorodov
-
May 26th, 2009, 03:28 AM
#4
Re: tray menu leaking handles
Handle leaking is probably located in WM_PAINT, or OnPaint, OnDraw functions...can you paste that code too?
-
May 26th, 2009, 05:17 AM
#5
Re: tray menu leaking handles
well, i dont really handle wm_paint or so.
as for the call to theApp.GetAccountsCount(), it just returns a vector size.
it's really annoying .. every time i show the menu .. booom i loose minimum 3 gdi handles.
-
May 26th, 2009, 05:32 AM
#6
Re: tray menu leaking handles
found it ! (not yet fixed it)
Code:
bool CTrayIcon::SetIcon(LPCTSTR lpszIconName)
{
int cx = ::GetSystemMetrics(SM_CXSMICON);
int cy = ::GetSystemMetrics(SM_CYSMICON);
m_hIcon = ( HICON )::LoadImage( AfxGetResourceHandle( ), lpszIconName, IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR );
return SetIcon( m_hIcon );
}
bool CTrayIcon::SetIcon(UINT nIDResource)
{
return SetIcon( MAKEINTRESOURCE( nIDResource ) );
}
the second SetIcon is called each time i right click on the tray.
it appears that there is no release for the previously allocated icon handle.
-
May 26th, 2009, 05:41 AM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|