|
|
@ -11,147 +11,152 @@ |
|
|
|
#define ID_TRAY_ICON 2050 |
|
|
|
#define ID_TRAY_ICON 2050 |
|
|
|
#define WM_TRAYICON (WM_USER + 1) |
|
|
|
#define WM_TRAYICON (WM_USER + 1) |
|
|
|
|
|
|
|
|
|
|
|
void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) |
|
|
|
namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
HMENU hPopup = CreatePopupMenu(); |
|
|
|
namespace win32 |
|
|
|
InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About..."); |
|
|
|
{ |
|
|
|
InsertMenu (hPopup, 1, MF_BYPOSITION | MF_STRING, ID_EXIT , "Exit"); |
|
|
|
static void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) |
|
|
|
SetMenuDefaultItem (hPopup, ID_ABOUT, FALSE); |
|
|
|
|
|
|
|
SetFocus (hWnd); |
|
|
|
|
|
|
|
SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
POINT p; |
|
|
|
|
|
|
|
if (!curpos) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
GetCursorPos (&p); |
|
|
|
HMENU hPopup = CreatePopupMenu(); |
|
|
|
curpos = &p; |
|
|
|
InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About..."); |
|
|
|
} |
|
|
|
InsertMenu (hPopup, 1, MF_BYPOSITION | MF_STRING, ID_EXIT , "Exit"); |
|
|
|
|
|
|
|
SetMenuDefaultItem (hPopup, ID_ABOUT, FALSE); |
|
|
|
|
|
|
|
SetFocus (hWnd); |
|
|
|
|
|
|
|
SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0); |
|
|
|
|
|
|
|
|
|
|
|
WORD cmd = TrackPopupMenu (hPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, curpos->x, curpos->y, 0, hWnd, NULL); |
|
|
|
POINT p; |
|
|
|
SendMessage (hWnd, WM_COMMAND, cmd, 0); |
|
|
|
if (!curpos) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GetCursorPos (&p); |
|
|
|
|
|
|
|
curpos = &p; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DestroyMenu(hPopup); |
|
|
|
WORD cmd = TrackPopupMenu (hPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, curpos->x, curpos->y, 0, hWnd, NULL); |
|
|
|
} |
|
|
|
SendMessage (hWnd, WM_COMMAND, cmd, 0); |
|
|
|
|
|
|
|
|
|
|
|
void AddTrayIcon (HWND hWnd) |
|
|
|
DestroyMenu(hPopup); |
|
|
|
{ |
|
|
|
} |
|
|
|
NOTIFYICONDATA nid; |
|
|
|
|
|
|
|
memset(&nid, 0, sizeof(nid)); |
|
|
|
|
|
|
|
nid.cbSize = sizeof(nid); |
|
|
|
|
|
|
|
nid.hWnd = hWnd; |
|
|
|
|
|
|
|
nid.uID = ID_TRAY_ICON; |
|
|
|
|
|
|
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; |
|
|
|
|
|
|
|
nid.uCallbackMessage = WM_TRAYICON; |
|
|
|
|
|
|
|
nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (IDI_ICON1)); |
|
|
|
|
|
|
|
strcpy (nid.szTip, "i2pd"); |
|
|
|
|
|
|
|
Shell_NotifyIcon(NIM_ADD, &nid ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RemoveTrayIcon (HWND hWnd) |
|
|
|
static void AddTrayIcon (HWND hWnd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
NOTIFYICONDATA nid; |
|
|
|
NOTIFYICONDATA nid; |
|
|
|
nid.hWnd = hWnd; |
|
|
|
memset(&nid, 0, sizeof(nid)); |
|
|
|
nid.uID = ID_TRAY_ICON; |
|
|
|
nid.cbSize = sizeof(nid); |
|
|
|
Shell_NotifyIcon (NIM_DELETE, &nid); |
|
|
|
nid.hWnd = hWnd; |
|
|
|
} |
|
|
|
nid.uID = ID_TRAY_ICON; |
|
|
|
|
|
|
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; |
|
|
|
|
|
|
|
nid.uCallbackMessage = WM_TRAYICON; |
|
|
|
|
|
|
|
nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (IDI_ICON1)); |
|
|
|
|
|
|
|
strcpy (nid.szTip, "i2pd"); |
|
|
|
|
|
|
|
Shell_NotifyIcon(NIM_ADD, &nid ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
|
|
|
static void RemoveTrayIcon (HWND hWnd) |
|
|
|
{ |
|
|
|
|
|
|
|
switch (uMsg) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
case WM_CREATE: |
|
|
|
NOTIFYICONDATA nid; |
|
|
|
{ |
|
|
|
nid.hWnd = hWnd; |
|
|
|
AddTrayIcon (hWnd); |
|
|
|
nid.uID = ID_TRAY_ICON; |
|
|
|
break; |
|
|
|
Shell_NotifyIcon (NIM_DELETE, &nid); |
|
|
|
} |
|
|
|
} |
|
|
|
case WM_CLOSE: |
|
|
|
|
|
|
|
{ |
|
|
|
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
|
|
|
RemoveTrayIcon (hWnd); |
|
|
|
{ |
|
|
|
PostQuitMessage (0); |
|
|
|
switch (uMsg) |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case WM_COMMAND: |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (LOWORD(wParam)) |
|
|
|
case WM_CREATE: |
|
|
|
{ |
|
|
|
{ |
|
|
|
case ID_ABOUT: |
|
|
|
AddTrayIcon (hWnd); |
|
|
|
{ |
|
|
|
break; |
|
|
|
MessageBox( hWnd, TEXT("i2pd"), TEXT("About"), MB_ICONINFORMATION | MB_OK ); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
case WM_CLOSE: |
|
|
|
} |
|
|
|
{ |
|
|
|
case ID_EXIT: |
|
|
|
RemoveTrayIcon (hWnd); |
|
|
|
|
|
|
|
PostQuitMessage (0); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case WM_COMMAND: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (LOWORD(wParam)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PostMessage (hWnd, WM_CLOSE, 0, 0); |
|
|
|
case ID_ABOUT: |
|
|
|
return 0; |
|
|
|
{ |
|
|
|
|
|
|
|
MessageBox( hWnd, TEXT("i2pd"), TEXT("About"), MB_ICONINFORMATION | MB_OK ); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case ID_EXIT: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PostMessage (hWnd, WM_CLOSE, 0, 0); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
case WM_TRAYICON: |
|
|
|
} |
|
|
|
|
|
|
|
case WM_TRAYICON: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SetForegroundWindow (hWnd); |
|
|
|
|
|
|
|
switch (lParam) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
case WM_RBUTTONUP: |
|
|
|
SetForegroundWindow (hWnd); |
|
|
|
|
|
|
|
switch (lParam) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SetForegroundWindow (hWnd); |
|
|
|
case WM_RBUTTONUP: |
|
|
|
ShowPopupMenu(hWnd, NULL, -1); |
|
|
|
{ |
|
|
|
PostMessage (hWnd, WM_APP + 1, 0, 0); |
|
|
|
SetForegroundWindow (hWnd); |
|
|
|
break; |
|
|
|
ShowPopupMenu(hWnd, NULL, -1); |
|
|
|
|
|
|
|
PostMessage (hWnd, WM_APP + 1, 0, 0); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return DefWindowProc( hWnd, uMsg, wParam, lParam); |
|
|
|
} |
|
|
|
} |
|
|
|
return DefWindowProc( hWnd, uMsg, wParam, lParam); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show) |
|
|
|
bool StartWin32App () |
|
|
|
{ |
|
|
|
|
|
|
|
// check if tunning already
|
|
|
|
|
|
|
|
if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"))) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK); |
|
|
|
if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"))) |
|
|
|
return 0; |
|
|
|
{ |
|
|
|
|
|
|
|
MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// register main window
|
|
|
|
|
|
|
|
auto hInst = GetModuleHandle(NULL); |
|
|
|
|
|
|
|
WNDCLASSEX wclx; |
|
|
|
|
|
|
|
memset (&wclx, 0, sizeof(wclx)); |
|
|
|
|
|
|
|
wclx.cbSize = sizeof(wclx); |
|
|
|
|
|
|
|
wclx.style = 0; |
|
|
|
|
|
|
|
wclx.lpfnWndProc = WndProc; |
|
|
|
|
|
|
|
wclx.cbClsExtra = 0; |
|
|
|
|
|
|
|
wclx.cbWndExtra = 0; |
|
|
|
|
|
|
|
wclx.hInstance = hInst; |
|
|
|
|
|
|
|
wclx.hIcon = LoadIcon (hInst, IDI_APPLICATION); |
|
|
|
|
|
|
|
wclx.hIconSm = LoadIcon (hInst, IDI_APPLICATION); |
|
|
|
|
|
|
|
wclx.hCursor = LoadCursor (NULL, IDC_ARROW); |
|
|
|
|
|
|
|
wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); |
|
|
|
|
|
|
|
wclx.lpszMenuName = NULL; |
|
|
|
|
|
|
|
wclx.lpszClassName = I2PD_WIN32_CLASSNAME; |
|
|
|
|
|
|
|
RegisterClassEx (&wclx); |
|
|
|
|
|
|
|
// create new window
|
|
|
|
|
|
|
|
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInst, NULL)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MessageBox(NULL, "Failed to create main window", TEXT("Warning!"), MB_ICONERROR | MB_OK | MB_TOPMOST); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
// register main window
|
|
|
|
|
|
|
|
WNDCLASSEX wclx; |
|
|
|
int RunWin32App () |
|
|
|
memset (&wclx, 0, sizeof(wclx)); |
|
|
|
|
|
|
|
wclx.cbSize = sizeof(wclx); |
|
|
|
|
|
|
|
wclx.style = 0; |
|
|
|
|
|
|
|
wclx.lpfnWndProc = WndProc; |
|
|
|
|
|
|
|
wclx.cbClsExtra = 0; |
|
|
|
|
|
|
|
wclx.cbWndExtra = 0; |
|
|
|
|
|
|
|
wclx.hInstance = hInst; |
|
|
|
|
|
|
|
wclx.hIcon = LoadIcon (hInst, IDI_APPLICATION); |
|
|
|
|
|
|
|
wclx.hIconSm = LoadIcon (hInst, IDI_APPLICATION); |
|
|
|
|
|
|
|
wclx.hCursor = LoadCursor (NULL, IDC_ARROW); |
|
|
|
|
|
|
|
wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); |
|
|
|
|
|
|
|
wclx.lpszMenuName = NULL; |
|
|
|
|
|
|
|
wclx.lpszClassName = I2PD_WIN32_CLASSNAME; |
|
|
|
|
|
|
|
RegisterClassEx (&wclx); |
|
|
|
|
|
|
|
// create new window
|
|
|
|
|
|
|
|
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInst, NULL)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageBox(NULL, "Failed to create main window", TEXT("Warning!"), MB_ICONERROR | MB_OK | MB_TOPMOST); |
|
|
|
MSG msg; |
|
|
|
return 1; |
|
|
|
while (GetMessage (&msg, NULL, 0, 0 )) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
TranslateMessage (&msg); |
|
|
|
|
|
|
|
DispatchMessage (&msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return msg.wParam; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* // init
|
|
|
|
void StopWin32App () |
|
|
|
char * argv[] = { (char *)"i2pd" }; |
|
|
|
|
|
|
|
Daemon.init(sizeof (argv)/sizeof (argv[0]), argv); |
|
|
|
|
|
|
|
// start
|
|
|
|
|
|
|
|
Daemon.start ();*/ |
|
|
|
|
|
|
|
// main loop
|
|
|
|
|
|
|
|
MSG msg; |
|
|
|
|
|
|
|
while (GetMessage (&msg, NULL, 0, 0 )) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
TranslateMessage (&msg); |
|
|
|
UnregisterClass (I2PD_WIN32_CLASSNAME, GetModuleHandle(NULL)); |
|
|
|
DispatchMessage (&msg); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/* // atop
|
|
|
|
} |
|
|
|
Daemon.stop ();*/ |
|
|
|
} |
|
|
|
// terminate
|
|
|
|
|
|
|
|
UnregisterClass (I2PD_WIN32_CLASSNAME, hInst); |
|
|
|
|
|
|
|
return msg.wParam; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|