Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 160  Thanks: 46 times Was thanked: 22 time(s) in 17 post(s)
|
It will popup an icons bar with defined functions near the cursor even if you select words, and it can do anything when clicking one icon, the basic actions like launch a program, or handle select text like Copy, Paste, Cut, open a link, search on the browser, translate, or control the media, deal with the files, etc. It is just a Demo that I haven't designed many icons with actions to show, if you need any actions, add or modify the info in the Object. First, Such as I add 6 icons info in the imgData Object to show on the Winform bar as well as a set of 6 variables in the varLabel Array. image is the icon shown on the bar, please create a folder named icons in your S+ path, and add entire image name with the folder as "\\icons\\name"(eg, path+"\\icons\\Rename.png"). tt is the tooltip that shows when the mouse hovers each icon, which use to exhibit the description. popup is the script to do the action. Note: 1 It's better if the background of the image is transparent, and I suggest the format of the image like PNG, BMP, etc. 2 The size of the original image suggests 16x16(Need to resize the Label on the Winform) or 22x22(Default) Second, after editing the icons info into the imgData Object, then adding the icons Click Event with the template with the equal number of icons. The icons bar will show by a Gesture or a Hotkey, and it can close by clicking the blank area or scrolling, putting the third and fourth part code into the Left Click script, and Scroll script. Two years ago I posted Whether can S+net popup an icon bar, in which I mentioned the PopClip program on MAC OS that with more than 100 actions inside, and I still think the icons bar is as necessary as the context menu which may show too wider with long text, another reason is that there are many plugins or javascript codes that are efficient, and frequently used in the Browser for searching the selected words. The insufficient is that the icons bar with edit actions launched by the gesture instead auto recognizes the selected words. From now on, getting the selected words directly without Copy still seems impossible from different Windows. I may add transparency backcolor to the form and as an option or with others like transplant and color if someone needs it.  Put the first code into Global Actions-Load/Unload Code:if(!NativeModules.User32)
{
var IntPtrT = host.typeOf(clr.System.IntPtr);
var Int32T = host.typeOf(clr.System.Int32);
var BooleanT = host.typeOf(clr.System.Boolean);
var user32TB = sp.NativeModule().DefineType("User32", "Class,Public,SequentialLayout,Serializable");
user32TB.DefinePInvokeMethod("ShowWindow",
"user32.dll",
[IntPtrT,Int32T],
BooleanT,
"PreserveSig");
user32TB.DefinePInvokeMethod("SetWindowPos",
"user32.dll",
[IntPtrT,Int32T,Int32T,Int32T,Int32T,Int32T,Int32T],
BooleanT,
"PreserveSig");
user32TB.Create();
}
Update: 20220812 Re-define the varLabel labelClick labelMouseEnter labelMouseLeave array 20220807 Update large picture to show in the icons bar 20220806 Set a variable sz that the size of each icon, default 22(shows 22x22)
Code:var currentMouseLocation = sp.GetCurrentMousePoint();
var mouseWnd = sp.WindowFromPoint(currentMouseLocation, true);
var wndHandle = mouseWnd.HWnd;
var desktopHandle = sp.DesktopWindowListView().HWnd;
var isDesktop = false;
var sz = 22; // The size of the icons to show, default 22x22
if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32() ||
mouseWnd.ClassName == 'WorkerW' || mouseWnd.ClassName == 'Progman') {
//Desktop
isDesktop = true;
}
if (sp.WindowFromHandle(sp.GetStoredHandle('formHWDS1'))) {
try {
sp.WindowFromHandle(sp.GetStoredHandle('formHWDS1')).SendClose();
} catch {}
}
var varLabel = [];
var labelClick = [];
var labelMouseEnter = [];
var labelMouseLeave = [];
var imgData = {
lb1: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\ag99y-oigie-001.ico",
tt: "Hello",
popup: function () {
//sp.ConsoleLog('1');
sp.SendVKey(vk.F2);
},
},
lb2: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\image-2022-07-29 203832.png",
tt: "Yes",
popup: function () {
sp.ConsoleLog('2');
},
},
lb3: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\ag99y-oigie-001.ico",
tt: "OK",
popup: function () {
sp.ConsoleLog('3');
},
},
lb4: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\ag99y-oigie-001.ico",
tt: "AHA",
popup: function () {
sp.ConsoleLog('4');
},
},
lb5: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\ag99y-oigie-001.ico",
tt: "Opss",
popup: function () {
sp.ConsoleLog('5');
},
},
lb6: {
image: clr.System.IO.Path.GetDirectoryName(clr.System.Reflection.Assembly.GetEntryAssembly().Location) + "\\icons\\ag99y-oigie-001.ico",
tt: "Hmmm",
popup: function () {
sp.ConsoleLog('6');
},
},
}
var Forms = forms.System.Windows.Forms;
var form = new Forms.Form;
form.StartPosition = Forms.FormStartPosition.Manual;
form.FormBorderStyle = Forms.FormBorderStyle.None;
form.TopMost = true;
form.ControlBox = false;
form.ShowInTaskbar = false;
form.Margin = new Forms.Padding(0);
//form.Padding = new Forms.Padding(1);
form.MinimumSize = new Size(1, 1);
form.Size = new Size(150, sz);
form.Location = new Point(currentMouseLocation.X + 5, currentMouseLocation.Y + 25);
form.AutoSize = true;
form.GetType().GetProperty("DoubleBuffered",
host.flags(clr.System.Reflection.BindingFlags.NonPublic,
clr.System.Reflection.BindingFlags.Instance))
.SetValue(form, true);
form.BackColor = Color.WhiteSmoke;
//form.TransparencyKey = Color.WhiteSmoke;
form.Opacity = 0.9;
var toolTip = new Forms.ToolTip;
var orign = 0;
varLabel.length = Object.keys(imgData).length;
labelClick.length = labelMouseEnter.length = labelMouseLeave.length = varLabel.length
for(var i = 0; i < varLabel.length; i++) {
orign = i*sz;
varLabel[i] = new Forms.Label;
varLabel[i].Text = "";
//varLabel[i].Image = new clr.System.Drawing.Bitmap(System.Drawing.Image.FromFile(imgData[Object.keys(imgData)[i]].image));
varLabel[i].BackgroundImage = new clr.System.Drawing.Bitmap(System.Drawing.Image.FromFile(imgData[Object.keys(imgData)[i]].image));
varLabel[i].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
varLabel[i].Location = new Point(orign, 0);
varLabel[i].Height = sz;
varLabel[i].Width = sz;
form.Controls.Add(varLabel[i]);
toolTip.SetToolTip(varLabel[i], imgData[Object.keys(imgData)[i]].tt);
labelMouseEnter[i] =
varLabel[i].MouseEnter.connect(
function (sender, e) {
toolTip.ShowAlways = true;
});
labelMouseLeave[i] =
varLabel[i].MouseLeave.connect(
function (sender, e) {
toolTip.ShowAlways = false;
});
}
// Add Click Event to each Label,
// the equal number of the icons you need
labelClick[0] =
varLabel[0].Click.connect(
function (sender, e) {
sp.StoreBool('shownS1', false);
sp.DeleteStoredHandle('formHWDS1');
form.Close();
if(isDesktop) {
isDesktop = false;
sp.WindowFromHandle(sp.DesktopWindowListView().HWnd).Activate();
}
var pp = new imgData[Object.keys(imgData)[0]].popup;
});
labelClick[1] =
varLabel[1].Click.connect(
function (sender, e) {
sp.StoreBool('shownS1', false);
sp.DeleteStoredHandle('formHWDS1');
form.Close();
if(isDesktop) {
isDesktop = false;
sp.WindowFromHandle(sp.DesktopWindowListView().HWnd).Activate();
}
var pp = new imgData[Object.keys(imgData)[1]].popup;
});
var form_shown =
form.Shown.connect(
function (sender, args) {
var HWND_TOPMOST = -1;
var SWP_NOACTIVATE = 0x0010;
var SW_SHOWNOACTIVATE = 4;
NativeModules.User32.ShowWindow(form.Handle, SW_SHOWNOACTIVATE);
NativeModules.User32.SetWindowPos(form.Handle, HWND_TOPMOST,form.Left, form.Top, form.Width, form.Height,SWP_NOACTIVATE);
form.TopMost = false;
sp.StoreBool('shownS1', true);
sp.StoreHandle('formHWDS1', form.Handle);
});
Forms.Application.Run(form);
Put into Left Click script to close the icons bar Code: if(sp.GetStoredBool('shownS1')) {
try {
if (sp.WindowFromPoint(sp.GetCurrentMousePoint(), true).ClassName != "WindowsForms10.Window.8.app.0.13965fa_r6_ad1" &&
sp.WindowFromClassOrTitle("WindowsForms10.Window.8.app.0.13965fa_r6_ad1", "").Process.MainModule.ModuleName == "StrokesPlus.net.exe") {
sp.StoreBool('shownS1', false);
sp.WindowFromHandle(sp.GetStoredHandle('formHWDS1')).SendClose();
sp.DeleteStoredHandle('formHWDS1');
}
} catch {}
}
Scroll script Code: sp.StoreBool('shownS1', false);
sp.WindowFromHandle(sp.GetStoredHandle('formHWDS1')).SendClose();
sp.DeleteStoredHandle('formHWDS1');
Edited by user Friday, August 12, 2022 2:28:29 PM(UTC)
| Reason: Not specified
|