Разработка информационно-поисковой системы, страница 17

            wnd->hLV = CreateWindowEx (0, WC_LISTVIEW, NULL,

                  LVS_SHOWSELALWAYS + LVS_SORTASCENDING + LVS_REPORT + WS_CHILD + WS_VISIBLE,

                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

                  hWnd, 0, hInstance, 0);

            SendMessage (wnd->hLV, LVM_SETEXTENDEDLISTVIEWSTYLE,

                  0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

            break;

      }

      case WM_SIZE:

      {

            RECT rect;

            LVWnd_t * wnd = (LVWnd_t*) GetWindowLong (hWnd, GWL_USERDATA);

            if (wnd == 0) break;

            GetClientRect (hWnd, &rect);

            /* разтяжение окна списка на всю клиентскую область главного окна */

            MoveWindow (wnd->hLV, 0, 0, rect.right, rect.bottom, TRUE);

            return DefMDIChildProc (hWnd, message, wParam, lParam);

      }

      case WM_KEYDOWN:

      {

            LVWnd_t * wnd = (LVWnd_t*) GetWindowLong (hWnd, GWL_USERDATA);

            if (wnd)

            switch(wParam)

            {

                  case VK_DELETE:

                  {

                        if (wnd->rows == 0 || wnd->editRow == -1)

                              return 0;

                        if (delete_row(wnd))

                              MessageBox (hWnd, "Невозможно удалить элемент !",

                                   "Ошибка !", MB_ICONERROR);

                        else

                        {

                              LRESULT rc = ListView_DeleteItem (wnd->hLV, wnd->editRow);

                              wnd->rows--;

                        }

                        break;

                  }

                  case VK_INSERT:

                  {    

                        char ** buf = (char**)malloc(sizeof(int)*wnd->cols);

                        char tmp[] = "???";

                        for (int i = 0; i < wnd->cols; i++)

                              buf[i] = tmp;

                        insert_row (wnd, buf);

                        free (buf);

                        break;

                  }

            }

            break;

      }

      case WM_NOTIFY:

      {

            LPNMHDR nmhdr = (LPNMHDR)lParam;

            if (nmhdr->code == LVN_ENDLABELEDIT)

            {

                  LPNMLVDISPINFOA pdi = (LPNMLVDISPINFOA) lParam;

                  char *newText = pdi->item.pszText;

                  if (newText != NULL)

                  {    

                        LVWnd_t * wnd = (LVWnd_t*) GetWindowLong (hWnd, GWL_USERDATA);

                        if (wnd == 0) break;

                        ListView_SetItemText (wnd->hLV, wnd->editRow, wnd->editCol, newText);

                  }

            }

            break;

      }

      case WM_ERASEBKGND:

            break;

      case WM_CLOSE:

      {

            LVWnd_t * wnd = (LVWnd_t*) GetWindowLong (hWnd, GWL_USERDATA);

            if (wnd)

                  wnd->hTable = 0;

      }

      default:

            return DefMDIChildProc (hWnd, message, wParam, lParam);

      }

      return 0;

}

LRESULT CALLBACK LVWndProc(HWND hWnd, UINT mMsg, WPARAM wParam, LPARAM lParam)

{

      static HWND hCell = NULL; /* Edit/Combo */

      switch (mMsg)

      {

      case WM_KEYDOWN:

      case WM_CHAR:

      {

            /* pass on keyboard input to the parent */

            SendMessage(GetParent(hWnd), mMsg, wParam, lParam);

            break;

      }

      case WM_LBUTTONDOWN:

      {

            LVWnd_t * wnd = (LVWnd_t*) GetWindowLong (hWnd, GWL_USERDATA);

            if (wnd == 0)

                  return 0;

            LRESULT rc;

            LVHITTESTINFO hti;

            memset(&hti, 0, sizeof(hti));

            hti.pt.x = LOWORD(lParam);

            hti.pt.y = HIWORD(lParam);

            ListView_SubItemHitTest(hWnd, &hti);

            wnd->editRow = hti.iItem;

            wnd->editCol = hti.iSubItem;

            enum COLUMN_TYPE coltype = table[wnd->tid][wnd->editCol].type;

            if (coltype == CT_CONST)

            {