Solved

CWinApp Tray Application

Posted on 1998-12-08
8
660 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 125
List out all word 7 292
has77  challenge 9 85
NotAlone Challenge 20 83
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

773 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