首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

SysTreeview32解决方案

2012-04-15 
SysTreeview32vb 怎么读取 systreeview中选中节点 文本名称呢[解决办法]窗体:VB codeOption ExplicitPriva

SysTreeview32
vb 怎么读取 systreeview 中选中节点 文本名称呢

[解决办法]
窗体:

VB code
Option ExplicitPrivate Sub Command1_Click()    Dim mhwnd As Long    mhwnd = Val(Text1.Text) 'Text1里 treeview的句柄    Dim i As Long, s As String    Dim dwProcessId As Long, hProcess As Long    Dim dwBytesRead As Long, dwBytesWrite As Long    Dim bSuccess As Long    Call GetWindowThreadProcessId(mhwnd, dwProcessId)    Dim lpTreeItemRemote As Long, lpTextRemote As Long    Dim nMaxLen As Long    nMaxLen = 1023    Dim szBuf() As Byte    ReDim szBuf(nMaxLen)    Dim lvItemLocal As TVITEM    Dim bWriteOK As Long        Dim sItemText As String        hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0&, dwProcessId)    If hProcess <> 0 Then        lpTextRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, nMaxLen + 1, MEM_COMMIT, PAGE_READWRITE)        lpTreeItemRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, Len(lvItemLocal), MEM_COMMIT, PAGE_READWRITE)        bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesWrite)                'write structure        dwBytesWrite = 0        lvItemLocal.hItem = SendMessage(mhwnd, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0)        lvItemLocal.mask = TVIF_TEXT + TVIF_HANDLE        lvItemLocal.cchTextMax = nMaxLen        lvItemLocal.pszText = lpTextRemote        bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpTreeItemRemote, ByVal VarPtr(lvItemLocal), Len(lvItemLocal), dwBytesWrite)                'get item        i = SendMessage(mhwnd, TVM_GETITEM, 0&, ByVal lpTreeItemRemote)                        'read result        bSuccess = ReadProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesRead)        Call VirtualFreeEx(hProcess, ByVal lpTreeItemRemote, 0, MEM_DECOMMIT)        Call VirtualFreeEx(hProcess, ByVal lpTextRemote, 0, MEM_DECOMMIT)    End If    CloseHandle hProcess        '*************** 显示结果    sItemText = StrConv(LeftB(szBuf, InStrB(szBuf, ChrB(0))), vbUnicode)    Text2.Text = sItemTextEnd Sub
[解决办法]
VB code
Option ExplicitPublic Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPublic Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long'StructuresPublic Type TVITEM    mask As Long    hItem As Long    state As Long    stateMask As Long    pszText As Long    cchTextMax As Long    iImage As Long    iSelectedImage As Long    cChildren As Long    lParam As LongEnd Type'public constantsPublic Const TVIF_TEXT = 1Public Const TVIF_HANDLE = &H10Public Const TV_FIRST = &H1100&Public Const TVM_GETCOUNT = TV_FIRST + 5Public Const TVM_SELECTITEM = TV_FIRST + 11Public Const TVM_GETITEM = TV_FIRST + 12Public Const TVM_GETNEXTITEM = TV_FIRST + 10Public Const TVGN_ROOT = 0Public Const TVGN_NEXT = 1Public Const TVGN_CHILD = 4Public Const TVGN_CARET = 9'API declarationsPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongPublic Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPublic Declare Function VirtualAlloc Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPublic Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPublic Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPublic Declare Function VirtualFree Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As LongPublic Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPublic Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String)'============NT Shared memory staff======================Public Const PROCESS_QUERY_INFORMATION = &H400Public Const PROCESS_VM_OPERATION = &H8Public Const PROCESS_VM_READ = &H10Public Const PROCESS_VM_WRITE = &H20Public Const PROCESS_ALL_ACCESS = 0Public Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPublic Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As LongPublic Const MEM_COMMIT = &H1000Public Const MEM_RESERVE = &H2000Public Const MEM_DECOMMIT = &H4000Public Const MEM_RELEASE = &H8000Public Const MEM_FREE = &H10000Public Const MEM_PRIVATE = &H20000Public Const MEM_MAPPED = &H40000Public Const MEM_TOP_DOWN = &H100000'==========Memory access public constants===========Public Const PAGE_NOACCESS = &H1&Public Const PAGE_READONLY = &H2&Public Const PAGE_READWRITE = &H4&Public Const PAGE_WRITECOPY = &H8&Public Const PAGE_EXECUTE = &H10&Public Const PAGE_EXECUTE_READ = &H20&Public Const PAGE_EXECUTE_READWRITE = &H40&Public Const PAGE_EXECUTE_WRITECOPY = &H80&Public Const PAGE_GUARD = &H100&Public Const PAGE_NOCACHE = &H200& 

热点排行