CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    Join Date
    Jan 2011
    Posts
    34

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    What does not work?
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2011
    Posts
    34

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    According to Winpector, the application doesn't receive the WM_NOTIFY message.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Quote Originally Posted by AlexA2 View Post
    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

  5. #5
    Join Date
    Jan 2011
    Posts
    34

    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.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Quote Originally Posted by AlexA2 View Post
    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

  7. #7
    Join Date
    Jan 2011
    Posts
    34

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Isn't SysHeader32 the child, and SysListView32 the parent that should receive the notification?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Quote Originally Posted by AlexA2 View Post
    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

  9. #9
    Join Date
    Jan 2011
    Posts
    34

    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.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  11. #11
    Join Date
    Jan 2011
    Posts
    34

    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.

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  13. #13
    Join Date
    Jan 2011
    Posts
    34

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    http://img254.imageshack.us/i/74380008.png/



    Uploaded with ImageShack.us

    It doesn't look very good, right?

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Right.
    The hProcHnd was not initialized...
    Victor Nijegorodov

  15. #15
    Join Date
    Jan 2011
    Posts
    34

    Re: Problem sending LVN_COLUMNCLICK notification to a window

    Why does it say "unused"?
    What should I do now?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured