弹图标栏 v0.2
类似Mac OS上的PopClip以及Windows上的SnipDo(原Pantherbar),弹出图标栏,通过图标替代右键菜单文字显示,鼠标移动到图标显示提示,点击图标执行动作,比如启动指定软件、复制、粘贴、剪切文字、打开链接等等
在2代码中的 imgData 对象中添加和设置需要显示图标的路径、提示、点击功能信息
image 图标路径,默认显示图标大小为22x22,需要在S+目录下新建icons文件夹,路径为 “\icons\name”,比如:path+“\icons\Rename.png”(双反斜杠)
tt 图标提示信息
popup 点击触发功能
需要按照模板,依次将各个Label绑定Click事件,与图标数相同
点击图标、点击空白之处、滚动后关闭图标栏
分别添加3代码、4代码,到 全局动作-鼠标事件-左键单击、全局动作-鼠标事件-鼠标滚轮
更新:
20220807 移除透明背景,修复大图片显示,设置sz变量显示图标大小(默认22,显示为22x22)
不足之处
a 暂时无法识别划词之后,自动弹文字编辑相关功能的图标栏
b 显示图标栏闪的问题暂时无法解决
1
添加到全局动作-启动/退出-启动(开启)
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();
}
2
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 = ["label1", "label2", "label3", "label4", "label5", "label6",];
var labelClick = ["label1_Click", "label2_Click", "label3_Click", "label4_Click", "label5_Click", "label6_Click",];
var labelMouseEnter = ["label1_MouseEnter", "label2_MouseEnter", "label3_MouseEnter", "label4_MouseEnter", "label5_MouseEnter", "label6_MouseEnter",];
var labelMouseLeave = ["label1_MouseLeave", "label2_MouseLeave", "label3_MouseLeave", "label4_MouseLeave", "label5_MouseLeave", "label6_MouseLeave",];
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;
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;
});
}
// 添加绑定图标数相等的点击事件
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);
3
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 {}
}
4
sp.StoreBool('shownS1', false);
sp.WindowFromHandle(sp.GetStoredHandle('formHWDS1')).SendClose();
sp.DeleteStoredHandle('formHWDS1');