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:
Quote:
#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
Re: Problem sending LVN_COLUMNCLICK notification to a window
Re: Problem sending LVN_COLUMNCLICK notification to a window
According to Winpector, the application doesn't receive the WM_NOTIFY message.
Re: Problem sending LVN_COLUMNCLICK notification to a window
Quote:
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?
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.
Re: Problem sending LVN_COLUMNCLICK notification to a window
Quote:
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!
Re: Problem sending LVN_COLUMNCLICK notification to a window
Isn't SysHeader32 the child, and SysListView32 the parent that should receive the notification?
Re: Problem sending LVN_COLUMNCLICK notification to a window
Quote:
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.
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. :(
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?
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.
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...
Re: Problem sending LVN_COLUMNCLICK notification to a window
Re: Problem sending LVN_COLUMNCLICK notification to a window
Right.
The hProcHnd was not initialized...
Re: Problem sending LVN_COLUMNCLICK notification to a window
Why does it say "unused"?
What should I do now?