WIN MOBILE键盘调用:
///
/// 键盘输入法切换
///
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);
}
}
///
/// Embedded in the SIPINFO class. RECT represents a rectangle.
///
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
private class SIPINFO
{
///
/// Initialize a SIPINFO instance by setting the size.
///
public SIPINFO()
{
cbSize = (uint)Marshal.SizeOf(this);
}
///
/// 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.
///
public uint cbSize;
///
/// 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.
///
public uint fdwFlags;
///
/// 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.
///
public RECT rcVisibleDesktop;
///
/// 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.
///
public RECT rcSipRect;
///
/// Specifies the size of the data pointed to by the pvImData member.
///
public uint dwImDataSize;
///
/// Void pointer to IM-defined data. The IM calls the
/// IInputMethod::GetImData and IInputMethod::SetImData methods to send
/// and receive information from this structure.
///
public IntPtr pvImData;
}
///
/// 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.
///
/// [out] Pointer to the SIPINFO structure that contains
/// information about the current software-based input panel.
///
/// error information, call GetLastError.
[DllImport("coredll.dll")]
private extern static uint SipGetInfo(SIPINFO pSipInfo);
///
/// 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.
///
/// [in] Pointer to the SIPINFO structure that contains
/// information about the current software-based input panel.
///
/// error information, call GetLastError.
[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; //向下时的精度
///
/// 显示在顶部
///
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("系统错误,请稍后重试!");
}
}
///
/// 显示在底部
///
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("系统错误,请稍后重试!");
}
}
///
/// 自动显示
///
/// 窗体高度
/// 当前焦点所在控件Top坐标
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 description for MemoryStatus.
///
public class MemoryStatus
{
///
/// 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;
///
private class MEMORYSTATUS
{
///
/// Initialize an instance of MEMORYSTATUS by setting the
/// size parameter.
///
public MEMORYSTATUS()
{
dwLength = (uint)Marshal.SizeOf(this);
}
///
/// Specifies the size, in bytes, of the MEMORYSTATUS structure. Set
/// this member to sizeof(MEMORYSTATUS) when passing it to the
/// GlobalMemoryStatus function.
///
public uint dwLength;
///
/// 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.
///
public uint dwMemoryLoad;
///
/// Indicates the total number of bytes of physical memory.
///
public uint dwTotalPhys;
///
/// Indicates the number of bytes of physical memory available.
///
public uint dwAvailPhys;
///
/// 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.
///
public uint dwTotalPageFile;
///
/// Indicates the number of bytes available in the paging file.
///
public uint dwAvailPageFile;
///
/// Indicates the total number of bytes that can be described in the user
/// mode portion of the virtual address space of the calling process.
///
public uint dwTotalVirtual;
///
/// Indicates the number of bytes of unreserved and uncommitted memory
/// in the user mode portion of the virtual address space of the calling
/// process.
///
public uint dwAvailVirtual;
}
///
/// This function gets information on the physical and virtual memory of
/// the system.
///
/// [out] Pointer to a MEMORYSTATUS structure. The
/// GlobalMemoryStatus function stores information about current memory
/// availability in this structure.
[DllImport("CoreDll.dll")]
private static extern void GlobalMemoryStatus(MEMORYSTATUS lpBuffer);
///
/// This function retrieves information from the kernel pertaining to object
/// store and system memory.
///
/// Long pointer to the number of pages dedicated
/// to the store.
/// Long pointer to the number of pages dedicated
/// to system memory.
/// Long pointer to the number of bytes in a page.
///
[DllImport("CoreDll.dll")]
private static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);
///
/// 可用内存
///
public static uint AvailSize
{
get
{
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);
return memStatus.dwAvailPhys;
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------
public class MemoryStatus
{
///
/// 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;
///
private class MEMORYSTATUS
{
///
/// Initialize an instance of MEMORYSTATUS by setting the
/// size parameter.
///
public MEMORYSTATUS()
{
dwLength = (uint)Marshal.SizeOf(this);
}
///
/// Specifies the size, in bytes, of the MEMORYSTATUS structure. Set
/// this member to sizeof(MEMORYSTATUS) when passing it to the
/// GlobalMemoryStatus function.
///
public uint dwLength;
///
/// 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.
///
public uint dwMemoryLoad;
///
/// Indicates the total number of bytes of physical memory.
///
public uint dwTotalPhys;
///
/// Indicates the number of bytes of physical memory available.
///
public uint dwAvailPhys;
///
/// 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.
///
public uint dwTotalPageFile;
///
/// Indicates the number of bytes available in the paging file.
///
public uint dwAvailPageFile;
///
/// Indicates the total number of bytes that can be described in the user
/// mode portion of the virtual address space of the calling process.
///
public uint dwTotalVirtual;
///
/// Indicates the number of bytes of unreserved and uncommitted memory
/// in the user mode portion of the virtual address space of the calling
/// process.
///
public uint dwAvailVirtual;
}
///
/// This function gets information on the physical and virtual memory of
/// the system.
///
/// [out] Pointer to a MEMORYSTATUS structure. The
/// GlobalMemoryStatus function stores information about current memory
/// availability in this structure.
[DllImport("CoreDll.dll")]
private static extern void GlobalMemoryStatus(MEMORYSTATUS lpBuffer);
///
/// This function retrieves information from the kernel pertaining to object
/// store and system memory.
///
/// Long pointer to the number of pages dedicated
/// to the store.
/// Long pointer to the number of pages dedicated
/// to system memory.
/// Long pointer to the number of bytes in a page.
///
[DllImport("CoreDll.dll")]
private static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);
///
/// 可用内存
///
public static uint AvailSize
{
get
{
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);
return memStatus.dwAvailPhys;
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------