Solved

CWinApp Tray Application

Posted on 1998-12-08
8
649 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
Complete beginner needs help making a cron job 9 110
abstract class with all non abstract mentods 6 76
MaxSpan challenge 9 80
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

24 Experts available now in Live!

Get 1:1 Help Now