2009年8月25日 星期二

[2009/10/11 更新] [C#] XP Aero Snap RC2




這是最近我自己寫的一個小程式,已經進入RC版,除了原本的拉到上方最大化、拉到左方半視窗與拉到右方半視窗還增加了拉到下方最小化功能,目前已穩定許多,可以正常的使用,還會繼續改善與debug,有空的時候會陸續更新....


// ----------------------------------------------------------------------------------------------------


[DllImport("user32.dll")]


public extern static bool GetCursorPos(out Point p); // 取得滑鼠位置


 // ----------------------------------------------------------------------------------------------------


[StructLayout(LayoutKind.Sequential)]


public struct RECT


{


public int left;


public int top;


public int right;


public int bottom;


}


[DllImport("user32.dll")]


public static extern int GetWindowRect(int hwnd, ref RECT rc); // 取得視窗位置


 // ----------------------------------------------------------------------------------------------------


private const int SW_HIDE = 0;


private const int SW_NORMAL = 1;


private const int SW_MAXIMIZE = 3;


private const int SW_SHOWNOACTIVATE = 4;


private const int SW_SHOW = 5;


private const int SW_MINIMIZE = 6;


private const int SW_RESTORE = 9;


private const int SW_SHOWDEFAULT = 10;


[DllImport("User32.dll")] 


private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow); // 變更視窗的狀態 (ex: 最大化 最小化)


 // ----------------------------------------------------------------------------------------------------


[DllImport("user32.dll", EntryPoint = "GetAsyncKeyState")]


public static extern int GetAsyncKeyState(int vKey);


private const int VK_LBUTTON = 1;


private const int VK_RBUTTON = 2;


private const int VK_MBUTTON = 4;



// ----------------------------------------------------------------------------------------------------


static readonly IntPtr HWND_TOP = new IntPtr(0);


private const int SWP_SHOWWINDOW = 64;


private const int SWP_NOSIZE = 1;


private const int SWP_NOMOVE = 2;


private const int SWP_NOZORDER = 0x4;


private const int SWP_FRAMECHANGED = 0x20;


[DllImport("user32.dll")]


private static extern bool SetWindowPos(int hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); // 改變視窗的位置或大小



// ----------------------------------------------------------------------------------------------------


[DllImport("user32")]


public static extern bool IsZoomed(IntPtr hwnd); // 判斷視窗是否為最大化



// ----------------------------------------------------------------------------------------------------


[DllImport("user32")]


public static extern bool IsIconic(IntPtr hwnd); // 判斷視窗是否為最小化



// ----------------------------------------------------------------------------------------------------


[DllImport("user32.dll")]


private static extern bool UpdateWindow(IntPtr hWnd); // 更新視窗



// ----------------------------------------------------------------------------------------------------


以上是所用到的API (Application Programming Interface) 應用程式介面,一種Windows所提供的系統函數


※ 2009/09/06 目前功能穩定 也許還有些bug出現,使用前必須先裝 .Net framework 3.5版才能執行!


※ 2009/10/11 同上並新增設定保存功能(Win7的使用者也能使用,只要留下"最小化"功能,其它三個功能不勾)


※ Win7 ,Vista 使用者 ,如果將檔案放置C:\Program Files\ 在修改設定值之前必須先以"系統管理員權限執行",否則設定值將無法寫入置硬碟。


執行檔下載


C# XP AeroSnap RC2 版原始碼下載

沒有留言:

張貼留言