Solved

CWinApp Tray Application

Posted on 1998-12-08
8
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:nigel5
ID: 1325888
Edited text of question
0
 

Author Comment

by:nigel5
ID: 1325889
Edited text of question
0
 
LVL 1

Expert Comment

by:fkurucz
ID: 1325890
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:wyy_cq
ID: 1325891
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
 

Author Comment

by:nigel5
ID: 1325892
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
ID: 1325893
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
ID: 1325894
thank you,

bye,
  feri
0
 

Author Comment

by:nigel5
ID: 1325895
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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