WIN MOBILE键盘调用:
/// <summary>
/// 键盘输入法切换
/// </summary>
class InputpanelOfMine
{
[DllImport("coredll.dll", EntryPoint = "SipShowIM")]
private static extern bool SipShowIM(IntPtr SIP_STATUS);
private static readonly IntPtr SIPF_OFF = (IntPtr)0x0;
private static readonly IntPtr SIPF_ON = (IntPtr)0x1;
public static void ShowIPS()
{
try
{
SipShowIM(SIPF_ON);
SipShowIM(SIPF_ON);
}
catch (Exception ept)
{
MessageBox.Show("切换输入法出错:"+ept.Message, "出错信息", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
}
}
/// <summary>
/// Embedded in the SIPINFO class. RECT represents a rectangle.
/// </summary>
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
private class SIPINFO
{
/// <summary>
/// Initialize a SIPINFO instance by setting the size.
/// </summary>
public SIPINFO()
{
cbSize = (uint)Marshal.SizeOf(this);
}
/// <summary>
/// Size, in bytes, of the SIPINFO structure. This member must be filled
/// in by the application with the size of operator. Because the system
/// can check the size of the structure to determine the operating system
/// version number, this member allows for future enhancements to the
/// SIPINFO structure while maintaining backward compatibility.
/// </summary>
public uint cbSize;
/// <summary>
/// Specifies flags representing state information of the software-based
/// input panel. It is any combination of the following bit flags:
/// SIPF_DOCKED, SIPF_LOCKED, SIPF_OFF, and SIPF_ON.
/// </summary>
public uint fdwFlags;
/// <summary>
/// Rectangle, in screen coordinates, that represents the area of the
/// desktop not obscured by the software-based input panel. If the software-
/// based input panel is floating, this rectangle is equivalent to the
/// working area. Full-screen applications that respond to software-based
/// input panel size changes can set their window rectangle to this rectangle.
/// If the software-based input panel is docked but does not occupy an entire
/// edge, then this rectangle represents the largest rectangle not obscured by
/// the software-based input panel. If an application wants to use the screen
/// space around the software-based input panel, it needs to reference
/// rcSipRect.
/// </summary>
public RECT rcVisibleDesktop;
/// <summary>
/// Rectangle, in screen coordinates of the window rectangle and not the
/// client area, the represents the size and location of the software-based
/// input panel. An application does not generally use this information unless
/// it needs to wrap around a floating or a docked software-based input panel
/// that does not occupy an entire edge.
/// </summary>
public RECT rcSipRect;
/// <summary>
/// Specifies the size of the data pointed to by the pvImData member.
/// </summary>
public uint dwImDataSize;
/// <summary>
/// Void pointer to IM-defined data. The IM calls the
/// IInputMethod::GetImData and IInputMethod::SetImData methods to send
/// and receive information from this structure.
/// </summary>
public IntPtr pvImData;
}
/// <summary>
/// This function receives information including the state of the software-
/// based input panel, the area of the desktop that is not obscured by the
/// software-based input panel, the screen coordinates of the software-based
/// input panel, and information about the input method (IM) that the
/// software-based input panel is currently using.
/// </summary>
/// <param name="pSipInfo">[out] Pointer to the SIPINFO structure that contains
/// information about the current software-based input panel.</param>
/// <returns>TRUE indicates success. FALSE indicates failure. To get extended
/// error information, call GetLastError.</returns>
[DllImport("coredll.dll")]
private extern static uint SipGetInfo(SIPINFO pSipInfo);
/// <summary>
/// This function sets information including the state of the software-based
/// input panel, the area of the desktop that is not obscured by the software-
/// based input panel, the screen coordinates of the software-based input
/// panel, and application-defined information about the input method (IM)
/// that the software-based input panel is currently using.
/// </summary>
/// <param name="pSipInfo">[in] Pointer to the SIPINFO structure that contains
/// information about the current software-based input panel.</param>
/// <returns>TRUE indicates success. FALSE indicates failure. To get extended
/// error information, call GetLastError.</returns>
[DllImport("coredll.dll")]
private extern static uint SipSetInfo(SIPINFO pSipInfo);
public static int GetTop()
{
SIPINFO sipInfo = new SIPINFO();
if (SipGetInfo(sipInfo) != 0)
{
return sipInfo.rcSipRect.top;
}
else
{
return -1;
}
}
private static int top = 0; //默认顶部坐标
private static bool isTop = false; //是否在顶部
private static int up_height = 60; //向上时的精度
private static int down_height = 20; //向下时的精度
/// <summary>
/// 显示在顶部
/// </summary>
public static void MoveTop()
{
SIPINFO sipInfo = new SIPINFO();
if (SipGetInfo(sipInfo) != 0) //未出现错误
{
int curTop = sipInfo.rcSipRect.top;
if (curTop != top) //不在顶部时
{
sipInfo.rcSipRect.top = top;
}
SipSetInfo(sipInfo);
}
else
{
throw new Exception("系统错误,请稍后重试!");
}
}
/// <summary>
/// 显示在底部
/// </summary>
public static void MoveBottom(int height)
{
SIPINFO sipInfo = new SIPINFO();
if (SipGetInfo(sipInfo) != 0) //未出现错误
{
int curTop = sipInfo.rcSipRect.top;
int curBottom = sipInfo.rcSipRect.bottom;
if (curTop == top) //输入板在顶部时
{
sipInfo.rcSipRect.top = height - (curBottom - curTop);
}
SipSetInfo(sipInfo);
}
else
{
throw new Exception("系统错误,请稍后重试!");
}
}
/// <summary>
/// 自动显示
/// </summary>
/// <param name="height">窗体高度</param>
/// <param name="controlTop">当前焦点所在控件Top坐标</param>
public static void AutoMove(int height, int controlTop)
{
SIPINFO sipInfo = new SIPINFO();
if (SipGetInfo(sipInfo) != 0) //未出现错误
{
int curTop = sipInfo.rcSipRect.top; //当前输入板Top坐标
int curBottom = sipInfo.rcSipRect.bottom; //当前输入板Bottom坐标
if (!isTop) //在底部时
{
if (curTop < controlTop + up_height)
{
sipInfo.rcSipRect.top = top;
isTop = !isTop;
}
else
sipInfo.rcSipRect.top = height - (curBottom - curTop);
}
else //在顶部时
{
if (curBottom > controlTop - down_height)
{
sipInfo.rcSipRect.top = height - (curBottom - curTop);
isTop = !isTop;
}
else
sipInfo.rcSipRect.top = top;
}
SipSetInfo(sipInfo);
}
else
throw new Exception("系统错误,请稍后重试!");
}
}
/// <summary>
/// Summary description for MemoryStatus.
/// </summary>
public class MemoryStatus
{
/// <summary>
/// This structure contains information about current memory availability.
/// The GlobalMemoryStatus function uses this structure.
/// typedef struct _MEMORYSTATUS
/// {
/// DWORD dwLength;
/// DWORD dwMemoryLoad;
/// DWORD dwTotalPhys;
/// DWORD dwAvailPhys;
/// DWORD dwTotalPageFile;
/// DWORD dwAvailPageFile;
/// DWORD dwTotalVirtual;
/// DWORD dwAvailVirtual;
/// } MEMORYSTATUS, *LPMEMORYSTATUS;
/// </summary>
private class MEMORYSTATUS
{
/// <summary>
/// Initialize an instance of MEMORYSTATUS by setting the
/// size parameter.
/// </summary>
public MEMORYSTATUS()
{
dwLength = (uint)Marshal.SizeOf(this);
}
/// <summary>
/// Specifies the size, in bytes, of the MEMORYSTATUS structure. Set
/// this member to sizeof(MEMORYSTATUS) when passing it to the
/// GlobalMemoryStatus function.
/// </summary>
public uint dwLength;
/// <summary>
/// Specifies a number between 0 and 100 that gives a general idea of
/// current memory utilization, in which 0 indicates no memory use and
/// 100 indicates full memory use.
/// </summary>
public uint dwMemoryLoad;
/// <summary>
/// Indicates the total number of bytes of physical memory.
/// </summary>
public uint dwTotalPhys;
/// <summary>
/// Indicates the number of bytes of physical memory available.
/// </summary>
public uint dwAvailPhys;
/// <summary>
/// Indicates the total number of bytes that can be stored in the
/// paging file. Note that this number does not represent the actual
/// physical size of the paging file on disk.
/// </summary>
public uint dwTotalPageFile;
/// <summary>
/// Indicates the number of bytes available in the paging file.
/// </summary>
public uint dwAvailPageFile;
/// <summary>
/// Indicates the total number of bytes that can be described in the user
/// mode portion of the virtual address space of the calling process.
/// </summary>
public uint dwTotalVirtual;
/// <summary>
/// Indicates the number of bytes of unreserved and uncommitted memory
/// in the user mode portion of the virtual address space of the calling
/// process.
/// </summary>
public uint dwAvailVirtual;
}
/// <summary>
/// This function gets information on the physical and virtual memory of
/// the system.
/// </summary>
/// <param name="lpBuffer">[out] Pointer to a MEMORYSTATUS structure. The
/// GlobalMemoryStatus function stores information about current memory
/// availability in this structure.</param>
[DllImport("CoreDll.dll")]
private static extern void GlobalMemoryStatus(MEMORYSTATUS lpBuffer);
/// <summary>
/// This function retrieves information from the kernel pertaining to object
/// store and system memory.
/// </summary>
/// <param name="lpdwStorePages">Long pointer to the number of pages dedicated
/// to the store.</param>
/// <param name="lpdwRamPages">Long pointer to the number of pages dedicated
/// to system memory.</param>
/// <param name="lpdwPageSize">Long pointer to the number of bytes in a page.</param>
/// <returns>TRUE indicates success; FALSE indicates failure.</returns>
[DllImport("CoreDll.dll")]
private static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);
/// <summary>
/// 可用内存
/// </summary>
public static uint AvailSize
{
get
{
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);
return memStatus.dwAvailPhys;
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------
public class MemoryStatus
{
/// <summary>
/// This structure contains information about current memory availability.
/// The GlobalMemoryStatus function uses this structure.
/// typedef struct _MEMORYSTATUS
/// {
/// DWORD dwLength;
/// DWORD dwMemoryLoad;
/// DWORD dwTotalPhys;
/// DWORD dwAvailPhys;
/// DWORD dwTotalPageFile;
/// DWORD dwAvailPageFile;
/// DWORD dwTotalVirtual;
/// DWORD dwAvailVirtual;
/// } MEMORYSTATUS, *LPMEMORYSTATUS;
/// </summary>
private class MEMORYSTATUS
{
/// <summary>
/// Initialize an instance of MEMORYSTATUS by setting the
/// size parameter.
/// </summary>
public MEMORYSTATUS()
{
dwLength = (uint)Marshal.SizeOf(this);
}
/// <summary>
/// Specifies the size, in bytes, of the MEMORYSTATUS structure. Set
/// this member to sizeof(MEMORYSTATUS) when passing it to the
/// GlobalMemoryStatus function.
/// </summary>
public uint dwLength;
/// <summary>
/// Specifies a number between 0 and 100 that gives a general idea of
/// current memory utilization, in which 0 indicates no memory use and
/// 100 indicates full memory use.
/// </summary>
public uint dwMemoryLoad;
/// <summary>
/// Indicates the total number of bytes of physical memory.
/// </summary>
public uint dwTotalPhys;
/// <summary>
/// Indicates the number of bytes of physical memory available.
/// </summary>
public uint dwAvailPhys;
/// <summary>
/// Indicates the total number of bytes that can be stored in the
/// paging file. Note that this number does not represent the actual
/// physical size of the paging file on disk.
/// </summary>
public uint dwTotalPageFile;
/// <summary>
/// Indicates the number of bytes available in the paging file.
/// </summary>
public uint dwAvailPageFile;
/// <summary>
/// Indicates the total number of bytes that can be described in the user
/// mode portion of the virtual address space of the calling process.
/// </summary>
public uint dwTotalVirtual;
/// <summary>
/// Indicates the number of bytes of unreserved and uncommitted memory
/// in the user mode portion of the virtual address space of the calling
/// process.
/// </summary>
public uint dwAvailVirtual;
}
/// <summary>
/// This function gets information on the physical and virtual memory of
/// the system.
/// </summary>
/// <param name="lpBuffer">[out] Pointer to a MEMORYSTATUS structure. The
/// GlobalMemoryStatus function stores information about current memory
/// availability in this structure.</param>
[DllImport("CoreDll.dll")]
private static extern void GlobalMemoryStatus(MEMORYSTATUS lpBuffer);
/// <summary>
/// This function retrieves information from the kernel pertaining to object
/// store and system memory.
/// </summary>
/// <param name="lpdwStorePages">Long pointer to the number of pages dedicated
/// to the store.</param>
/// <param name="lpdwRamPages">Long pointer to the number of pages dedicated
/// to system memory.</param>
/// <param name="lpdwPageSize">Long pointer to the number of bytes in a page.</param>
/// <returns>TRUE indicates success; FALSE indicates failure.</returns>
[DllImport("CoreDll.dll")]
private static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);
/// <summary>
/// 可用内存
/// </summary>
public static uint AvailSize
{
get
{
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);
return memStatus.dwAvailPhys;
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------