c#用API两次调用SendMessage,但参数类型不同,如何声明
c#的.net compact,用API调用SendMessage的SB_SETPARTS来把StatusBar分成3栏,然后再调用SendMessage的SB_SETTEXT来发送要显示的文本,但是SB_SETPARTS和SB_SETTEXT中的最后一个参数是不同的类型,前者是数组,后者是字符串,清用过的大家帮帮忙,这个如何同一呀?
代码如下,还没同一类型,编译出错:
[DllImport("coredll.Dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int[] lParam);//只能应用一种?
public const int WM_USER = 0x0400;
public const int SB_SETPARTS = WM_USER + 4;
public const int SB_SETTEXT = WM_USER + 11;
//设置状态栏的分栏和显示文本,但是widths和"abc"类型不能同一呀?
int[] widths = { 200, 100, 100, -1 };
SendMessage(this.statusBar1.Handle, SB_SETPARTS, 3, widths[0]);
SendMessage(this.statusBar1.Handle, SB_SETTEXT, 0, "abc");
API
C#
SB_SETPARTS
SB_SETTEXT
SendMessage
------解决方案--------------------可以用指定入口点声明2个函数,但参数不同,如:
[DllImport("user32.dll", EntryPoint="MessageBoxA")]
public static extern int MsgBox(uint hWnd, String text, String caption,
uint type);
[DllImport("user32.dll", EntryPoint="MessageBoxA")]
public static extern int MsgIntBox(int hWnd, String text, String caption,
int type);