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 : Thursday, September 26, 2019 12:59:06 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
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 : Thursday, September 26, 2019 1:44:45 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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/26/2019(UTC)
liuchina  
#3 Posted : Thursday, September 26, 2019 9:13:25 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
thank you very much.
Yuichi  
#4 Posted : Friday, September 27, 2019 11:32:01 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 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 1:37:58 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Is this for the text shown in the menu itself, or the message box text?
Yuichi  
#6 Posted : Friday, September 27, 2019 2:26:45 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 post(s)
MessageBox is fine, an error occurs in menu (ShowPopupMenuEx).
Rob  
#7 Posted : Friday, September 27, 2019 2:43:12 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 4:55:55 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 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 5:50:17 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 6:32:28 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 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 6:39:35 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 9:25:46 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 9:32:10 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 post(s)
It works perfect, Thx Rob BigGrin
Rob  
#14 Posted : Saturday, September 28, 2019 1:50:13 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 10:04:11 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 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 10:40:53 AM(UTC)  | Reason: it was close all menus

thanks 1 user thanked Yuichi for this useful post.
soooulp on 7/11/2022(UTC)
liuchina  
#16 Posted : Sunday, September 29, 2019 2:47:54 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
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 12:43:20 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

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

Thanks: 18 times
Was thanked: 18 time(s) in 13 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/30/2019(UTC)
Rob  
#18 Posted : Sunday, September 29, 2019 3:37:51 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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/30/2019(UTC)
soooulp  
#19 Posted : Monday, July 11, 2022 4:03:33 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post


The function needs to already exist within the script engine before you call ShowPopupMenu.


Thanks to Yuichi's left-click code to close the menu.

There is a small but unnecessary ask for the UI of the PopupMenuInfoEx.

Could the style of the mouse hover color of the menu change to the default style which is white of Win10(pic 1),
as well as the style of the white background color and the gray mouse hover color in the Chrome context menu(pic 2)?

The current style of the mouse hover color is blue the same as the S+ program context menu, but I prefer the Win10 default style or Chrome context menu style.

Hmmm, so is it easy to deal with it?

I tried the Autohotkey script instead, and the interface is nice, but the launch is terrible by the shortcuts, in my opinion, which is the main reason that not better than S+.

Oops, I find that the notepad context menu is the same as the S+.

And another problem is after clicking the popupmenu that the selected file on the desktop seems will lose focus but on explorer is normal.

UserPostedImage

UserPostedImage

The AHK menu
UserPostedImage

Edited by user Tuesday, July 12, 2022 4:57:08 PM(UTC)  | Reason: Not specified

Rob  
#20 Posted : Wednesday, July 13, 2022 2:22:26 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
It's just a standard .NET WinForms menu, so it is what it is for now in terms of look/colors.

Regarding the select file losing focus, can you give me an example of what you're trying to do?
soooulp  
#21 Posted : Wednesday, July 13, 2022 5:30:10 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Lose focus of the selected file when I click the menu like to rename the file on the desktop to the clipboard current text

but it is normal on the explorer

I just find it is easy that activate the desktop window before the action

sp.DesktopWindow().Activate()



hmmm, does it mean that I need to try to make a plugin for the new interface of PopupMenuInfoEx I want?

As I tried the script directly by WinForms and it seems not easy to change the mouse hover color even the shadow, Aha

Edited by user Wednesday, July 13, 2022 6:00:51 PM(UTC)  | Reason: Not specified

Rob  
#22 Posted : Wednesday, July 13, 2022 7:28:14 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
You would probably have to make a library using UWP/WinUI to get the modern menu - though invoking it from .NET Framework may require some extra steps or a wrapper library.

https://docs.microsoft.com/en-us/windows/apps/design/controls/menus-and-context-menus
soooulp  
#23 Posted : Thursday, July 14, 2022 12:04:03 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Thank you, Rob
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.