zoukankan      html  css  js  c++  java
  • Get ListView items from other windows z

    This is more difficult than one might think. In order to get the information you're looking for, you have to execute the code in the same process space as the application containing the ListView control. You do that by allocating a block of memory in the target process that is large enough to hold the LVITEM structure and the string data you expect to be returned, then move that structure to the target process. The .NET Framework makes things quite a bit easier on us here with the Marshal class.

    Once you've taken that into account, it's a simple matter of declaring the LVITEM structure and sending the LVM_GETITEM message to the control using the SendMessage function, as you suspected.

    // P/Invoke declarationsprivateconstint LVM_FIRST =0x1000;privateconstint LVM_GETITEMCOUNT = LVM_FIRST +4;privateconstint LVM_GETITEM = LVM_FIRST +75;privateconstint LVIF_TEXT =0x0001;[DllImport("user32.dll"),CharSet=CharSet.Auto]privatestaticexternIntPtrSendMessage(IntPtr hWnd,intMsg,IntPtr wParam,IntPtr lParam);[StructLayoutAttribute(LayoutKind.Sequential)]privatestruct LVITEM
    {publicuint mask;publicint iItem;publicint iSubItem;publicuint state;publicuint stateMask;publicIntPtr pszText;publicint cchTextMax;publicint iImage;publicIntPtr lParam;}

    And then you would use it like this (assuming hListView is a valid handle to a ListView control):

    // Declare and populate the LVITEM structure
    LVITEM lvi =new LVITEM();
    lvi.mask = LVIF_TEXT;
    lvi.cchTextMax =512;
    lvi.iItem =1;// the zero-based index of the ListView item
    lvi.iSubItem =0;// the one-based index of the subitem, or 0 if this//  structure refers to an item rather than a subitem
    lvi.pszText =Marshal.AllocHGlobal(512);// Send the LVM_GETITEM message to fill the LVITEM structureIntPtr ptrLvi =Marshal.AllocHGlobal(Marshal.SizeOf(lvi));Marshal.StructureToPtr(lvi, ptrLvi,false);SendMessage(hListView, LVM_GETITEM,IntPtr.Zero, ptrLvi);// Extract the text of the specified itemstring itemText =Marshal.PtrToStringAuto(lvi.pszText);
  • 相关阅读:
    【CF1523E】Crypto Lights
    【洛谷P3228】数列
    【洛谷P4319】变化的道路
    Educational Codeforces Round 110
    【洛谷P2444】病毒
    一、Java语言基础(1)_走进java——第一个java程序
    android studio 调试smali
    Kickstart Round B 2018
    Proj THUDBFuzz Paper Reading: A Review of Machine Learning Applications in Fuzzing
    Proj THUDBFuzz Paper Reading: Fuzzing: Hack, Art, and Science
  • 原文地址:https://www.cnblogs.com/zeroone/p/3681397.html
Copyright © 2011-2022 走看看