Henkie
February 20th, 2007, 12:42 PM
Hi,
I'm trying to write a programm in c++ that reads a ListView (from an other programm) and double click on an Item in the listview. I can read the listview but double clicking is a problem. Should this be done with a WM_NOTIFY message?
UnfitElf
February 20th, 2007, 11:28 PM
Hope the following helps
case WM_NOTIFY:
{
switch (((LPNMHDR)lParam)->code)
{
case NM_CLICK:
{
}
break;
case NM_DBLCLK:
{
}
break;
}
}
break;
In other words yes, you need to send a WM_NOTIFY message. Click here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/common/messages/wm_notify.asp) for info on the WM_NOTIFY message. You will also need to fill out the NMHDR structure to go with the message.
This is for the single and doubble click :)
Henkie
February 21st, 2007, 04:36 AM
First of all thx for your time and effort. I'm relative new to the Windows API and have lots to learn.
The code you posted isn't that to check if there has been a click / double click in the list within the programm? I'm trying to write a programm that clicks the list in a totally different programm. So I'm running a programm which I do not have the code from and I'm coding a programm that automates a few things for that programm (I'm lazy).
After reading on msdn for a bit I read this:
"For Windows 2000 and later systems, the WM_NOTIFY message cannot be sent between processes." Will this be a problem?
Thx in advance for the help.
Edit: Maybe it helps if I post some of my code:
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include <winuser.h>
#define LISTVIEWCONTROLEID 0x150
void main(void) {
NMHDR MessageStructure;
HWND MainClientHandle = FindWindow(NULL, "Window Name\0");
HWND ListViewHandle = GetDlgItem(MainClientHandle, LISTVIEWCONTROLEID);
int count=(int)SendMessage(ListViewHandle, LVM_GETITEMCOUNT, 0, 0);
int i;
LVITEM lvi, *_lvi;
char item[512], subitem[512];
char *_item, *_subitem;
unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(ListViewHandle, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|
PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM),
MEM_COMMIT, PAGE_READWRITE);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
lvi.cchTextMax=512;
for(i=0; i<count; i++) {
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(ListViewHandle, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
lvi.iSubItem=1;
lvi.pszText=_subitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(ListViewHandle, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, 512, NULL);
ReadProcessMemory(process, _subitem, subitem, 512, NULL);
printf("%s - %s\n", item, subitem);
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
// Try double clicking something
MessageStructure.hwndFrom = ListViewHandle;
MessageStructure.idFrom = LISTVIEWCONTROLEID;
MessageStructure.code = NM_DBLCLK;
SendMessage(MainClientHandle, WM_NOTIFY, LISTVIEWCONTROLEID, (LPARAM)&MessageStructure);
getch();
}
The first part is to read the listview. The bottom part is my attempt to double click something. I have no idea what I'm clicking here, I hoped mayb it would click the selected part in the list. I was just trying something.