| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| using System; |
| using System.Drawing; |
| using System.Collections.Generic; |
| using System.IO; |
| using System.Linq; |
| using System.Threading.Tasks; |
| using System.Text; |
| using System.Windows.Forms; |
| using System.Runtime.InteropServices; |
| |
| namespace WinFormsApp |
| { |
| public class Winapi{ |
| public const int WM_DESTROY=0x0002; |
| public const int WM_HOTKEY=0x0312; |
| public const int WM_KEYDOWN=0x0100; |
| public const int WM_KEYUP=0x0101; |
| public const int MOD_NOREPEAT=0x4000; |
| [DllImport("user32.dll",ExactSpelling=true)] |
| [return:MarshalAs(UnmanagedType.Bool)] |
| public static extern bool RegisterHotKey(IntPtr hwnd,int id,uint fsmodifiers,uint vk); |
| [DllImport("user32.dll",ExactSpelling=true)] |
| [return:MarshalAs(UnmanagedType.Bool)] |
| public static extern bool UnregisterHotKey(IntPtr hwnd,int id); |
| [DllImport("user32.dll")] |
| public static extern IntPtr GetForegroundWindow(); |
| [DllImport("user32.dll",ExactSpelling=true)] |
| [return:MarshalAs(UnmanagedType.Bool)] |
| public static extern bool PostMessageA(IntPtr hwnd, uint msg, int wparam, uint iparam); |
| } |
| |
| public partial class Form999:Form{ |
| |
| private List<Label> lstlb; |
| private List<TextBox> lsttb; |
| private List<bool> lsbl; |
| private Button bt1; |
| private Button bt2; |
| private Label lb; |
| private System.ComponentModel.IContainer components = null; |
| |
| protected override void Dispose(bool disposing){ |
| if (disposing && (components != null)){components.Dispose();} |
| base.Dispose(disposing); |
| } |
| |
| public Form999(){Initial();} |
| |
| public void Initial(){ |
| this.lstlb=new List<Label>(10); |
| this.lsttb=new List<TextBox>(10); |
| this.lsbl=new List<bool>(10); |
| for(int t=0x70;t<0x7a;t++){ |
| lsbl.Add(Winapi.RegisterHotKey(this.Handle,t,Winapi.MOD_NOREPEAT,(uint)t)); |
| } |
| this.SuspendLayout(); |
| int i=0; |
| for(int c=0;c<10;c++){ |
| lstlb.Add(new Label()); |
| if((c>4) && (0==i)){i+=1;} |
| lstlb[c].Size=new Size(30,70); |
| lstlb[c].Name="lable"+c; |
| if(c<5){lstlb[c].TextAlign=ContentAlignment.TopRight;} |
| lstlb[c].Text=String.Format("F{0}",c+1); |
| lstlb[c].Location=new Point(16+(8+150+60+30+8)*i,70*(c%5)+8*(c%5+1)); |
| |
| lsttb.Add(new TextBox()); |
| if((c>4) && (0==i)){i+=1;} |
| lsttb[c].Size=new Size(150,70); |
| lsttb[c].Name="textbox"+c; |
| lsttb[c].TabIndex=i; |
| lsttb[c].BorderStyle=BorderStyle.FixedSingle; |
| lsttb[c].Multiline=true; |
| lsttb[c].Location=new Point(16+30+8+(150+60+30+8)*i,70*(c%5)+8*(c%5+1)); |
| if(!lsbl[c]){lsttb[c].Enabled=false;lsttb[c].Text="快捷键注册失败";} |
| } |
| |
| this.bt1=new Button(); |
| this.bt1.Name="button1"; |
| this.bt1.Size=new Size(100,24); |
| this.bt1.Location=new Point(16+30+8+24,480-16-20-32); |
| this.bt1.TabIndex=11; |
| this.bt1.Text="清空框框内容"; |
| this.bt1.UseVisualStyleBackColor=true; |
| this.bt1.Click+=new EventHandler(this.bt1_Click); |
| |
| this.bt2=new Button(); |
| this.bt2.Name="button2"; |
| this.bt2.Size=new Size(100,24); |
| this.bt2.Location=new Point(16+(30+8)*2+150+60+24,480-16-20-32); |
| this.bt2.TabIndex=12; |
| this.bt2.Text="重新加载配置"; |
| this.bt2.UseVisualStyleBackColor=true; |
| this.bt2.Click+=new EventHandler(this.bt2_Click); |
| |
| for(int t=0;t<10;t++){this.lstlb[t].TabIndex=t+13;} |
| |
| this.lb=new Label(); |
| this.lb.Location = new System.Drawing.Point(8, 480-16-8); |
| this.lb.Name = "label"; |
| this.lb.Size = new System.Drawing.Size(480-8-8, 20); |
| this.lb.TabIndex = 23; |
| this.lb.TextAlign=ContentAlignment.TopCenter; |
| this.lb.Text="可将 123456.txt 作为配置文件,文件编码 utf8,一行一个,不想配置的可用空行代替"; |
| |
| this.bt2_Click(null,null); |
| this.ClientSize = new System.Drawing.Size(480, 480); |
| for(int t=0;t<10;t++){ |
| this.Controls.Add(this.lstlb[t]); |
| this.Controls.Add(this.lsttb[t]); |
| } |
| this.Controls.Add(this.bt1); |
| this.Controls.Add(this.bt2); |
| this.Controls.Add(this.lb); |
| this.Name = "Form999"; |
| this.Text = "单功能剪切板"; |
| this.ResumeLayout(false); |
| this.PerformLayout(); |
| } |
| |
| protected override void WndProc(ref Message m) |
| { |
| int value=0;IntPtr ip; |
| switch(m.Msg){ |
| case Winapi.WM_DESTROY: |
| for(int t=0;t<10;t++){ |
| if(this.lsbl[t]){ |
| Winapi.UnregisterHotKey(this.Handle,t+0x70); |
| }} |
| break; |
| case Winapi.WM_HOTKEY: |
| value=(int)m.WParam; |
| if((value>0x69)&&(value<0x7a)&&(!string.IsNullOrEmpty(this.lsttb[value-0x70].Text))){ |
| Clipboard.SetData("UnicodeText",this.lsttb[value-0x70].Text); |
| System.Threading.Thread.Sleep(0); |
| SendKeys.SendWait("^v"); |
| }else{ |
| ip=Winapi.GetForegroundWindow(); |
| if(ip != IntPtr.Zero){ |
| Winapi.PostMessageA(ip,Winapi.WM_KEYDOWN,value,0x40000001); |
| Winapi.PostMessageA(ip,Winapi.WM_KEYUP,value,0xc0000001); |
| }} |
| break; |
| } |
| base.WndProc(ref m); |
| } |
| |
| private void bt1_Click(object sender, EventArgs e){ |
| for(int t=0;t<10;t++){ |
| if(lsbl[t]){this.lsttb[t].Text="";} |
| }} |
| |
| private void bt2_Click(object sender, EventArgs e){ |
| string cfgfile="123456.txt"; |
| string[] str; |
| if(File.Exists(cfgfile)){ |
| str=File.ReadAllLines(cfgfile,Encoding.UTF8); |
| for(int t=0;(t<(str.Length-1))&&(t<10);t++){ |
| if(this.lsbl[t]){this.lsttb[t].Text=str[t];} |
| }}} |
| } |
| |
| static class Program{ |
| [STAThread] |
| static void Main(){ |
| Application.EnableVisualStyles(); |
| Application.SetCompatibleTextRenderingDefault(false); |
| Application.Run(new Form999()); |
| }} |
| |
| }COPY |