Solved

CWinApp Tray Application

Posted on 1998-12-08
8
637 Views
Last Modified: 2013-11-20
I have a standard C App using WinMain and a dispatch function, but I want to convert into using a CWinApp, and the class wizard, for dialogs and stuff. I have 2 menus IDR_LEFT_MENU and IDR_RIGHT_MENU, for use when the user uses the left and right buttons on the tray icon.

I have had a go at converting my ShellNotify stuff, but it doesn't stay in the tray. I don't know where to put the MenuHandler either.

Thoereticaly (as far as I can work out), I just need 3 functions (maybe 4)

On InitInstance() - create a NOTIFYICON thingy and NIM_ADD it. (need to create an hwnd??)
On ExitInstance NIM_DELETE NOTIFYICON thingy.
On left button pressed on icon - trackMenuEx(LeftMenu)
On rightbutton pressed on icon - trackMenuEx(RightMenu)

How wrong is this?

Can anyone provide a very simple shell and explanation?

Tanks.
0
Comment
Question by:nigel5
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:nigel5
Comment Utility
Edited text of question
0
 

Author Comment

by:nigel5
Comment Utility
Edited text of question
0
 
LVL 1

Expert Comment

by:fkurucz
Comment Utility
Hi nigle5,

the following fragment shows you how to implement the message map for an taskbar-icon (taken from a Dialog-Project):



from MyDlg.cpp:
---

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
      //{{AFX_MSG_MAP(CItimeDlg)
      ON_MESSAGE(WM_USER+0x01, OnWMUser01)
//     ...
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CMyDlg::InstallIcon()
{
//  ...
    NOTIFYICONDATA  nid;
//  ...
    nid.uCallbackMessage    =   WM_USER+0x01;
    nid.hWnd                =   m_hwnd;
//  ...
    Shell_NotifyIcon(   NIM_ADD,    &nid);
//  ...
}

BOOL CMyDlg::OnWMUser01(WPARAM wParam, LPARAM lParam)
{
//  ...
    // return TRUE to keep the icon alive
    return TRUE;
}

---

hope it helps.

bye,
  feri

0
 
LVL 2

Expert Comment

by:wyy_cq
Comment Utility
after you add the icon to the tray.
your window will receive the mouse move, botton down/up message.

      NOTIFYICONDATA tn;
      tn.cbSize=sizeof(tn);
      tn.hIcon=::CopyIcon(hIcon);
      lstrcpy(tn.szTip,pszTip);
      tn.uCallbackMessage=uMessage;// the message will send to the hWnd , when mouse move ,button/down
      tn.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
      tn.uID=uID;
      tn.hWnd=hWnd;// this window will receive the message
      Shell_NotifyIcon(NIM_ADD,&tn);

in your window proc add this line to test the left button down message
proc(hwnd,message,wp,lp)
{
..
      case(you_added_Message)
      {
            if(lP==WM_LBUTTONUP)
            {
                  messageBox("l b up");
            }
      }
         break;
.....
}


i ever added the icon to the tray, and subclass the window,
all the message was send to my wndProc .
in my wndProc i deal with all the message associated with system tray.

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:nigel5
Comment Utility
I did actually want the CWinApp version sorry.

If fkurucz, you want the points, please answer the qoestion.

regards
Nigel.
0
 
LVL 2

Expert Comment

by:wyy_cq
Comment Utility
you declared your application is C standard with WinMain.

if your application is base MFC,
you need to map the message ,the message is the parameter when you add the tray icon .



0
 
LVL 1

Accepted Solution

by:
fkurucz earned 50 total points
Comment Utility
thank you,

bye,
  feri
0
 

Author Comment

by:nigel5
Comment Utility
wwy_cq, I said I already had a C app with a winmain, but I wanted to port it to MFC using a CWinApp.

Sorry.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 104
repeatEnd java challenge 42 83
Define unique primary key 9 81
Window placement 17 64
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now