#include "windows.h"
#include <conio.h>
#include "resource.h"
#include <stdio.h>
#include <process.h>
#include "taskbaricon.h"
// --------------------------------------------------------------------------
// Define callbacks for managing mouse events on showed icon.
// --------------------------------------------------------------------------
void __stdcall LeftButtonClickHandler(
char* p_IconNameCurrentlyShowed,
int p_x,
int p_y
)
{
char l_Str[MAX_PATH];
sprintf(
l_Str,
"(CurrentIconFrameName: %s) LeftButtonClickHandler mouse coordinates <x,y>==<%u,%u>",
p_IconNameCurrentlyShowed,
p_x,
p_y);
::MessageBox(
NULL,
l_Str,
"Application Event Handler",
MB_OK);
}
void __stdcall RightButtonClickHandler(
char* p_IconNameCurrentlyShowed,
int p_x,
int p_y
)
{
/*
char l_Str[MAX_PATH];
sprintf(
l_Str,
"(CurrentIconFrameName: %s) RightButtonClickHandler mouse coordinates <x,y>==<%u,%u>",
p_IconNameCurrentlyShowed,
p_x,
p_y);
::MessageBox(
NULL,
l_Str,
"Application Event Handler",
MB_OK);
*/
}
void __stdcall LeftButtonDoubleClickHandler(
char* p_IconNameCurrentlyShowed,
int p_x,
int p_y
)
{
char l_Str[MAX_PATH];
sprintf(
l_Str,
"(CurrentIconFrameName: %s) LeftButtonDoubleClickHandler mouse coordinates <x,y>==<%u,%u>",
p_IconNameCurrentlyShowed,
p_x,
p_y);
::MessageBox(
NULL,
l_Str,
"Application Event Handler",
MB_OK);
}
// ---------------------------------------------------
// Callback for managing user selection on popup menu.
// ---------------------------------------------------
void __stdcall PopupUserActionHandler(int p_MenuItemIdentifier)
{
char l_Text1[]="Option1";
char l_Text2[]="Option2";
char l_Text3[]="Option3";
char l_Text4[]="Option4";
char l_Str[MAX_PATH];
char l_UserChoice[MAX_PATH];
if (p_MenuItemIdentifier==1)
{
strcpy(l_UserChoice,l_Text1);
}
else
if (p_MenuItemIdentifier==2)
{
strcpy(l_UserChoice,l_Text2);
}
else
if (p_MenuItemIdentifier==3)
{
strcpy(l_UserChoice,l_Text3);
}
else
if (p_MenuItemIdentifier==4)
{
strcpy(l_UserChoice,l_Text4);
}
else
{
// unknown
strcpy(l_UserChoice,"Unknown");
}
sprintf(l_Str,"User selection: %s", l_UserChoice);
MessageBox(NULL,l_Str,"Popup menu user choice",MB_OK);
}
// --------------------------------------------------------------------------
// User have to press a char to go ahead.
// --------------------------------------------------------------------------
void GetChar(char* p_Text)
{
printf(p_Text);
int l_Char = _getch();
}
// --------------------------------------------------------------------------
// Entry point.
// --------------------------------------------------------------------------
int main(int argc, char* argv[])
{
// Create a "task bar icon" object.
ITaskBarIcon* l_TaskBarIcon = ITaskBarIcon::Create();
// Create a set of icons. Each of these icon represent one possible
// status (f.i. "Disactivated", "Activated", "Idle", "Working").
HINSTANCE hInstance = (HINSTANCE) GetModuleHandle (NULL);
HICON l_Icon1 = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1));
HICON l_Icon2 = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON2));
HICON l_Icon3 = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON3));
HICON l_Icon4 = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON4));
// Set the icon frames to the object.
l_TaskBarIcon->SetIconFrame(
"Disactivated",
l_Icon1,
IDI_ICON1,
"Process Disactivated");
l_TaskBarIcon->SetIconFrame(
"Activated",
l_Icon2,
IDI_ICON2,
"Process Activated");
l_TaskBarIcon->SetIconFrame(
"Idle",
l_Icon3,
IDI_ICON3,
"Process Idle");
l_TaskBarIcon->SetIconFrame(
"Working",
l_Icon4,
IDI_ICON4,
"Process Working");
// ---------------------
// Set popup menu items.
// ---------------------
l_TaskBarIcon->SetPopupMenuItem(
"Option1",
1);
l_TaskBarIcon->SetPopupMenuItem(
"Option2",
2);
l_TaskBarIcon->SetPopupMenuItem(
"Option3",
3);
l_TaskBarIcon->SetPopupMenuItem(
"Option4",
4);
// ----------------------------------------------------------------------
// Set various event handlers.
// ----------------------------------------------------------------------
l_TaskBarIcon->SetLeftButtonClickHandler(
LeftButtonClickHandler);
l_TaskBarIcon->SetRightButtonClickHandler(
RightButtonClickHandler);
l_TaskBarIcon->SetLeftButtonDoubleClickHandler(
LeftButtonDoubleClickHandler);
// Handler for getting user selection on icon popup menu.
l_TaskBarIcon->SetPopupHandler(PopupUserActionHandler);
// ----------------------------------------------------------------------
// Start and show the initial icon.
// ----------------------------------------------------------------------
GetChar("Press a key to show an icon on the taskbar\n");
l_TaskBarIcon->Start("Disactivated");
GetChar("Press a key to change icon status\n");
// ----------------------------------------------------------------------
// Change the hicon appearence according to certain events.
// ----------------------------------------------------------------------
//...
l_TaskBarIcon->ChangeIconFrame("Idle");
GetChar("Press a key to change icon status\n");
//...
l_TaskBarIcon->ChangeIconFrame("Activated");
GetChar("Press a key to change icon status\n");
//...
l_TaskBarIcon->ChangeIconFrame("Working");
GetChar("Press a key to change icon status\n");
//...
l_TaskBarIcon->ChangeIconFrame("Idle");
GetChar("Press a key to change icon status\n");
//...
l_TaskBarIcon->ChangeIconFrame("Disactivated");
//...
// ----------------------------------------------------------------------
// Release the "task bar icon" object.
// ----------------------------------------------------------------------
GetChar("Press a key to make the icon disappear from the taskbar\n");
l_TaskBarIcon->Stop();
l_TaskBarIcon->Release();
GetChar("Press a key to exit\n");
return 0;
}