Re: Using WM_LBUTTONUP
From: Gizmo (Gizmo_at_discussions.microsoft.com)
Date: 02/07/05
- Next message: AndyCarr: "Re: How can I tell which OS Platform a CE device is using?"
- Previous message: Wei Lee: "How to setup folder sharing in Simulator?"
- In reply to: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Next in thread: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Reply: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 7 Feb 2005 07:19:02 -0800
I put all the code, It will be more simple for me to explain. I've tried to
modify the sample program, I've added an icon on the dialog box. And now I
wanna tap on that icon to turn off my PPC. The name of the icon is IDC_CLOSE.
I've placed 2 comments on the code //Here...
Thanks
#include "stdafx.h"
#define TRAY_NOTIFYICON WM_USER + 2001
#define WMO_PALMTRAYAPP WM_USER + 2002
#define ID_TRAY 5000
// === Function Prototypes
====================================================
BOOL WINAPI MainDlgProc(
HWND,
UINT,
WPARAM,
LPARAM
);
// === Global Variables
=======================================================
HINSTANCE g_hInst;
BOOL g_bWinHide = FALSE;
BOOL g_bPalmTrayAppActive = FALSE;
// Tray Icons and Notification ------------------------------
BOOL TrayMessage(
HWND hwnd,
DWORD dwMessage,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
BOOL res = FALSE;
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = hwnd;
tnd.uID = uID;
tnd.uFlags = NIF_MESSAGE|NIF_ICON;
tnd.uCallbackMessage = TRAY_NOTIFYICON;
tnd.hIcon = hIcon;
tnd.szTip[0] = '\0';
res = Shell_NotifyIcon(dwMessage, &tnd);
return res;
}
void TrayIconDelete(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
TrayMessage(hwnd, NIM_DELETE, uID, hIcon, NULL);
}
void TrayIconModify(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
//animate icons
TrayMessage(hwnd, NIM_MODIFY, uID, hIcon, NULL);
}
void TrayIconAdd(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
TrayMessage(hwnd, NIM_ADD, uID, hIcon, NULL);
}
// === Application Entry Point
================================================
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrev,
LPTSTR lpCmdLine,
int nShowCmd
)
{
int retcode;
g_hInst = hInstance; // Save instance handle in global
InitCommonControls();
retcode = DialogBox( g_hInst, MAKEINTRESOURCE(IDD_PALMTRAYAPP), NULL,
(DLGPROC)MainDlgProc );
return(retcode);
}
// === Main Window (dialog) Proc
==============================================
BOOL WINAPI MainDlgProc(
HWND hDlg,
UINT Msg,
WPARAM wParam,
LPARAM lParam
)
{
switch (Msg)
{
case WM_CLOSE:
//Clean up on Close and remove tray icons
TrayIconDelete(hDlg, ID_TRAY, LoadIcon( g_hInst,
MAKEINTRESOURCE(IDI_ICON2) ), NULL);
EndDialog(hDlg, TRUE);
return(TRUE);
case WM_INITDIALOG:
//On Pocket PC devices you normally create all Dialog's as
fullscreen dialog's
// with an OK button in the upper corner.
SHINITDLGINFO shidi;
// Create a Done button and size it.
shidi.hDlg = hDlg;
//initialzes the dialog based on the dwFlags parameter
SHInitDialog(&shidi);
//Set Tray Icon
TrayIconAdd(hDlg, ID_TRAY, LoadIcon(g_hInst,
MAKEINTRESOURCE(IDI_ICON2)), NULL);
SetForegroundWindow(hDlg); // make us come to the front
return(TRUE);
case WM_LBUTTONUP:
MessageBox( NULL, NULL, NULL, NULL); //Here I've added my code
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDCANCEL:
g_bPalmTrayAppActive = FALSE;
TrayIconDelete(hDlg, ID_TRAY, LoadIcon( g_hInst,
MAKEINTRESOURCE(IDI_ICON2) ), NULL);
EndDialog( hDlg, TRUE );
return(TRUE);
break;
case IDOK:
//Hide window
if (FALSE == g_bWinHide)
{
ShowWindow(hDlg, SW_HIDE);
g_bWinHide = TRUE;
}
//Active state
PostMessage(hDlg, WM_COMMAND, (WPARAM)WMO_PALMTRAYAPP, 0);
return(TRUE);
break;
}
case TRAY_NOTIFYICON:
switch (lParam)
{
case WM_LBUTTONDOWN: //Here I've found the example, intercept the
tap on the icon
if (ID_TRAY == wParam)
{
g_bPalmTrayAppActive = FALSE;
if (TRUE == g_bWinHide)
{
ShowWindow(hDlg, SW_SHOW);
SetForegroundWindow(hDlg); // make us come to the front
g_bWinHide = FALSE;
}
else
{
g_bWinHide = TRUE;
}
}
break;
}
break;
}
return( FALSE );
}
"Michael J. Salamone [eMVP]" wrote:
> You're calling Shell_NotifyIcon to add your tray items?
>
> In the NOTIFYICONDATA structure passed to Shell_NotifyIcon is a field called
> uCallbackMessage. That is the message (application defined) you will
> receive when there is an icon event, not WM_LBUTTONUP.
> --
>
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com
>
>
>
> "Gizmo" <Gizmo@discussions.microsoft.com> wrote in message
> news:EBC4037D-CB1C-42F9-9A60-C110B18C3306@microsoft.com...
> > Hi,
> > I'm writing a small app with Embedded Visual C++, I need to handle a
> > message
> > when I tap over tree Icons or Immages. I've started from the demo of
> > TrayApp
> > Sample code.
> > I've write the code after the WM_INITDIALOG
> >
> > case WM_LBUTTONUP:
> > MessageBox( NULL, NULL, NULL, NULL); //Only for testing
> >
> > It works on the entire of the dialog box and i need to use only on the 3
> > icons.
> > Can anybody help me? Please be patient I'm new with C++
> > Thanks
>
>
>
- Next message: AndyCarr: "Re: How can I tell which OS Platform a CE device is using?"
- Previous message: Wei Lee: "How to setup folder sharing in Simulator?"
- In reply to: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Next in thread: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Reply: Michael J. Salamone [eMVP]: "Re: Using WM_LBUTTONUP"
- Messages sorted by: [ date ] [ thread ]