using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Corp3s.NativeAPI
{    
    #if !DESIGN

    public class NTAPI : IWinAPI
    {
        #region IWinAPI Members

        public int GetWindowLong(IntPtr hWnd, int nIndex)
        {
            try
            {
                return GetWindowLongA(hWnd, nIndex);
            }
            catch { return 0; }
        }

        public int SetWindowLong(IntPtr hWnd, int nIndex, WndProcDelegate newProc)
        {
            try
            {
                return SetWindowLongA(hWnd, nIndex, newProc);
            }
            catch { return 0; }
        }

        public int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr newProc)
        {
            try
            {
                return SetWindowLongA(hWnd, nIndex, newProc);
            }
            catch { return 0; }
        }

        public int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                return CallWindowProcA(lpPrevWndFunc, hWnd, msg, wParam, lParam);
            }
            catch { return 0; }
        }

        public IntPtr GetWindow(IntPtr hWnd, uint uCmd)
        {
            try
            {
                return GetWindowA(hWnd, uCmd);
            }
            catch { return IntPtr.Zero; }
        }

        public IntPtr GetCapture()
        {
            try
            {
                return GetCaptureA();
            }
            catch { return IntPtr.Zero; }
        }

        public int SetWindowLong(IntPtr hWnd, int index, int dwNewLong)
        {
            try
            {
                return SetWindowLongA(hWnd, index, dwNewLong);
            }
            catch { return 0; }
        }

        public bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags)
        {
            try
            {
                return SetWindowPosA(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
            }
            catch { return false; }
        }

        #endregion

        [DllImport("user32.dll", EntryPoint = "GetWindowLong")]//, SetLastError = true)]
        public static extern int GetWindowLongA(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll", EntryPoint = "SetWindowLong")]//, SetLastError = true)]
        public static extern int SetWindowLongA(IntPtr hWnd, int nIndex, WndProcDelegate newProc);

        [DllImport("user32.dll", EntryPoint = "SetWindowLong")]//, SetLastError = true)]
        public static extern int SetWindowLongA(IntPtr hWnd, int nIndex, IntPtr newProc);        

        [DllImport("user32.dll", EntryPoint = "SetWindowLong")]//, SetLastError = true)]
        private static extern int SetWindowLongA(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]//, SetLastError = true)]
        private static extern bool SetWindowPosA(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

        [DllImport("user32.dll", EntryPoint = "CallWindowProc")]//, SetLastError = true)]
        public static extern int CallWindowProcA(IntPtr lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", EntryPoint = "GetWindow")]//, SetLastError = true)]
        public static extern IntPtr GetWindowA(IntPtr hWnd, uint uCmd);

        [DllImport("user32.dll", EntryPoint = "GetCapture")]
        private static extern IntPtr GetCaptureA();
    }
    #endif

}
