задача сделать адекватный вывод меню при нажатии правой кнопкой по иконке в сусменю.
Перепробывал много вариантов и , даже сделал отдельного окно, но обработчик событий не откликается как надо.
1) проходит правая кнопка не всегда, если отлавливать и нажатие и отпускание еще более менее, но не всегда
2) иногда меню просто зависает, и при нажатии в другие области экрана не уходит
3) первый клик вообще не срабатывает
4) иногда вообще открывается непонятно где и зависает
в коде выводится сообщение о реальных пройденных кликах, для понимания сколько кликаешь, а сколько получаешь
CODE:
int eCol_Kib, eX_Kib, eY_Kib; getdisplay(eCol_Kib, eX_Kib, eY_Kib);
int WIN_TRAY;
int imgicon;
int imgiconw;
char NOTIFYICONDATA[488];
char ClassTray[99]; // для окна Треи
win wintemp;
int h=0; // счетчик 1
int hbase=0; // счетчик 2
// Tray
#define WS_VISIBLE2 268435456
#define WS_CHILD 1073741824
#define NIF_SHOWTIP 128
#define NIF_TIP 4
#define NIF_ICON 2
#define NIF_INFO 16
#define NIM_ADD 0
#define NIM_DELETE 2
#define NIF_MESSAGE 1
#define NIM_MODIFY 0x00000001
#define SC_MINIMIZE 61472
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define IMAGE_ICON 1
#define LR_LOADFROMFILE 16
#define IDI_INFORMATION 32516
#define LR_SHARED 0x00008000
#define WS_EX_TOPMOST 0x00000008
external(INT, "RegisterClass", "RegisterClassA", "User32.dll");
external(INT, "UnregisterClass", "UnregisterClassA", "User32.dll");
external(INT, "CreateWindow", "CreateWindowExA", "User32.dll");
external(INT, "Shell_NotifyIcon", "Shell_NotifyIconA", "Shell32.dll");
external(INT, "LoadIcon", "LoadIconA", "User32.dll");
external(INT, "LoadImage", "LoadImageA", "User32.dll");
external(INT, "ShowWindow", "ShowWindow", "User32.dll");
external(INT, "DestroyIcon", "DestroyIcon", "User32.dll");
external(INT, "CreatePopupMenu", "CreatePopupMenu", "User32.dll" );
external(INT, "AppendMenu", "AppendMenuA", "User32.dll" );
external(INT, "TrackPopupMenu", "TrackPopupMenu", "User32.dll" );
external(INT, "DestroyMenu", "DestroyMenu", "User32.dll" );
external(INT, "EndMenu", "EndMenu", "User32.dll" );
external(INT, "SetForegroundWindow", "SetForegroundWindow", "user32.dll");
createdialog(0); showdialog(0,"TEST",600,600,300,300,4,0);
int WinProc=address("WindowProc");
strcpy(#ClassTray[0],"dtry"+format(rand(12312,999999)));
int PWNDCLASS[10];
int CLASS=address(#PWNDCLASS[0]);
initialarray(#PWNDCLASS[0], 0);
writeaddress(WinProc, address(#PWNDCLASS[1]));
writeaddress(address(#ClassTray[0]), address(#PWNDCLASS[9]));
if (RegisterClass(CLASS)==0){ messagebox("ERROR CREATE TRAY. EXIT"); }
WIN_TRAY=CreateWindow(WS_EX_TOPMOST, address(#ClassTray[0]), 0, 0, 0, 0, 0, 0, 0 ,0,0,0); //WIN_MAIN gethwnd(0)
initialarray(#NOTIFYICONDATA[0], 0);
writeaddress(sizearray(NOTIFYICONDATA), address(#NOTIFYICONDATA[0]));
writeaddress(WIN_TRAY, address(#NOTIFYICONDATA[4]));
writeaddress(1025, address(#NOTIFYICONDATA[8])); // идентификатор иконки
writeaddress(WM_CONTEXTMENU, address(#NOTIFYICONDATA[16]));
writeaddress(NIF_ICON | NIF_SHOWTIP | NIF_TIP | NIF_INFO | NIF_MESSAGE, address(#NOTIFYICONDATA[12]));
writeaddress(LoadIcon(0, IDI_INFORMATION), address(#NOTIFYICONDATA[20]));
strcpy(#NOTIFYICONDATA[24], "Hint"); // подсказка при наведении на значок
Shell_NotifyIcon(NIM_ADD, address(#NOTIFYICONDATA[0])); // NIM_MODIFY NIM_ADD
loop()sleep(1);Exit:;
function getmessage(0,WM_CLOSE) {
if (WIN_TRAY!=0) {
UnregisterClass(address(#ClassTray[0]), 0);
Shell_NotifyIcon(NIM_DELETE, address(#NOTIFYICONDATA[0]));
DestroyIcon(imgicon); DestroyIcon(imgiconw);
}
goto global Exit;
}
function getmessage (WM_CONTEXTMENU) {
if(message.wparam==1025) {
//SetForegroundWindow(WIN_TRAY);
//sendmessage(WM_CANCELMODE, 0, 0, formatiw(gethwnd(0)));
//sendmessage(WM_CANCELMODE, 0, 0, formatiw(WIN_TRAY));
//EndMenu();
// if (message.lparam==WM_RBUTTONDOWN) {
if ((message.lparam==WM_RBUTTONUP) || (message.lparam==WM_RBUTTONDOWN)) {
h++; textout(0, 20, 20, "прошло кликов: "+format(h), 1);
DestroyMenu(MENU_TRAY);
EndMenu(); sleep(5);
activate(formatiw(WIN_TRAY));
SetForegroundWindow(WIN_TRAY);
int x,y; getmouse(x,y); if (y<eY_Kib-30) return;
int MENU_TRAY=CreatePopupMenu();
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0, 2, "asd" );
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
wintemp=formatiw(WIN_TRAY);
setwindowparam(wintemp);
int result=TrackPopupMenu(MENU_TRAY, 256, x+4, y-15, 0, formatwi(wintemp), 0 ); // вывести меню
SetForegroundWindow(WIN_TRAY);
if (result==2) { messagebox("asd"); }
}
}
}
int WIN_TRAY;
int imgicon;
int imgiconw;
char NOTIFYICONDATA[488];
char ClassTray[99]; // для окна Треи
win wintemp;
int h=0; // счетчик 1
int hbase=0; // счетчик 2
// Tray
#define WS_VISIBLE2 268435456
#define WS_CHILD 1073741824
#define NIF_SHOWTIP 128
#define NIF_TIP 4
#define NIF_ICON 2
#define NIF_INFO 16
#define NIM_ADD 0
#define NIM_DELETE 2
#define NIF_MESSAGE 1
#define NIM_MODIFY 0x00000001
#define SC_MINIMIZE 61472
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define IMAGE_ICON 1
#define LR_LOADFROMFILE 16
#define IDI_INFORMATION 32516
#define LR_SHARED 0x00008000
#define WS_EX_TOPMOST 0x00000008
external(INT, "RegisterClass", "RegisterClassA", "User32.dll");
external(INT, "UnregisterClass", "UnregisterClassA", "User32.dll");
external(INT, "CreateWindow", "CreateWindowExA", "User32.dll");
external(INT, "Shell_NotifyIcon", "Shell_NotifyIconA", "Shell32.dll");
external(INT, "LoadIcon", "LoadIconA", "User32.dll");
external(INT, "LoadImage", "LoadImageA", "User32.dll");
external(INT, "ShowWindow", "ShowWindow", "User32.dll");
external(INT, "DestroyIcon", "DestroyIcon", "User32.dll");
external(INT, "CreatePopupMenu", "CreatePopupMenu", "User32.dll" );
external(INT, "AppendMenu", "AppendMenuA", "User32.dll" );
external(INT, "TrackPopupMenu", "TrackPopupMenu", "User32.dll" );
external(INT, "DestroyMenu", "DestroyMenu", "User32.dll" );
external(INT, "EndMenu", "EndMenu", "User32.dll" );
external(INT, "SetForegroundWindow", "SetForegroundWindow", "user32.dll");
createdialog(0); showdialog(0,"TEST",600,600,300,300,4,0);
int WinProc=address("WindowProc");
strcpy(#ClassTray[0],"dtry"+format(rand(12312,999999)));
int PWNDCLASS[10];
int CLASS=address(#PWNDCLASS[0]);
initialarray(#PWNDCLASS[0], 0);
writeaddress(WinProc, address(#PWNDCLASS[1]));
writeaddress(address(#ClassTray[0]), address(#PWNDCLASS[9]));
if (RegisterClass(CLASS)==0){ messagebox("ERROR CREATE TRAY. EXIT"); }
WIN_TRAY=CreateWindow(WS_EX_TOPMOST, address(#ClassTray[0]), 0, 0, 0, 0, 0, 0, 0 ,0,0,0); //WIN_MAIN gethwnd(0)
initialarray(#NOTIFYICONDATA[0], 0);
writeaddress(sizearray(NOTIFYICONDATA), address(#NOTIFYICONDATA[0]));
writeaddress(WIN_TRAY, address(#NOTIFYICONDATA[4]));
writeaddress(1025, address(#NOTIFYICONDATA[8])); // идентификатор иконки
writeaddress(WM_CONTEXTMENU, address(#NOTIFYICONDATA[16]));
writeaddress(NIF_ICON | NIF_SHOWTIP | NIF_TIP | NIF_INFO | NIF_MESSAGE, address(#NOTIFYICONDATA[12]));
writeaddress(LoadIcon(0, IDI_INFORMATION), address(#NOTIFYICONDATA[20]));
strcpy(#NOTIFYICONDATA[24], "Hint"); // подсказка при наведении на значок
Shell_NotifyIcon(NIM_ADD, address(#NOTIFYICONDATA[0])); // NIM_MODIFY NIM_ADD
loop()sleep(1);Exit:;
function getmessage(0,WM_CLOSE) {
if (WIN_TRAY!=0) {
UnregisterClass(address(#ClassTray[0]), 0);
Shell_NotifyIcon(NIM_DELETE, address(#NOTIFYICONDATA[0]));
DestroyIcon(imgicon); DestroyIcon(imgiconw);
}
goto global Exit;
}
function getmessage (WM_CONTEXTMENU) {
if(message.wparam==1025) {
//SetForegroundWindow(WIN_TRAY);
//sendmessage(WM_CANCELMODE, 0, 0, formatiw(gethwnd(0)));
//sendmessage(WM_CANCELMODE, 0, 0, formatiw(WIN_TRAY));
//EndMenu();
// if (message.lparam==WM_RBUTTONDOWN) {
if ((message.lparam==WM_RBUTTONUP) || (message.lparam==WM_RBUTTONDOWN)) {
h++; textout(0, 20, 20, "прошло кликов: "+format(h), 1);
DestroyMenu(MENU_TRAY);
EndMenu(); sleep(5);
activate(formatiw(WIN_TRAY));
SetForegroundWindow(WIN_TRAY);
int x,y; getmouse(x,y); if (y<eY_Kib-30) return;
int MENU_TRAY=CreatePopupMenu();
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0, 2, "asd" );
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
AppendMenu(MENU_TRAY, 0x00000001, -1, ">> ");
wintemp=formatiw(WIN_TRAY);
setwindowparam(wintemp);
int result=TrackPopupMenu(MENU_TRAY, 256, x+4, y-15, 0, formatwi(wintemp), 0 ); // вывести меню
SetForegroundWindow(WIN_TRAY);
if (result==2) { messagebox("asd"); }
}
}
}