我发送这样两个消息使一个item被选中:::PostMessage(hListView,WM_LBUTTONDOWN,1,MAKELONG(10,10));
::PostMessage(hListView,WM_LBUTTONUP,1,MAKELONG(10,10));运行的时候虽然这个item加亮了,但实际上还是没有选中,因为我再点另外一个button的时候,它提示说没有选中。我这个问题应该怎么解决?因为SysListView32是另外一个进程的窗口,我只能通过发送消息来控制。而且我不想用鼠标模拟,因为这样的话窗口就不能最小化。谢谢各位给点建议!

解决方案 »

  1.   

    试试这个
    LBN_SELCHANGE
    An application sends the LBN_SELCHANGE notification message when the selection in a list box is about to change. The parent window of the list box receives this notification message through the WM_COMMAND message. LBN_SELCHANGE 
    idListBox = (int) LOWORD(wParam);  // identifier of list box 
    hwndListBox = (HWND) lParam;       // handle to list box 
     
    Res
    This notification message is not sent if the LB_SETCURSEL message changes the selection. This notification message applies only to a list box that has the LBS_NOTIFY style. For a multiple-selection list box, the LBN_SELCHANGE notification is sent whenever the user presses an arrow key, even if the selection does not change. QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.
      

  2.   

    我不是listBox控件啊,是CListCtrl控件,LBN_SELCHANGE这个消息是LsitBox的啊,
      

  3.   

    为什么我的是选中的,“再点另外一个button的时候,它提示说没有选中”,这是什么意思,你怎么判断是否选中的?
      

  4.   

    我就是通过再点另外一个button的时候,看它弹出什么窗口来判断item是否被选中的。
    如果我是手动去选中那个item,再点另外一个button,它就不会提示说“没有选中”.
      

  5.   

    LVITEM lvItem = (LVITEM*)AllocShareMemory(sizeof(LVITEM));
    memset(lvItem, 0, sizeof(lvItem));
    lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
    lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
    SendMessage(hListView, LVM_SETITEMSTATE, nItem, (LPARAM)lvItem);
    FreeShareMemory(lvItem);
      

  6.   

    更正:
    LVITEM lvItem     ->   LVITEM *lvItem
    sizeof(lvItem)    ->   sizeof(LVITEM)
    lvItem.stateMask  ->   lvItem->stateMask
    lvItem.state      ->   lvItem->state
      

  7.   

    to:needways(武林怪杰) 'AllocShareMemory' : undeclared identifier没有这个函数啊?
      

  8.   

    AllocateSharedMemorywin2000以上的系统。Requirements
    Client: Included in Windows XP, Windows 2000 Professional.
    Server: Included in Windows Server 2003, Windows 2000 Server.
    Header: Declared in Ntsecpkg.h.
      

  9.   

    你可以到 codeproject 去看看 CShareMem 的例子。
      

  10.   

    发送LVM_SETITEMSTATE,并设置参数为LVIS_FOCUSED|LVIS_SELECTED同理于
    m_list.SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED,
        LVIS_SELECTED|LVIS_FOCUSED);
      

  11.   

    我的系统是 Windows 2000 Server 啊,照说应该可以的,
    可是我包含Ntsecpkg.h的时候,它说找不到这个文件,怎么回事啊?
      

  12.   

    AllocShareMemory 的大致实现方法如下:
        HANDLE hFile = CreateFile(INVALID_HANDLE_VALUE, ...);
        HANDLE hMap  = CreateFileMapping(hFile, ...);
        return (PVOID)MapViewOfFile(hMap, ...);
      

  13.   

    参考“CSharedMemory, A Small Class to Share Data Via File Mapping ” ->
    http://www.codeguru.com/Cpp/W-P/system/sharedmemory/article.php/c5689/
      

  14.   

    to:  needways(武林怪杰)
    按你说的,我下载了CShareMemory类,还是不行!你看看是我用的不对吗?我自己程序的构造涵数中:
    m_SM.Init("MyUniqueMemoryName",sizeof(LVITEM));//CShareMemory m_SM是我的类的成员,我用下面的代码来使ITEM选中:
    m_SM.Lock();
    ((LVITEM*)m_SM.GetData())->stateMask = LVIS_FOCUSED | LVIS_SELECTED;
    ((LVITEM*)m_SM.GetData())->state = LVIS_FOCUSED | LVIS_SELECTED;
    m_SM.Unlock();
    ::SendMessage(hListView, LVM_SETITEMSTATE, 0, (LPARAM)(LVITEM*)m_SM.GetData() );可是运行后还是没有作用!怎么回事啊?
      

  15.   

    对于你原来的PostMessage,你先调试一下你的消息收到没有,如果没有收到消息,那就是你发消息出错了,应该没错的,因为你已经高亮显示了
    如果收到了消息,那基本上可以说你已经选中了,至于为什么你的button没有提示,你看看是不是还有其它的原因,还是不明白你这里的button是什么意思,没听说过ListView中有什么button的
    你GetFirstSelectedItemPosition,然后GetNextSelectItem看看有没有选中的项,有选中的项,就表示肯定选择上了,没有的话,哎,就得看情况了,好难分析啊,感觉上好象不太可能的