XP.
April 21st, 2007, 07:49 PM
Hello, i have got a code, and i need put "menu-tray" when click mouse right in this "icon". If any can help me, to incorporate this please, thanks. To detect mouse right click on systray im using this:
if (lParam == WM_RBUTTONUP)
{
//Here go´s code to show MENU
return TRUE;
}
here is my source code
#include "InjectLibrary.h"
#include <stdio.h>
#include <tlhelp32.h>
#include <iostream>
#include <fstream>
using namespace std;
#pragma comment(lib,"urlmon.lib")
#define WM_TRAY ( WM_USER+1 )
NOTIFYICONDATA trayIcon;
HWND hwnd;
DWORD WINAPI LaserInjectorThread( LPVOID lpParam );
VOID TrayIcon( WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK LaserInjectorDialog( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam );
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HANDLE handle = CreateMutex( NULL, TRUE, "Laser" );
if ( GetLastError() != ERROR_SUCCESS )
{
return 0;
}
trayIcon.cbSize = sizeof( NOTIFYICONDATA );
trayIcon.uCallbackMessage = WM_TRAY;
trayIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
trayIcon.uID = 1;
trayIcon.hIcon = LoadIcon( hInstance, (CHAR*)IDI_LASERINJECTOR );
sprintf( trayIcon.szTip, "Laser" );
CreateThread( NULL, 0, LaserInjectorThread, NULL, 0, new DWORD );
DialogBox( hInstance, MAKEINTRESOURCE(IDD_LASERINJECTOR), hwnd, (DLGPROC)LaserInjectorDialog );
return 0;
}
DWORD WINAPI LaserInjectorThread( LPVOID lpParam )
{
CHAR mainDllName[MAX_PATH];
GetModuleFileName( NULL, mainDllName, MAX_PATH );
mainDllName[ strlen( mainDllName ) - 3 ] = 0;
strcat( mainDllName, "dll" );
WIN32_FIND_DATA WFD;
if ( FindFirstFile( mainDllName, &WFD ) == INVALID_HANDLE_VALUE )
{
CHAR failMsg[512] = { 0 };
exit( 0 );
}
return 0;
}
VOID TrayIcon( WPARAM wParam, LPARAM lParam )
{
if ( (UINT)lParam == WM_LBUTTONUP )
{
Shell_NotifyIcon( NIM_DELETE, &trayIcon );
ShowWindow( (HWND)wParam, SW_SHOW );
}
}
LRESULT CALLBACK LaserInjectorDialog( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch ( Msg )
{
case WM_INITDIALOG:
return TRUE;
case WM_SYSCOMMAND:
if ( wParam == SC_MINIMIZE )
{
trayIcon.hWnd = hDlg;
Shell_NotifyIcon( NIM_ADD, &trayIcon );
ShowWindow( hDlg, SW_HIDE );
return TRUE;
}
break;
case WM_TRAY:
TrayIcon( (WPARAM)(hDlg), lParam );
break;
}
return FALSE;
}
if (lParam == WM_RBUTTONUP)
{
//Here go´s code to show MENU
return TRUE;
}
here is my source code
#include "InjectLibrary.h"
#include <stdio.h>
#include <tlhelp32.h>
#include <iostream>
#include <fstream>
using namespace std;
#pragma comment(lib,"urlmon.lib")
#define WM_TRAY ( WM_USER+1 )
NOTIFYICONDATA trayIcon;
HWND hwnd;
DWORD WINAPI LaserInjectorThread( LPVOID lpParam );
VOID TrayIcon( WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK LaserInjectorDialog( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam );
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HANDLE handle = CreateMutex( NULL, TRUE, "Laser" );
if ( GetLastError() != ERROR_SUCCESS )
{
return 0;
}
trayIcon.cbSize = sizeof( NOTIFYICONDATA );
trayIcon.uCallbackMessage = WM_TRAY;
trayIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
trayIcon.uID = 1;
trayIcon.hIcon = LoadIcon( hInstance, (CHAR*)IDI_LASERINJECTOR );
sprintf( trayIcon.szTip, "Laser" );
CreateThread( NULL, 0, LaserInjectorThread, NULL, 0, new DWORD );
DialogBox( hInstance, MAKEINTRESOURCE(IDD_LASERINJECTOR), hwnd, (DLGPROC)LaserInjectorDialog );
return 0;
}
DWORD WINAPI LaserInjectorThread( LPVOID lpParam )
{
CHAR mainDllName[MAX_PATH];
GetModuleFileName( NULL, mainDllName, MAX_PATH );
mainDllName[ strlen( mainDllName ) - 3 ] = 0;
strcat( mainDllName, "dll" );
WIN32_FIND_DATA WFD;
if ( FindFirstFile( mainDllName, &WFD ) == INVALID_HANDLE_VALUE )
{
CHAR failMsg[512] = { 0 };
exit( 0 );
}
return 0;
}
VOID TrayIcon( WPARAM wParam, LPARAM lParam )
{
if ( (UINT)lParam == WM_LBUTTONUP )
{
Shell_NotifyIcon( NIM_DELETE, &trayIcon );
ShowWindow( (HWND)wParam, SW_SHOW );
}
}
LRESULT CALLBACK LaserInjectorDialog( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch ( Msg )
{
case WM_INITDIALOG:
return TRUE;
case WM_SYSCOMMAND:
if ( wParam == SC_MINIMIZE )
{
trayIcon.hWnd = hDlg;
Shell_NotifyIcon( NIM_ADD, &trayIcon );
ShowWindow( hDlg, SW_HIDE );
return TRUE;
}
break;
case WM_TRAY:
TrayIcon( (WPARAM)(hDlg), lParam );
break;
}
return FALSE;
}