www.pudn.com > 嵌入式linux9应用开发祥解.rar > listview.c


#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#define IDC_CTRL2       20
#define IDC_CTRL3       30
#define IDC_CTRL4       40
static HWND hMainWnd = HWND_INVALID;
static int
ControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
  static HWND hChildWnd1, hBtnWnd1, hBtnWnd2;

  switch (message)
    {
    case MSG_CREATE:
      {
        int i;
        LVSUBITEM subdata;
        LVITEM item;
        LVCOLOUM s1;

        hChildWnd1 = CreateWindow (CTRL_LISTVIEW, "List View",
                                   WS_CHILD | WS_VISIBLE | WS_VSCROLL |
                                   WS_HSCROLL | WS_BORDER, 110, 20, 20, 200,
                                   200, hWnd, 0);
        s1.nCols = 1;
        s1.pszHeadText = "JJJ";
        s1.width = 80;


        SendMessage (hChildWnd1, LVM_ADDCOLUMN, 0, (LPARAM) & s1);

        s1.nCols = 2;
        s1.pszHeadText = "JJJ";
        s1.width = 80;

        SendMessage (hChildWnd1, LVM_ADDCOLUMN, 0, (LPARAM) & s1);

        s1.nCols = 3;
        s1.pszHeadText = "JJJ";
        s1.width = 60;


        SendMessage (hChildWnd1, LVM_ADDCOLUMN, 0, (LPARAM) & s1);


        for (i = 1; i <= 4; i++)
          {
            item.nItem = i;
            SendMessage (hChildWnd1, LVM_ADDITEM, 0, (LPARAM) & item);
          }
        subdata.nItem = 1;
        subdata.subItem = 2;
        subdata.pszText = "11asas11";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 2;
        subdata.subItem = 2;
        subdata.pszText = "21sdsfsfi21";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 3;
        subdata.subItem = 2;
        subdata.pszText = "31ajsd31";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 4;
        subdata.subItem = 2;
        subdata.pszText = "41ksdj41";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        SendMessage (hChildWnd1, LVM_SETITEMCOLOR, 3, PIXEL_green);

        subdata.nItem = 1;
        subdata.subItem = 1;
        subdata.pszText = "11asas11";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 2;
        subdata.subItem = 1;
        subdata.pszText = "21sdsfsfi21";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 3;
        subdata.subItem = 1;
        subdata.pszText = "31ajsd31";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 4;
        subdata.subItem = 1;
        subdata.pszText = "41ksdj41";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        SendMessage (hChildWnd1, LVM_SETITEMCOLOR, 3, PIXEL_green);

        subdata.nItem = 1;
        subdata.subItem = 3;
        subdata.pszText = "11asas11asdjasdajsd";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 2;
        subdata.subItem = 3;
        subdata.pszText = "21sdsfsfi21asdasdas";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 3;
        subdata.subItem = 3;
        subdata.pszText = "31ajsd31";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        subdata.nItem = 4;
        subdata.subItem = 3;
        subdata.pszText = "41ksdj41";
        SendMessage (hChildWnd1, LVM_FILLSUBITEM, 0, (LPARAM) & subdata);
        SendMessage (hChildWnd1, LVM_SETITEMCOLOR, 3, PIXEL_green);

        s1.nCols = 1;
        s1.pszHeadText = "hhh";
        SendMessage (hChildWnd1, LVM_MODIFYHEAD, 0, (LPARAM) & s1);

        hBtnWnd1 = CreateWindow ("button", "Delete",
                                 WS_CHILD
                                 | BS_PUSHBUTTON
                                 | WS_VISIBLE,
                                 IDC_CTRL2, 230, 20, 60, 20, hWnd, 0);
        hBtnWnd2 = CreateWindow ("button", "Clear",
                                 WS_CHILD
                                 | BS_PUSHBUTTON
                                 | WS_VISIBLE,
                                 IDC_CTRL3, 230, 60, 60, 20, hWnd, 0);
        /*
           hBtnWnd3 = CreateWindow("button",   "Add",                
           WS_CHILD 
           | BS_PUSHBUTTON 
           | WS_VISIBLE, 
           IDC_CTRL4,
           50, 260, 120, 20, hWnd, 0);
         */



      }
      break;
    case MSG_COMMAND:
      {
        int id = LOWORD (wParam);
        int nSel;
        LVITEM param;

        switch (id)
          {

          case IDC_CTRL2:
            nSel = SendMessage (hChildWnd1, LVM_GETSELECTEDITEM, 0, 0);
            param.nItem = nSel;
            SendMessage (hChildWnd1, LVM_DELITEM, 0, (LPARAM) & param);
            break;
          case IDC_CTRL3:
            SendMessage (hChildWnd1, LVM_DELALLITEM, 0, 0);
            break;
          case IDC_CTRL4:
            break;

          }
      }
      break;
    case MSG_CLOSE:
      DestroyAllControls (hWnd);
      DestroyMainWindow (hWnd);
      MainWindowCleanup (hWnd);
      hMainWnd = HWND_INVALID;
      return 0;

    }
  return DefaultMainWinProc (hWnd, message, wParam, lParam);

}
static void
InitCreateInfo (PMAINWINCREATE pCreateInfo)
{
  pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_MINIMIZEBOX
    | WS_MAXIMIZEBOX | WS_VISIBLE;
  pCreateInfo->dwExStyle = WS_EX_NONE;
  pCreateInfo->spCaption = "ListView control";
  pCreateInfo->hMenu = 0;
  pCreateInfo->hCursor = GetSystemCursor (1);
  pCreateInfo->hIcon = 0;
  pCreateInfo->MainWindowProc = ControlTestWinProc;
  pCreateInfo->lx = 0;
  pCreateInfo->ty = 0;
  pCreateInfo->rx = 400;
  pCreateInfo->by = 300;
  pCreateInfo->iBkColor = GetWindowElementColor (BKC_CONTROL_DEF); 
  pCreateInfo->dwAddData = 0;
  pCreateInfo->hHosting = HWND_DESKTOP;
}

void
listview_demo (HWND hwnd)
{
  MAINWINCREATE CreateInfo;
  if (hMainWnd != HWND_INVALID)
    {
      ShowWindow (hMainWnd, SW_SHOWNORMAL);
      return;
    }

  InitCreateInfo (&CreateInfo);
  CreateInfo.hHosting = hwnd;

  hMainWnd = CreateMainWindow (&CreateInfo);


  /*
     MessageBox (hwnd, "Sorry, this demo is under construction!",
     "Under construction!", MB_OK | MB_ICONINFORMATION); */
}