
如圖左邊是一個SysTreeView32控制元件,
我想獲取該控制元件下所有節點的句柄,并能發送訊息選中單擊某個指定名稱節點
求指點。。。
小菜鳥剛接觸API不久
在線等.....求原始碼
#region API
/* API的定義 */
/// <summary>
/// 本質是FindWindow,查找目標句柄
/// </summary>
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
最好能用c#語言寫 更容易看懂
uj5u.com熱心網友回復:
不是有C#的專門版塊嗎?uj5u.com熱心網友回復:
Tree Control Item Information
Home | Overview | Sample
Tree controls (CTreeCtrl) have a number of member functions that retrieve information about items in the control. The GetItem member function retrieves some or all of the data associated with an item. This data could include the item's text, state, images, count of child items, and an application-defined 32-bit data value. There is also a SetItem function that can set some or all of the data associated with an item.
The GetItemState, GetItemText, GetItemData, and GetItemImage member functions retrieve individual attributes of an item. Each of these functions has a corresponding Set function for setting the attributes of an item.
The GetNextItem member function retrieves the tree control item that bears the specified relationship to the current item. This function can retrieve an item's parent, the next or previous visible item, the first child item, and so on. There are also member functions to traverse the tree: GetRootItem, GetFirstVisibleItem, GetNextVisibleItem, GetPrevVisibleItem, GetChildItem, GetNextSiblingItem, GetPrevSiblingItem, GetParentItem, GetSelectedItem, and GetDropHilightItem.
The GetItemRect member function retrieves the bounding rectangle for a tree control item. The GetCount and GetVisibleCount member functions retrieve a count of the items in a tree control and a count of the items that are currently visible in the tree control's window, respectively. You can ensure that a particular item is visible by calling the EnsureVisible member function.
See Also Windows Common Controls and MFC Classes
Common Control Sample List
Home | Overview | Details
See the following sample programs that illustrate common controls:
CMNCTRL1
CMNCTRL2
CTRLTEST
FIRE
Back to Control Tasks
uj5u.com熱心網友回復:
public static bool GetTreeViewText(IntPtr AHandle){
uint vProcessId;
GetWindowThreadProcessId(AHandle, out vProcessId);
IntPtr vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
PROCESS_VM_WRITE, false, vProcessId);
IntPtr vPointer = VirtualAllocEx(vProcess, IntPtr.Zero, 4096,
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
try
{
uint vItemCount = TreeView_GetCount(AHandle);
IntPtr vTreeItem = GetRoot(AHandle);//根節點
vTreeItem = GetFirstChildItem(AHandle, vTreeItem);//第一個子節點
MessageBox.Show(vItemCount.ToString());
for (int i = 0; i < vItemCount; i++)
{
byte[] vBuffer = new byte[256];
TVITEM[] vItem = new TVITEM[1];
vItem[0] = new TVITEM();
vItem[0].mask = TVIF_TEXT;
vItem[0].hItem = vTreeItem;
vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(TVITEM)));
vItem[0].cchTextMax = vBuffer.Length;
uint vNumberOfBytesRead = 0;
WriteProcessMemory(vProcess, vPointer,
Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),
Marshal.SizeOf(typeof(TVITEM)), ref vNumberOfBytesRead);
SendMessage(AHandle, TVM_GETITEMA, 0, (int)vPointer);
ReadProcessMemory(vProcess,
(IntPtr)((int)vPointer + Marshal.SizeOf(typeof(TVITEM))),
Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),
vBuffer.Length, ref vNumberOfBytesRead);
MessageBox.Show(Marshal.PtrToStringAnsi(
Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0)));
vTreeItem = GetNextItem(AHandle, vTreeItem);
}
}
finally
{
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
}
return true;
}
所有句柄 都有 值 但回傳的 就是空的字串
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/102511.html
標籤:API
上一篇:程式API介面訪問問題
