mirror of
https://github.com/jie65535/CodeMatrix.git
synced 2025-07-31 18:19:13 +08:00
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace CodeMatrix.Utils
|
|
{
|
|
public static class FormHelper
|
|
{
|
|
[DllImport("user32.dll")]
|
|
static extern bool ReleaseCapture();
|
|
|
|
[DllImport("user32.dll")]
|
|
static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
|
|
|
|
const int WM_SYSCOMMAND = 0x0112;
|
|
const int SC_MOVE = 0xF010;
|
|
const int HTCAPTION = 0x0002;
|
|
|
|
public static void OnMouseDown(IntPtr handle)
|
|
{
|
|
ReleaseCapture();
|
|
SendMessage(handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
|
|
}
|
|
|
|
const int CS_DropSHADOW = 0x20000;
|
|
const int GCL_STYLE = -26;
|
|
|
|
static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
|
|
{
|
|
if (IntPtr.Size > 4)
|
|
return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
|
|
else
|
|
return new IntPtr(SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
|
|
}
|
|
|
|
[DllImport("user32.dll", EntryPoint = "SetClassLong")]
|
|
static extern uint SetClassLongPtr32(IntPtr hWnd, int nIndex, uint dwNewLong);
|
|
|
|
[DllImport("user32.dll", EntryPoint = "SetClassLongPtr")]
|
|
static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
|
static IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex)
|
|
{
|
|
if (IntPtr.Size > 4)
|
|
return GetClassLongPtr64(hWnd, nIndex);
|
|
else
|
|
return new IntPtr(GetClassLongPtr32(hWnd, nIndex));
|
|
}
|
|
|
|
[DllImport("user32.dll", EntryPoint = "GetClassLong")]
|
|
static extern uint GetClassLongPtr32(IntPtr hWnd, int nIndex);
|
|
|
|
[DllImport("user32.dll", EntryPoint = "GetClassLongPtr")]
|
|
static extern IntPtr GetClassLongPtr64(IntPtr hWnd, int nIndex);
|
|
|
|
|
|
public static void EnableFromDropShadow(IntPtr handle)
|
|
{
|
|
SetClassLong(handle, GCL_STYLE, (IntPtr)((long)GetClassLongPtr(handle, GCL_STYLE) | CS_DropSHADOW));
|
|
}
|
|
}
|
|
} |