0

サードパーティのアプリケーションからリストビューを取得しようとしています。これを達成しようとしている方法は次のとおりです

   [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
    const int LVM_GETITEMCOUNT = 0x018B;
    const int LVM_GETITEMTEXT = 0x0189;

    // Get ListBox contents hwnd
    private List<string> GetListViewContents(IntPtr listviewHwnd)
    {
        int cnt = (int)SendMessage(listviewHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, null);
        List<string> listViewContents = new List<string>();
        for (int i = 0; i < cnt; i++)
        {
            StringBuilder sb = new StringBuilder(256);
            IntPtr getText = SendMessage(listviewHwnd, LVM_GETITEMTEXT, (IntPtr)i, sb);
            listViewContents.Add(sb.ToString());
         }
        return listViewContents;
    }

次に、UISpy を使用してアプリケーションのリストビュー プロパティのハンドルを取得し、次のコードを使用してアプリケーション リストボックスにデータを入力します。

     IntPtr ks = new IntPtr(0x00040FA8); // temp handle for the 3rd party listview
     listBox1.DataSource = GetListViewContents(ks);

データが返されません。問題は何ですか?

4

1 に答える 1

0

http://msdn.microsoft.com/en-us/library/windows/desktop/bb761055(v=vs.85).aspxに従って、特定の構造を期待しているものに StringBuffer を渡しています。

64ビットでSysListView32からテキストを取得するをご覧ください。

于 2013-08-16T03:55:09.843 に答える