Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 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.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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);
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 Location: 北京 Thanks: 18 times Was thanked: 1 time(s) in 1 post(s)
|
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 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);
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 post(s)
|
Is this for the text shown in the menu itself, or the message box text?
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
MessageBox is fine, an error occurs in menu (ShowPopupMenuEx).
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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.
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 post(s)
|
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 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.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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.
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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.exeIt'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.
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
It works perfect, Thx Rob
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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.
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 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
|
1 user thanked Yuichi for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 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);
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 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"?
|
1 user thanked Yuichi for this useful post.
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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.
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Originally Posted by: Rob
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. The AHK menu Edited by user Tuesday, July 12, 2022 4:57:08 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 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?
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,360 Location: Tampa, FL Thanks: 28 times Was thanked: 421 time(s) in 357 post(s)
|
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
|
|
|
|
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close