怎样获取Nero中左边Listview中的内容? ( 积分: 100 )

  • 主题发起人 主题发起人 缤纷翼彩
  • 开始时间 开始时间

缤纷翼彩

Unregistered / Unconfirmed
GUEST, unregistred user!
我从网上收集这些代码整合后应该可以获取其他窗体中ListView控件的内容的,我已经把我的程序打包&nbsp;放上来了。<br><br>运行程序后把鼠标指到要获取的Listview上&nbsp;,然后按Alt+F8;程序将获得其Listview中的内容<br>图中成功获得NERO右边的目录树内容<br>
142417_1470532163_hqqlkbxb.jpg
<br><br>但是我尝试用同样的方法来获取左边的内容就有问题,如图<br><br>
145145_665782952_scusecpz.jpg
<br><br>我猜测左边的控件不是标准的ListView,是该程序的开发者重新编写的,那么&nbsp;我想获取左边的<br><br>
145456_1854831151_tjwprfni.jpg
<br>这个控件的所有内容呢?<br><br>不知道有没有高手为我讲解一下呢?&nbsp;好希望多掌握点东西。
 
我把程序的代码贴出来&nbsp;<br><br>
代码:
unit&nbsp;Unit1;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;CommCtrl,&nbsp;StdCtrls;<br><br>type<br>&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;MemoText:&nbsp;TMemo;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormClose(Sender:&nbsp;TObject;&nbsp;var&nbsp;Action:&nbsp;TCloseAction);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormCreate(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;function&nbsp;ListViewColumnCount(mHandle:&nbsp;THandle):&nbsp;Integer;<br>&nbsp;&nbsp;function&nbsp;GetListViewText(mHandle:&nbsp;THandle;&nbsp;mStrings:&nbsp;TStrings):&nbsp;Boolean;<br>&nbsp;&nbsp;procedure&nbsp;HotKeyDown(var&nbsp;Msg:&nbsp;Tmessage);&nbsp;message&nbsp;WM_HOTKEY&nbsp;;<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br>&nbsp;&nbsp;HotKeyId:&nbsp;Integer;<br><br>{用到3个API函数&nbsp;<br><br>BOOL&nbsp;RegisterHotKey(&nbsp;<br>HWND&nbsp;hWnd,&nbsp;&nbsp;&nbsp;&nbsp;//响应该热键的窗口句柄&nbsp;<br>Int&nbsp;id,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//该热键的唯一标识&nbsp;<br>UINT&nbsp;fsModifiers,&nbsp;//该热键的辅助按键&nbsp;<br>UINT&nbsp;vk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//该热键的键值<br>);&nbsp;<br><br>为了得到唯一标识,我们还将用到另一个API函数&nbsp;<br><br>ATOM&nbsp;GlobalAddAtom(&nbsp;<br><br>LPCTSTR&nbsp;lpString&nbsp;//自己设定的一个字符串&nbsp;<br><br>);&nbsp;<br><br>因为我们还要在程序退出的时候,消除这个热键,&nbsp;所以需要声明一个全局变量:&nbsp;<br><br>HotKeyId:&nbsp;Integer;<br>}<br><br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>function&nbsp;TForm1.ListViewColumnCount(mHandle:&nbsp;THandle):&nbsp;Integer;<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;Header_GetItemCount(ListView_GetHeader(mHandle));<br>end;<br><br><br>{注册了热键,就该写下响应代码了。<br><br>首先,在程序头部分的private段中加入声明&nbsp;(作用是声明这个过程,和声明变量类似。<br>关于如何声明函数、过程,请请参考各自的帮助文件或其它资料):<br><br>procedure&nbsp;HotKeyDown(var&nbsp;Msg:&nbsp;Tmessage);&nbsp;message&nbsp;WM_HOTKEY;<br><br>然后在程序中加入如下代码:<br>}<br><br>procedure&nbsp;TForm1.HotKeyDown(var&nbsp;Msg:&nbsp;Tmessage);<br>begin<br>if&nbsp;(Msg.LparamLo&nbsp;=&nbsp;MOD_ALT)&nbsp;AND&nbsp;(Msg.LParamHi&nbsp;=&nbsp;VK_F8)&nbsp;then&nbsp;//&nbsp;假设热键为ALT+F8<br>begin<br>GetListViewText(WindowFromPoint(Point(Mouse.CursorPos.X,&nbsp;Mouse.CursorPos.Y)),MemoText.Lines);<br><br>end;<br>end;<br><br><br>function&nbsp;TForm1.GetListViewText(mHandle:&nbsp;THandle;&nbsp;mStrings:&nbsp;TStrings):&nbsp;Boolean;<br>var<br>&nbsp;&nbsp;vColumnCount:&nbsp;Integer;<br>&nbsp;&nbsp;vItemCount:&nbsp;Integer;<br>&nbsp;&nbsp;I,&nbsp;J:&nbsp;Integer;<br>&nbsp;&nbsp;vBuffer:&nbsp;array[0..255]&nbsp;of&nbsp;Char;<br>&nbsp;&nbsp;vProcessId:&nbsp;DWORD;<br>&nbsp;&nbsp;vProcess:&nbsp;THandle;<br>&nbsp;&nbsp;vPointer:&nbsp;Pointer;<br>&nbsp;&nbsp;vNumberOfBytesRead:&nbsp;Cardinal;<br>&nbsp;&nbsp;S:&nbsp;string;<br>&nbsp;&nbsp;vItem:&nbsp;TLVItem;<br><br><br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;False;<br>&nbsp;&nbsp;if&nbsp;not&nbsp;Assigned(mStrings)&nbsp;then&nbsp;Exit;<br><br><br>&nbsp;&nbsp;vColumnCount&nbsp;:=&nbsp;ListViewColumnCount(mHandle);<br>&nbsp;&nbsp;showmessage('有'+inttostr(vColumnCount)+'列');<br>&nbsp;&nbsp;if&nbsp;vColumnCount&nbsp;&lt;=&nbsp;0&nbsp;then&nbsp;Exit;<br>&nbsp;&nbsp;vItemCount&nbsp;:=&nbsp;ListView_GetItemCount(mHandle);<br>&nbsp;&nbsp;GetWindowThreadProcessId(mHandle,&nbsp;@vProcessId);<br>&nbsp;&nbsp;vProcess&nbsp;:=&nbsp;OpenProcess(PROCESS_VM_OPERATION&nbsp;or&nbsp;PROCESS_VM_READ&nbsp;or<br>&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_WRITE,&nbsp;False,&nbsp;vProcessId);<br>&nbsp;&nbsp;vPointer&nbsp;:=&nbsp;VirtualAllocEx(vProcess,&nbsp;nil,&nbsp;4096,&nbsp;MEM_RESERVE&nbsp;or&nbsp;MEM_COMMIT,<br>&nbsp;&nbsp;&nbsp;&nbsp;PAGE_READWRITE);<br>&nbsp;&nbsp;mStrings.BeginUpdate;<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;mStrings.Clear;<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;I&nbsp;:=&nbsp;0&nbsp;to&nbsp;vItemCount&nbsp;-&nbsp;1&nbsp;do&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S&nbsp;:=&nbsp;'';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;J&nbsp;:=&nbsp;0&nbsp;to&nbsp;vColumnCount&nbsp;-&nbsp;1&nbsp;do&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;vItem&nbsp;do&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mask&nbsp;:=&nbsp;LVIF_TEXT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iItem&nbsp;:=&nbsp;I;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iSubItem&nbsp;:=&nbsp;J;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cchTextMax&nbsp;:=&nbsp;SizeOf(vBuffer);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pszText&nbsp;:=&nbsp;Pointer(Cardinal(vPointer)&nbsp;+&nbsp;SizeOf(TLVItem));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WriteProcessMemory(vProcess,&nbsp;vPointer,&nbsp;@vItem,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SizeOf(TLVItem),&nbsp;vNumberOfBytesRead);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendMessage(mHandle,&nbsp;LVM_GETITEM,&nbsp;I,&nbsp;lparam(vPointer));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReadProcessMemory(vProcess,&nbsp;Pointer(Cardinal(vPointer)&nbsp;+&nbsp;SizeOf(TLVItem)),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@vBuffer[0],&nbsp;SizeOf(vBuffer),&nbsp;vNumberOfBytesRead);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S&nbsp;:=&nbsp;S&nbsp;+&nbsp;#9&nbsp;+&nbsp;vBuffer;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete(S,&nbsp;1,&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mStrings.Add(S);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;finally<br>&nbsp;&nbsp;&nbsp;&nbsp;VirtualFreeEx(vProcess,&nbsp;vPointer,&nbsp;0,&nbsp;MEM_RELEASE);<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(vProcess);<br>&nbsp;&nbsp;&nbsp;&nbsp;mStrings.EndUpdate;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;True;<br><br>end;&nbsp;{&nbsp;GetListViewText&nbsp;}<br><br><br>procedure&nbsp;TForm1.FormCreate(Sender:&nbsp;TObject);<br>begin<br>HotKeyId&nbsp;:=&nbsp;GlobalAddAtom('MyHotKey')&nbsp;-&nbsp;$C000;<br>{注:&nbsp;HotKeyId的合法取之范围是0x0000到0xBFFF之间,&nbsp;GlobalAddAtom函数得到的值&nbsp;<br>在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。}<br>&nbsp;&nbsp;&nbsp;RegisterHotKey(Handle,hotkeyid,MOD_ALT,VK_F8);<br><br><br>{热键的辅助按键包括Mod_Ctrl&nbsp;、Mod_Alt、Mod_Shift,对于Windows兼容键盘还支持Windows<br>键,即其键面上有Windows标志的那个键,其值为Mod_win。<br><br>上面&nbsp;的代码注册了一个热键:ALT+F8。当然如果你希望象TAKEIT那样,只用F8,&nbsp;就这么写:&nbsp;<br><br>RegisterHotKey(Handle,&nbsp;hotkeyid,&nbsp;0,&nbsp;VK_F8);&nbsp;&nbsp;&nbsp;<br><br>注:handle是一个特殊的变量,它表示当前窗口的句柄。&nbsp;<br><br>这个函数你应该能句举一反三了吧。&nbsp;<br><br>原理:&nbsp;<br><br>一旦热键设置成功,在程序应用过程中如果有相应的键被按下,Windows系统都会给你的应&nbsp;<br>用程序发送一个消息WM_HOTKEY,不管你的应用程序是否为当前活动的。其中WM_HOTKEY消&nbsp;<br>息的格式为:&nbsp;&nbsp;&nbsp;<br><br>idHotKey&nbsp;=&nbsp;(int)&nbsp;wParam;&nbsp;//&nbsp;该参数在设置系统级的热键有用,一般不予使用&nbsp;<br>fuModifiers&nbsp;=&nbsp;(UINT)&nbsp;LOWORD(lParam);&nbsp;&nbsp;//热键的辅助按键&nbsp;<br>uVirtKey&nbsp;=&nbsp;(UINT)&nbsp;HIWORD(lParam);&nbsp;//热键的键值<br>}<br>end;<br><br>procedure&nbsp;TForm1.FormClose(Sender:&nbsp;TObject;&nbsp;var&nbsp;Action:&nbsp;TCloseAction);<br>begin<br>UnRegisterHotKey(handle,&nbsp;HotKeyId);<br>{在窗口的close事件中加入&nbsp;<br><br>UnRegisterHotKey(handle,&nbsp;HotKeyId);&nbsp;//注销HotKey,&nbsp;释放资源。}<br>end;<br><br>end.
 
后退
顶部