|
|
Comments and Discussions
|
|
 |

|
Unfortunately this this class it won't work on w7. More, the visual scan method it will take a minute to scan the tray rect, if Aero is enabled...due to a slow call to GetPixel() on desktop's hwnd.
And here it's a fix for the visual scan technique. We drop GetPixel() and will capture the tray icon rect as an CImage and perform the visual scan on that.
please include hist 2 files: ScreenImage.h
#pragma once
#include <atlimage.h>
class CScreenImage : public CImage
{
public:
BOOL CaptureRect(const CRect& rect) throw();
BOOL CaptureScreen() throw();
BOOL CaptureWindow(HWND hWnd) throw();
};
ScreenImage.cpp
#include "StdAfx.h"
#include "ScreenImage.h"
BOOL CScreenImage::CaptureRect(const CRect& rect)
{
CImage::Destroy();
HDC hDCScreen = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
HDC hDCMem = ::CreateCompatibleDC(hDCScreen);
HBITMAP hBitmap =
::CreateCompatibleBitmap(hDCScreen, rect.Width(), rect.Height());
HBITMAP hBmpOld = (HBITMAP)::SelectObject(hDCMem, hBitmap);
DWORD dwRop = SRCCOPY | CAPTUREBLT;
BOOL bRet = ::BitBlt(hDCMem, 0, 0, rect.Width(), rect.Height(),
hDCScreen,
rect.left, rect.top, dwRop);
Attach(hBitmap);
::SelectObject(hDCMem, hBmpOld);
::DeleteDC(hDCMem);
::DeleteDC(hDCScreen);
return bRet;
}
BOOL CScreenImage::CaptureScreen()
{
CRect rect(0, 0, ::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN));
return CaptureRect(rect);
}
BOOL CScreenImage::CaptureWindow(HWND hWnd)
{
BOOL bRet = FALSE;
if(::IsWindow(hWnd))
{
CRect rect;
::GetWindowRect(hWnd, rect);
bRet = CaptureRect(rect);
}
return bRet;
}
then in
BOOL CTrayIconPosition::FindOutPositionOfIcon(HICON icon)
capture the image from tray's rect:
m_image.CaptureRect(m_rtRectangleOfTheTray);
and modify your code like this:
m_image.CaptureRect(m_rtRectangleOfTheTray);
for(int iy = m_rtRectangleOfTheTray.Height()-3; iy > 1; iy--)
{
int iNoOfPixelsInLine=0;
for(int ix=0;ix<m_rtRectangleOfTheTray.Width();ix++)
{
COLORREF crPixel = m_image.GetPixel( ix, iy);
COLORREF crPixel2 = m_image.GetPixel( ix, iy-2);
COLORREF crPixel3 = m_image.GetPixel( ix, iy+2);
and here:
m_ptPosition.x = m_rtRectangleOfTheTray.left + ix-1;
m_ptPosition.y = m_rtRectangleOfTheTray.top +iy-6;
where:
CScreenImage m_image;
et voila, the tray rect it's working fine with aero.
At the end I found that after
Shell_NotifyIcon(NIM_MODIFY, &nid);
we must add a Sleep(100) to let the shell paint the black icon; otherwise we may not capture the black icon.
modified 9 Mar '12 - 1:48.
|
|
|
|

|
Error 1 error C3867: 'CBalloonHelp::KeyboardHookProc': function call missing argument list; use '&CBalloonHelp::KeyboardHookProc' to create a pointer to member c:\downloads\ctrayiconposition_src\balloonhelp.cpp 205
Error 2 error C3867: 'CBalloonHelp::MouseHookProc': function call missing argument list; use '&CBalloonHelp::MouseHookProc' to create a pointer to member c:\downloads\ctrayiconposition_src\balloonhelp.cpp 206
Error 3 error C3867: 'CBalloonHelp::CallWndRetProc': function call missing argument list; use '&CBalloonHelp::CallWndRetProc' to create a pointer to member c:\downloads\ctrayiconposition_src\balloonhelp.cpp 207
Error 4 error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CBalloonHelp::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' c:\downloads\ctrayiconposition_src\balloonhelp.cpp 1085
Any ideas?
"The true sign of intelligence is not knowledge but imagination." - Albert Einstein
|
|
|
|

|
I know this is several years too late, but for future reference and as a general comment, why not do what the error messages tell you to?
For errors 1-3 change the signature of the calls
In the case of error 4, change the return value from UINT to LRESULT
--
http://www.coruscant.co.uk/
|
|
|
|

|
Just change the statement
KeyboardHookProc
MouseHookProc
CallWndRetProc
to
&CBalloonHelp::KeyboardHookProc
&CBalloonHelp::MouseHookProc
&CBalloonHelp::CallWndRetProc
World is vivid!
|
|
|
|
|

|
how to delete the trayicon started by another app.
I only have the Trayicon App's HWND, and i do not know its uid and callback function ect...
can anyone help me for deleting the trayicon by using my own App.? i appreciate for
if it is deleted, how to restore the trayicon just being deleted
I know the MSN plug-in can hide the trayicon and the windows of the MSN.
It really convenience that officer can use this to hide the MSN when the manager coming when they're using MSN to contact with friends.(because the manager thought MSN was a waste of working time)
I thought [ShellRegisterCallbacks] could do this.
Using this callback function can forward the [Shell_NotifyIcon] function to a custom shell.
But this way can only work when the MSN runs after the app, I don't know how to do this when the MSN has already run.
hi
|
|
|
|
|

|
I suspect you can. You need just to pass a valid HWND of window that created an icon and the icon id (so this class could be modified to do the trick).
Cheers!
Check out my software at: http://www.ireksoftware.com
|
|
|
|

|
Hi,
I am facing one problem: In my application I want to delete my printer Queue document. I am able to delete successfully. \
Now my problem is, the system Tray Icon's tool tip text is not updating the status. it is showing some document is pending in the printer queue.
So I am planning to delete/refresh the printer Icon from the system tray, if any one could help in this then it will be great!...
My mail ID Sebastin_saji@hotmail.com
T.Sebastin.T
|
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Ever wanted to know position of your tray icon? Windows supplies no API for that. This class is a compact solution that works.
| Type | Article |
| Licence | CPOL |
| First Posted | 20 Feb 2003 |
| Views | 171,180 |
| Downloads | 4,420 |
| Bookmarked | 81 times |
|
|