I am trying to force the tray icon to always show with Delphi.

I am trying to force the tray icon to always show with Delphi.
I found that FASTCOPY dose it in c++.
The source is at https://fastcopy.jp/archive/FastCopy351src.zip

Now to the point i am trying to translate the code to pascal.

The file is tmisc.cpp
and in mainwin.cpp line 2885 it uses the function ForceSetTrayIcon

Can any one help ?

from tmisc.cpp

class __declspec(uuid("FB852B2C-6BAD-4605-9551-F15F87830935")) ITrayNotify : public IUnknown {
public:
virtual HRESULT __stdcall RegisterCallback(INotificationCB *) = 0;
virtual HRESULT __stdcall SetPreference(const NOTIFYITEM *) = 0;
virtual HRESULT __stdcall EnableAutoTray(BOOL) = 0;
};

class __declspec(uuid("D133CE13-3537-48BA-93A7-AFCD5D2053B4")) ITrayNotify8 : public IUnknown {
public:
virtual HRESULT __stdcall RegisterCallback(INotificationCB *, u_long *) = 0;
virtual HRESULT __stdcall UnregisterCallback(u_long) = 0;
virtual HRESULT __stdcall SetPreference(const NOTIFYITEM *) = 0;
virtual HRESULT __stdcall EnableAutoTray(BOOL) = 0;
virtual HRESULT __stdcall DoAction(BOOL) = 0;
};

const CLSID TrayNotifyId = {
0x25DEAD04, 0x1EAC, 0x4911, {0x9E, 0x3A, 0xAD, 0x0A, 0x4A, 0xB5, 0x60, 0xFD}
};


BOOL ForceSetTrayIcon(HWND hWnd, UINT id, DWORD pref)
{
BOOL ret = FALSE;
NOTIFYITEM ni = { 0, 0, 0, hWnd, pref, id, 0 };

if (IsWin8()) {
ITrayNotify8 *tn = NULL;

CoCreateInstance(TrayNotifyId, NULL, CLSCTX_LOCAL_SERVER, __uuidof(ITrayNotify8),
(void **)&tn);
if (tn) {
if (SUCCEEDED(tn->SetPreference(&ni))) {
ret = TRUE;
}
tn->Release();
}
} else {
ITrayNotify *tn = NULL;

CoCreateInstance(TrayNotifyId, NULL, CLSCTX_LOCAL_SERVER, __uuidof(ITrayNotify),
(void **)&tn);
if (tn) {
if (SUCCEEDED(tn->SetPreference(&ni))) {
ret = TRUE;
}
tn->Release();
}
}

return ret;
}
from mainwin.cpp
#define FASTCOPY_NIM_ID 100

ForceSetTrayIcon(hWnd, FASTCOPY_NIM_ID);

https://fastcopy.jp/archive/FastCopy351src.zip

Comments

  1. I hate your program already, forcing itself into my notification area whether or not I like it.

    ReplyDelete
  2. AFAIK, this can't be enforced as Windows 10 gives the user total control over which tray icons that are visible and/or able to add notifications.

    Settings, Taskbar Settings, Select which Icons appear on the taskbar.

    Other than that, I agree with David.

    ReplyDelete
  3. Lars Fosdal i know about window 10 . otherwise i still think it is a good idea as an OPTION.

    ReplyDelete
  4. shlomo abuisak We already have the option. We know how to control what we see in our notification area.

    ReplyDelete
  5. Anyway, if you really want to do this dastardly deed go ahead. Translating this sort code is pretty straightforward. It maps across pretty much literally. What are you hoping to get from us?

    ReplyDelete
  6. David Heffernan some pascal source of the function if it is possible.

    ReplyDelete
  7. David Heffernan cause my knowledge with c++ is nil

    ReplyDelete
  8. David Heffernan i came from electronics Assembler c and Delphi but never c++

    ReplyDelete
  9. Now is your chance to learn a little. You don't need to know much at all. It's simply a literal translation. Presumably you know how to write COM code in Delphi?

    ReplyDelete
  10. Lars Fosdal Eli M thanks but all this is known and do not !! do the job. The software above forces !! the tray to show !!
    What you are referring is standard tray component. !!

    ReplyDelete
  11. shlomo abuisak Learn how to write COM code in Delphi and it's simple.

    ReplyDelete
  12. David Heffernan you are great . thank you for you help.
    after using D1 !! i should.

    ReplyDelete
  13. shlomo abuisak I mean, I could translate this code in my sleep, because I've done this sort of stuff before. But if you learn how to do it yourself that will be better for you. Then you'll learn something new and useful and you'll be able to judge whether or not the code is correct, decide on the risks of including code that is written against undocumented interfaces that are subject to change, and so on. Good luck.

    ReplyDelete

Post a Comment