winform 关于重写 CreateParams 和WndProc
本帖最后由 jorgenxu 于 2014-03-17 16:25:02 编辑
最近写程序经常遇到需要重写CreateParams 或者WndProc 或者DllImport
(1)比如加边框阴影:
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ClassStyle |= 0x20000;
return createParams;
}
}
(2)再比如使整个窗体都可以拖动:
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override void WndProc(ref Message message)
{
base.WndProc(ref message);
if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
{
message.Result = (IntPtr)HTCAPTION;
}
}
(3)或者是下面这种带DllImport
const int WM_COPYDATA = 0x004A;
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
ref COPYDATASTRUCT lParam // second message parameter
);
遇到这样的问题我都是从网上查的,不知道为什么“createParams.ClassStyle |= 0x20000”这就加上阴影边框了,20000是阴影,其他的哪,比如20001代表什么?这些技术叫什么?不知道有没有详细介绍这些技术的书或文章,麻烦给说下,谢谢!
------解决方案--------------------这是windowsAPI和windows消息,lz深受C#的毒害啊。