WinForm各种API---时时更新
-->
本文原文地址:http://www.cnblogs.com/hqxc/p/6160685.html
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB; private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
}
窗体移动API
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex); public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
窗体阴影API
const int WM_NCHITTEST = 0x0084;
const int HT_LEFT = ;
const int HT_RIGHT = ;
const int HT_TOP = ;
const int HT_TOPLEFT = ;
const int HT_TOPRIGHT = ;
const int HT_BOTTOM = ;
const int HT_BOTTOMLEFT = ;
const int HT_BOTTOMRIGHT = ;
const int HT_CAPTION = ;
#region 调大小
protected override void WndProc(ref Message Msg)
{
if (Msg.Msg == WM_NCHITTEST)
{
//获取鼠标位置
int nPosX = (Msg.LParam.ToInt32() & );
int nPosY = (Msg.LParam.ToInt32() >> );
//右下角
if (nPosX >= this.Right - && nPosY >= this.Bottom - )
{
Msg.Result = new IntPtr(HT_BOTTOMRIGHT);
return;
}
//左上角
else if (nPosX <= this.Left + && nPosY <= this.Top + )
{
Msg.Result = new IntPtr(HT_TOPLEFT);
return;
}
//左下角
else if (nPosX <= this.Left + && nPosY >= this.Bottom - )
{
Msg.Result = new IntPtr(HT_BOTTOMLEFT);
return;
}
//右上角
else if (nPosX >= this.Right - && nPosY <= this.Top + )
{
Msg.Result = new IntPtr(HT_TOPRIGHT);
return;
}
else if (nPosX >= this.Right - )
{
Msg.Result = new IntPtr(HT_RIGHT);
return;
}
else if (nPosY >= this.Bottom - )
{
Msg.Result = new IntPtr(HT_BOTTOM);
return;
}
else if (nPosX <= this.Left + )
{
Msg.Result = new IntPtr(HT_LEFT);
return;
}
else if (nPosY <= this.Top + )
{
Msg.Result = new IntPtr(HT_TOP);
return;
}
else
{
Msg.Result = new IntPtr(HT_CAPTION);
return;
}
}
base.WndProc(ref Msg);
}
#endregion
无边框拖动大小API
系统热键API
System.Timers.Timer time = new System.Timers.Timer();
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;//模拟鼠标左键抬起
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
申明API、定义常量
protected override void WndProc(ref Message Msg)
{
const int WM_HOTKEY = 0x0312;//如果m.Msg的值为0x0312那么表示用户按下了热键
switch (Msg.Msg)
{
case WM_HOTKEY:
ProcessHotkey(Msg);//按下热键时调用ProcessHotkey()函数
break;
}
base.WndProc(ref Msg);
}
接收热键函数
int ijk = ;//标记变量无意义
private void ProcessHotkey(Message m) //按下设定的键时调用该函数
{
IntPtr id = m.WParam; //IntPtr用于表示指针或句柄的平台特定类型
//MessageBox.Show(id.ToString());
string sid = id.ToString();
switch (sid)
{
case ""://热键ID
if (ijk == )
{
this.Size = new Size(, );
ijk = ;
}
else
{
this.Size = new Size(, );
ijk = ;
}
break;
}
}
热键调用的函数
RegisterHotKey(this.Handle, 100, 2, Keys.D1);-----注册热键
RegisterHotKey(本窗口句柄, 热键ID, 第一个键, 第二个键);
第一个键:0---null
1---Alt
2---Ctrl
3---Shift
4---Windows
第二个键:Keys.键 Keys可以点出来
PS:热键设为同一个有奇效【手动斜眼】
UnregisterHotKey(this.Handle, 100);-----移除热键
UnregisterHotKey(本窗口句柄, 热键ID);
PS:一定不要忘了移除啊!!!
#region 加密 //加密 public static string Encode(string data, string Key_64, string Iv_64)
{ string KEY_64 = Key_64;// "VavicApp"; string IV_64 = Iv_64;// "VavicApp"; try
{ byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize; MemoryStream ms = new MemoryStream(); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(cst); sw.Write(data); sw.Flush(); cst.FlushFinalBlock(); sw.Flush(); return Convert.ToBase64String(ms.GetBuffer(), , (int)ms.Length); } catch (Exception x)
{ return x.Message; } } #endregion #region 解密 //解密 public static string Decode(string data, string Key_64, string Iv_64)
{ string KEY_64 = Key_64;// "VavicApp";密钥 string IV_64 = Iv_64;// "VavicApp"; 向量 try
{ byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); byte[] byEnc; byEnc = Convert.FromBase64String(data); //把需要解密的字符串转为8位无符号数组 DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); MemoryStream ms = new MemoryStream(byEnc); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read); StreamReader sr = new StreamReader(cst); return sr.ReadToEnd(); } catch (Exception x)
{ return x.Message; } } #endregion
C#简单的加密解密
WinForm各种API---时时更新的更多相关文章
- 解决Android时时更新listview数组越界问题
时时更新数据一般出现在金融.股票行业对数据的准确性要求极高情况下使用. 先来看看下面一段代码, public class MainActivity extends Activity { private ...
- 利用Dnspod api批量更新添加DNS解析【python脚本】 - 推酷
利用Dnspod api批量更新添加DNS解析[python脚本] - 推酷 undefined
- Winform之跨线程更新UI
Winform之跨线程更新UI 使用`Invoke`或者`BeginInvoke`与UI线程交互示例 参考及源码 使用Invoke或者BeginInvoke与UI线程交互示例 private void ...
- Android:OpenFire 相关API (持续更新)
基于XMPP协议的聊天服务器.最近会一直更新相关的API. 需要的软件:OpenFire(服务器),Spark(客户端--测试用),Asmack(Jar包) 1.连接服务器的代码 private vo ...
- Dynamics CRM2016 Web Api之更新时间字段值
前篇我们论述了时间字段的查询,本篇来论述下时间字段的更新. 还是以之前建的当地时间(时间行为为用户当地时间)字段来测试 可以看到web api更新的是数据库的时间,而在前台的反映就是做了加8处理,所以 ...
- Dynamics CRM2016 Web API之更新记录的单个属性字段值
在web api中提供了对单个属性的更新接口,这和查询中查询单个属性类似,对这个接口我个人也是比较喜欢的. var id = "{D1E50347-86EB-E511-9414-ADA183 ...
- Dynamics CRM2016 Web API之更新记录
本篇继续探索web api,介绍如何通过web api更新记录. 下面是一段简单的更新代码,更新了几个不同类型的字段,entity的赋值和前篇创建时候的一样的. var entity = {}; en ...
- Winform实现多线程异步更新UI(进度及状态信息)
引言 在进行Winform程序开发需要进行大量的数据的读写操作的时候,往往会需要一定的时间,然在这个时间段里面,界面ui得不到更新,导致在用户看来界面处于假死的状态,造成了不好的用户体验.所以在大量数 ...
- Winform 打包 混淆 自动更新
路径: 最终的解决方案是,ConfuserEx+Installshield+AutoUpdater.NET,ConfuserEx做代码混淆工作,Installshield可以解决注册表的问题,Auto ...
- REST API (更新文档)
Elasticsearch的更新文档API准许通过脚本操作来更新文档.更新操作从索引中获取文档,执行脚本,然后获得返回结果.它使用版本号来控制文档获取或者重建索引. 我们新建一个文档: 请求:PUT ...
随机推荐
- [LeetCode] Edit Distance 编辑距离
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...
- Asp.net 设置GridView自适应列宽不变形
动态绑定的GridView由于列数不固定,而列又太多,这样设置GridView固定宽度就不能满足需求了.为此整理了两种方法来达到GridView自适应列宽不变形的效果. //在GridView的行数据 ...
- .NET跨平台之旅:将示例站点升级至ASP.NET Core 1.0
北京时间6月28日凌晨,微软发布了 .NET Core 1.0,详见新闻 .NET Core 1.0 正式发布了 ,ASP.NET Core 1.0 也随之一起发布了. 紧跟这次发布,我们将跑在 Li ...
- css的字体
移动端使用的字体:http://www.cnblogs.com/PeunZhang/p/3592096.html
- C#设计模式(3)——工厂方法模式
一.概念:定义一个用于创建对象的接口,让子类决定实例化哪一个类,工厂方法使一个类的实例化延迟到其子类. 二.代码实现 namespace 设计模式之工厂方法模式 { /// <summary&g ...
- oracle db link的查看创建与删除
1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...
- Markdown
1. 斜体和粗体 代码: *斜体*或_斜体_ **粗体** ***加粗斜体*** ~~删除线~~ 显示效果: 这是一段斜体 这是一段粗体 这是一段加粗斜体 这是一段删除线 2. 分级标题 第一种写法: ...
- XMind怎么使用查找功能
XMind思维导图中,XMind搜索功能与XMind查找替换功能乍一看有些相似,然而不尽相同,本文为你着重讲解XMind搜索功能. 首先在XMind思维导图中的工具栏找到"Search&qu ...
- py-faster-rcnn几个辅助脚本
py-faster-rcnn本身代码很棒. 不过使用它的时候,还是需要自己写一些脚本,作为辅助. 1 所有.py文件顶部添加utf8编码声明.因为有时候需要添加中文注释,不声明编码会报错 #inser ...
- django的cookie和session以及内置信号、缓存
cookie和session cookie和session的作用: cookie和session都记录了客户端的某种状态,用来跟踪用户访问网站的整个回话.两者最大的区别是cookie的信息是存放在浏览 ...