// JP opened flex table

Click to See Complete Forum and Search --> : Help to add systray menu


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;
}

Marc G
April 22nd, 2007, 03:50 AM
[ moved thread ]

ncode
April 25th, 2007, 01:45 AM
Hello, i have got a code, and i need put "menu-tray" when click mouse right in this "icon".
You have to create popup menu and use TrackPopupMenuEx() function.
Here is my handler for mouse actions on tray icon:

//m_hWnd - main window handle
//PopupMenu - menu handle
LRESULT CMainFrame::OnTrayNotify(UINT /*uMsg*/, WPARAM wparam, LPARAM lparam, BOOL& /*bHandled*/)
{
if(TRAY_ICON_ID != static_cast<UINT>(wparam))
return 0;

switch(lparam)
{
case WM_LBUTTONDOWN:
{
ShowWindow(SW_SHOWNORMAL);
::SetForegroundWindow(m_hWnd);
break;
}
case WM_RBUTTONDOWN:
{
::SetForegroundWindow(m_hWnd);
POINT cursor_pos;
::GetCursorPos(&cursor_pos);
if(FALSE == ::TrackPopupMenuEx(::GetSubMenu(PopupMenu, 0),
TPM_LEFTBUTTON|TPM_RIGHTBUTTON, cursor_pos.x, cursor_pos.y, m_hWnd, NULL))
TraceLastError(_T("OnTrayNotification(): TrackPopupMenuEx() failed"));
break;
}
}
return 0;
}

//JP added flex table