StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
liuchina  
#1 Posted : Wednesday, September 25, 2019 6:59:06 PM(UTC)
liuchina

Rank: Member

Reputation:

Groups: Approved
Joined: 9/25/2018(UTC)
Posts: 14
China
Location: 北京

Thanks: 8 times
Hi ROB
Please help me, why can't this code get the value of id?


var popupMenuInfo = new PopupMenuInfo();
popupMenuInfo.Items.Add('Test 1');
popupMenuInfo.Items.Add('Test 2');
popupMenuInfo.Items.Add('-');
popupMenuInfo.Items.Add('Test 3');
popupMenuInfo.Location = new Point(708,428);
popupMenuInfo.Callback = 'PopupMenuCallback';
var res = sp.ShowPopupMenu(popupMenuInfo);


function PopupMenuCallback(id) {
sp.MessageBox(typeof id, 'Selected Menu Item');
return id;
}

var pai= PopupMenuCallback();
sp.Sleep(2500);
sp.MessageBox (typeof pai, 'Selected Menu Item');

Thank you.
Rob  
#2 Posted : Wednesday, September 25, 2019 7:44:45 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
PopupMenuCallback should be defined in your Load Script, so it's globally available, then you check the value and do something.

You can't call PopupMenuCallback as it would be out of the context of the menu popup. The return would be sent immediately upon click (to no receiver), not when you call it. within the PopupMenuCallback, you can use sp.StoreNumber to save the value, then check it from another call...but you'd have to do so after you were sure the menu item was clicked.

But, you might want to look into ShowPopupMenuEx as it doesn't require a callback, the script is right within the definition of the popup menu:

Code:
//For script is running in an action, otherwise use a Point instead of action.End
var popupMenuInfoEx = new PopupMenuInfoEx(action.End);
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Test", `sp.MessageBox("Test", "Test");`));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("-"));
var mnuSubMenu = new PopupMenuItem("Sub Menu");
    mnuSubMenu.SubMenuItems.Add(new PopupMenuItem("Sub Item 1", `sp.MessageBox("Sub Item 1", "Sub Item 1");`));
    var mnuSubSubMenu = new PopupMenuItem("Sub Sub Menu");
        mnuSubSubMenu.SubMenuItems.Add(new PopupMenuItem("Sub Sub Item 1", `sp.MessageBox("Sub Sub Item 1", "Sub Sub Item 1");`));
    mnuSubMenu.SubMenuItems.Add(mnuSubSubMenu);
    mnuSubMenu.SubMenuItems.Add(new PopupMenuItem("Sub Item 2", `sp.MessageBox("Sub Item 2", "Sub Item 2");`));
popupMenuInfoEx.MenuItems.Add(mnuSubMenu);
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Last", `sp.MessageBox("Last", "Last");`));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("-"));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Close Popup", ""));
sp.ShowPopupMenuEx(popupMenuInfoEx);
thanks 1 user thanked Rob for this useful post.
liuchina on 9/25/2019(UTC)
liuchina  
#3 Posted : Thursday, September 26, 2019 3:13:25 AM(UTC)
liuchina

Rank: Member

Reputation:

Groups: Approved
Joined: 9/25/2018(UTC)
Posts: 14
China
Location: 北京

Thanks: 8 times
thank you very much.
Yuichi  
#4 Posted : Friday, September 27, 2019 5:32:01 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
This script is very useful but I have a problem. When I try to run this script, the first character from each field are changed to different sign each time I run it.

Examples
Instead of "Test" I get:
est
"est
(est
rest
*est
and so on...

I did the test: I turned off S + Net, deleted the settings file and let it run with the default settings and still the same.

Is this a "Net Framework" problem?

The program is updated to the latest version.

Test code:
Code:
var popupMenuInfoEx = new PopupMenuInfoEx(action.End);
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Test", `sp.MessageBox("Test", "Test");`));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("-"));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Close Popup", ""));
sp.ShowPopupMenuEx(popupMenuInfoEx);
Rob  
#5 Posted : Friday, September 27, 2019 7:37:58 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
Is this for the text shown in the menu itself, or the message box text?
Yuichi  
#6 Posted : Friday, September 27, 2019 8:26:45 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
MessageBox is fine, an error occurs in menu (ShowPopupMenuEx).
Rob  
#7 Posted : Friday, September 27, 2019 8:43:12 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
What keyboard/language are you using?

Also, have you tried manually retyping my "Test" text, just to ensure it picks up any language/character encoding differences between English and your local text encoding.
Yuichi  
#8 Posted : Friday, September 27, 2019 10:55:55 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
1. I use the keyboard/language "polish (programmer)" (or programist)
2. Yes, I rewrote all strings and still the same (I put them in "..." as well as in '...').

I ran the same script under Win 10 (the problem is in Win7), it showed me Chinese characters in first run and after that when I started it again everything worked fine every time.

Only next week I will be able to test this script on other computers with Win7

Rob  
#9 Posted : Friday, September 27, 2019 11:50:17 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
See if you get any different results from this:

https://www.strokesplus.net/files/StrokesPlus.net_Setup_0.3.4.5.exe
Yuichi  
#10 Posted : Friday, September 27, 2019 12:32:28 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
Thanks for the help, but it didn't work.
By the way, anyone else has a problem with it?
Don't get me wrong, Rob, but I'm trying to understand where the problem lies, whether it's a bug or my computer's fault.
Rob  
#11 Posted : Friday, September 27, 2019 12:39:35 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
Okay, was just curious if specifying the character set on the external declarations would magically resolve it. :)

No I doubt it's a bug on your computer. This particular set of calls use direct Windows API calls and character encoding is tricky (as well as the various unmanaged setup calls).

The second you start trying to deal with strings outside of managed code (.NET) and are not on an English/ANSI system, things get messy very fast..that was one of the big reasons I moved to .NET for this new version.

I'm going to see if there's a way I can do this without having to call TrackPopupMenuEx..or maybe still call that, but have the handle to the menu be a .NET Menu instead of a Windows API created one.
thanks 1 user thanked Rob for this useful post.
Yuichi on 9/27/2019(UTC)
Rob  
#12 Posted : Friday, September 27, 2019 3:25:46 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
OMG...what a pain in the ass! .NET has a MenuItem.MenuID, but it's protected so you can't actually access it in code...so had to write all of this cryptic crap using other WinAPI calls to go through all of the menu items (and nested for submenus..) comparing the IDs directly...anyway... I HOPE this works, lol

https://www.strokesplus.net/files/StrokesPlus.net_Setup_0.3.4.5.exe

It's using a .NET ContextMenu instead of a WinAPI menu..so I'm hoping the text is handled properly now. Note that I haven't updated ShowPopupMenu, only ShowPopupMenuEx for now, to see if this works...if it does I'll update the other function and release an update.
thanks 1 user thanked Rob for this useful post.
Yuichi on 9/27/2019(UTC)
Yuichi  
#13 Posted : Friday, September 27, 2019 3:32:10 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
It works perfect, Thx Rob BigGrin
Rob  
#14 Posted : Friday, September 27, 2019 7:50:13 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
I've release 0.3.4.5. I also realized I could just subclass MenuItem to expose MenuID and get rid of the extra WinAPI calls. Also updated ShowPopupMenu code as well.
Yuichi  
#15 Posted : Saturday, September 28, 2019 4:04:11 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
I made a small script for "PopupMenu" and "PopupMenuInfoEx", when the menu is launched it can't be closed by clicking outside of it,
so now clicking will do it.

Place it in the left mouse button script.

But I have to warn something when "PopupMenu" (not "PopupMenuInfoEx") is closed this way, "PopupMenuCallback" function will be called, with "id" = 0.


Code:
if (!click.Down) { // mouse button up

    // CLOSE POPUP MENU
    if (sp.WindowFromClassOrTitle("#32768", "")) {
        try {
            if (sp.WindowFromPoint(sp.GetCurrentMousePoint(), true).ClassName != "#32768" && sp.WindowFromClassOrTitle("#32768", "").Process.MainModule.ModuleName == "StrokesPlus.net.exe") {
                var wnds = sp.AllWindows();
                for (var i = 0; i < wnds.Length; i++) {
                    try {
                        if (wnds[i].Process.MainModule.ModuleName == "StrokesPlus.net.exe" && wnds[i].ClassName == "#32768") {
                            wnds[i].SendClose();
                        }
                    } catch {}
                }
            }
        } catch {}
    }
}

Edited by user Saturday, September 28, 2019 4:40:53 AM(UTC)  | Reason: it was close all menus

liuchina  
#16 Posted : Saturday, September 28, 2019 8:47:54 PM(UTC)
liuchina

Rank: Member

Reputation:

Groups: Approved
Joined: 9/25/2018(UTC)
Posts: 14
China
Location: 北京

Thanks: 8 times
About popupMenuInfo.
On my computer, I commented sp.MessageBox(''+id, 'Selected Menu Item'), as long as I add any code after popupMenuInfo. sp.MessageBox(''+id, 'Selected Menu Item')It still runs, I don't want it to run after I click on the menu. and if there is no code after popupMenuInfo, it will work properly. Is it my problem?

var popupMenuInfo = new PopupMenuInfo();
popupMenuInfo.Items.Add('Test 1');
popupMenuInfo.Items.Add('Test 2');
popupMenuInfo.Items.Add('-');
popupMenuInfo.Items.Add('Test 3');
popupMenuInfo.Location = new Point(700,450);
popupMenuInfo.Callback = 'PopupMenuCallback';
var res = sp.ShowPopupMenu(popupMenuInfo);

function PopupMenuCallback(id) {

//sp.MessageBox(''+id, 'Selected Menu Item');
}
sp.Sleep(1500);

Yuichi  
#17 Posted : Sunday, September 29, 2019 6:43:20 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
I think there's more than one "PopupMenuCallback" function, you need comment it, maybe is in "Global Actions -> Load/Unload Scripts -> Load Script"?
thanks 1 user thanked Yuichi for this useful post.
liuchina on 9/29/2019(UTC)
Rob  
#18 Posted : Sunday, September 29, 2019 9:37:51 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
Yes, the PopupMenuCallback function should NOT be defined in your action script, or it can create more than one. It can also create it in a different script engine.

The callback function should only be in either your Global > Load/Unload > Load Script or in an external script file via Options > Advanced > External Script.

The Load Script and External Script file are executed in each script engine upon starting S+, reloading, or clicking Apply/OK in the Settings screen; so this will define the PopupMenuCallback function in each script engine and be available for any action script to call.

The function needs to already exist within the script engine before you call ShowPopupMenu.
thanks 1 user thanked Rob for this useful post.
liuchina on 9/29/2019(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.