problem with ListView control

Hello, I have a problem with ListView control in my dialog box. I have to know when there aren't any selected items in that control.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
BOOL CALLBACK ExampleDlgProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{

switch(message)
  {
     case WM_INITDIALOG:
          return true;
          break;
    case WM_NOTIFY:
			switch(LOWORD(wParam))
			  {
                 case ILV_LOGICAL:
                   {
                      HWND hList=GetDlgItem(hwnd,ILV_MY_LISTVIEW);

                      if(((LPNMHDR)lParam)->code == NM_KILLFOCUS )
                        {

                        }
                      else if(((LPNMHDR)lParam)->code == NM_CLICK)
                        {
                          // do something
                        }
				      else if( /* no items selected */ )
				        {
				          // disable few buttons  (I know how to do this)
				        }
                    }
              break;
            }
  

    break;
     case WM_COMMAND:
          switch(LOWORD(wParam))
            {

              case IDCANCEL:
                   EndDialog(hwnd,IDD_EXAMPLE);
                   break;
            }
   default: return false;
  }

}

Thanks for help.
I'm sure that there is a function you can use (or there is a message you can send
to the listview asking it) to get the number of selected items in the ListView.

As a matter of fact:
http://msdn.microsoft.com/en-us/library/bb774996(VS.85).aspx
EDIT: I have another question. I created a popup menu:
1
2
3
4
5
6
7
8
9
10
// ....
                else  if(((LPNMHDR)lParam)->code == NM_RCLICK)
                  {
                    HMENU hPopupMenu = CreatePopupMenu();
                    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, IDCANCEL, (LPCSTR)"Cancel");
                    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, IDB_DELETE, (LPCSTR)"Delete");
                    SetForegroundWindow(hwnd);
                    TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hwnd, NULL);
                  }

The problem that it appears on upper left corner of screen and I want it to appear under mouse cursor. How can I do this?
Last edited on
TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hwnd, NULL);

In the TrackPopupMenu function, the x and y position cor-ordinates are relative to
the screen - not the window.

So the 0,0 in your call will put it at the very top left of the screen.

If you want it at the mouse co-ordinates, then if you don't have the mouse position to hand, then use this function
GetCursorPos Function.

See here:
http://msdn.microsoft.com/en-us/library/ms648390%28VS.85%29.aspx
Last edited on
Thanks!
Topic archived. No new replies allowed.