Коды команд есть в мсдн. Искать вручную в \Microsoft Visual Studio 8\VC\PlatformSDK\Include\WinUser.h:
| Код | #define LB_GETTEXT 0x0189 #define LB_GETTEXTLEN 0x018A |
Пример:
| Код | using System; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Text;
namespace WindowsApplication3 { public partial class Form1 : Form { [DllImport("user32.dll")] public static extern int SendMessage(int hwnd, int message, int wparam, int lparam);
[DllImport("user32.dll")] public static extern int SendMessage(int hwnd, int message, int wparam, StringBuilder lparam);
public Form1() { InitializeComponent();
GetTextFromListbox(this.listBox1.Handle.ToInt32()); }
string GetTextFromListbox(int hwnd) { int LB_GETTEXT = 0x189; int LB_GETTEXTLEN = 0x18A;
// получаем длину строки в листбоксе int len = SendMessage(hwnd, LB_GETTEXTLEN, 0, 0); // получаем текст StringBuilder sb = new StringBuilder(len); SendMessage(hwnd, LB_GETTEXT, 0, sb); return sb.ToString(); }
} } |
А вообще, http://www.pinvoke.net всегда был вне конкуренции
|