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
Solved

CWinApp Tray Application

Posted on 1998-12-08
8
668 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 548
lucky13 challenge 11 154
fix34  challenge 9 142
sumHeights2  challenge 7 115
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.

856 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