如何获得web窗体的handle属性值??高分求
IntPtr m_hIMC = WR_Imm32.ImmGetContext(Handle);
这个在winfrom中执行时没有问题的;不过,放到web中,就会报错
C:\Inetpub\wwwroot\trys\WebForm1.aspx.cs(123): 名 'Handle' 在'trys.WebForm1' 不存在。
那么 怎样在web窗体获得'Handle' 呢?
具体代码如下:
private string GetReverseConversion(string AText)
{
if (AText == "")
return "";
IntPtr m_hKL = WR_Imm32.GetKeyboardLayout(0);
IntPtr m_hIMC = WR_Imm32.ImmGetContext(Handle);
WR_Imm32.CANDIDATELIST m_list = new WR_Imm32.CANDIDATELIST();
int dwSize = WR_Imm32.ImmGetConversionList(m_hKL, m_hIMC, AText, IntPtr.Zero, 0, (int)WR_Imm32.GCL.REVERSE_LENGTH);
IntPtr BufList = Marshal.AllocHGlobal(dwSize);
WR_Imm32.ImmGetConversionList(m_hKL, m_hIMC, AText, BufList, dwSize, (int)WR_Imm32.GCL.REVERSECONVERSION);
Marshal.PtrToStructure(BufList, m_list);
byte[] buf = new byte[dwSize];
Marshal.Copy(BufList, buf, 0, dwSize);
Marshal.FreeHGlobal(BufList);
int os = m_list.dwOffset;
string str = System.Text.Encoding.Unicode.GetString(buf, os, buf.Length - os - 3);
string[] ret = str.Split(new char[1]{'\0'});
return ret[0];
}
类“
public WR_Imm32()
{
//nayiinStr=inStr;
//
// TODO: コンストラクタ ロジックをここに追加してください。
//
}
public enum GCL
{
CONVERSION = 1,
REVERSECONVERSION = 2,
REVERSE_LENGTH = 3
}
[DllImport("Imm32.dll", CharSet=CharSet.Auto, EntryPoint="ImmGetContext")]
public static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="GetKeyboardLayout")]
public static extern IntPtr GetKeyboardLayout(int idThread);
[DllImport("Imm32.dll", CharSet=CharSet.Auto, EntryPoint="ImmGetConversionList")]
public static extern int ImmGetConversionList(IntPtr hKL, IntPtr hIMC, string lpSrc, IntPtr lpDst, int dwBufLen, int uFlag);
[DllImport("Imm32.dll", CharSet=CharSet.Auto, EntryPoint="ImmReleaseContext")]
public static extern bool MessageBox(IntPtr hWnd, IntPtr hIMC);
[DllImport("imm32.dll", EntryPoint = "ImmInstallIME")]
public static extern int ImmInstallIMEA(string lpszIMEFileName, string lpszLayoutText);
[StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public class CANDIDATELIST
{
public int dwSize;
public int dwStyle;
public int dwCount;
public int dwSelection;
public int dwPageStart;
public int dwPageSize;
public int dwOffset;
}