February 16th, 2011 02:33 PM
#1
Problem sending LVN_COLUMNCLICK notification to a window
I'm trying to send a notification to a ListView, but I can't find what am I doing wrong.
This is the code:
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
int second_try(){
DWORD pid = 0;
HWND hWnd=HWND(0x00020756);
GetWindowThreadProcessId( hWnd, &pid );
HANDLE hProcHnd = OpenProcess( PROCESS_VM_OPERATION |PROCESS_VM_READ|PROCESS_VM_WRITE, FALSE, pid );
LPVOID pNMLV = VirtualAllocEx( hProcHnd, NULL, sizeof( NMLISTVIEW ),
MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
NMLISTVIEW nmlvitem;
nmlvitem.hdr.code = LVN_COLUMNCLICK;
nmlvitem.hdr.hwndFrom = HWND(0x00020770);
nmlvitem.hdr.idFrom = 0;
nmlvitem.iItem=-1;
nmlvitem.iSubItem=2;
nmlvitem.lParam=0;
nmlvitem.ptAction.x=0;
nmlvitem.ptAction.y=0;
nmlvitem.uChanged=0;
nmlvitem.uNewState=0;
nmlvitem.uOldState=0;
DWORD copied = 0;
WriteProcessMemory( hProcHnd, pNMLV, &nmlvitem, sizeof( NMLISTVIEW ), &copied );
SendMessage( hWnd, WM_NOTIFY, (WPARAM)0, (LPARAM)pNMLV ) ;
VirtualFreeEx( hProcHnd, pNMLV, 0, MEM_RELEASE );
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
second_try();
return 0;
}
or you can see it here, too:
http://pastebin.com/MJyb4xib
February 16th, 2011 02:38 PM
#2
Re: Problem sending LVN_COLUMNCLICK notification to a window
Victor Nijegorodov
February 16th, 2011 03:02 PM
#3
Re: Problem sending LVN_COLUMNCLICK notification to a window
According to Winpector, the application doesn't receive the WM_NOTIFY message.
February 16th, 2011 03:10 PM
#4
Re: Problem sending LVN_COLUMNCLICK notification to a window
Originally Posted by
AlexA2
According to Winpector, the application doesn't receive the WM_NOTIFY message.
*application * cannot receive any message. Only window can. Which window did you inspect? Is it the parent of the list control window?
Victor Nijegorodov
February 16th, 2011 03:20 PM
#5
Re: Problem sending LVN_COLUMNCLICK notification to a window
hWnd belongs to the window that has the SysListView32 (Unicode) class.
And, yes, I used Winspector to inspect messages for this SysListView32 window.
February 16th, 2011 03:30 PM
#6
Re: Problem sending LVN_COLUMNCLICK notification to a window
Originally Posted by
AlexA2
And, yes, I used Winspector to inspect messages for this SysListView32 window.
But you (I guess!) want to send this WM_NOTIFY to the parent of SysListView32 window. Read the documentation of LVN_COLUMNCLICK notification!
Victor Nijegorodov
February 16th, 2011 03:35 PM
#7
Re: Problem sending LVN_COLUMNCLICK notification to a window
Isn't SysHeader32 the child, and SysListView32 the parent that should receive the notification?
February 16th, 2011 03:44 PM
#8
Re: Problem sending LVN_COLUMNCLICK notification to a window
Originally Posted by
AlexA2
Isn't SysHeader32 the child, and SysListView32 the parent that should receive the notification?
If the notification is HDN_ITEMCLICK or some other HDN_... then yes, it's list view control window that receives all these notifications (because the list view control is the parent of its header control) but all LVN_... notifications are sent to (and supposed to received by) the parent of the list view control.
Victor Nijegorodov
February 16th, 2011 03:50 PM
#9
Re: Problem sending LVN_COLUMNCLICK notification to a window
I understand now.
I've changed the hWnd to the parent's one and Winspector did not intercept any message.
February 16th, 2011 04:09 PM
#10
Re: Problem sending LVN_COLUMNCLICK notification to a window
Well, then:
1. Check if window handle (of the "parent") you are sending message to is the same as the actual one.
2. Try Spy++
3. BTW, did you debug your code to be sure it runs OK?
Victor Nijegorodov
February 16th, 2011 04:15 PM
#11
Re: Problem sending LVN_COLUMNCLICK notification to a window
How should I do a proper debug? Please tell me what should I check, and I'll post back the values.
February 16th, 2011 04:20 PM
#12
Re: Problem sending LVN_COLUMNCLICK notification to a window
Set a break point at the beginning of you second_try function, then press F5 to start debugging... then use F10 to go step by step through your code to see what happens...
Victor Nijegorodov
February 16th, 2011 04:31 PM
#13
Re: Problem sending LVN_COLUMNCLICK notification to a window
February 16th, 2011 04:37 PM
#14
Re: Problem sending LVN_COLUMNCLICK notification to a window
Right.
The hProcHnd was not initialized ...
Victor Nijegorodov
February 16th, 2011 04:38 PM
#15
Re: Problem sending LVN_COLUMNCLICK notification to a window
Why does it say "unused"?
What should I do now?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks