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

WNDPROC origEditWndProc = NULL;

WNDPROC origComboWndProc = NULL;

int tables = 0;

column_t *table[32];

LVWnd_t *window[32];

int get_row_id(LVWnd_t * wnd)

{

      char str[16];

      ListView_GetItemText(wnd->hLV, wnd->editRow, 0, str, sizeof(str));

      return atoi(str);

}

/* создание 2 окон - главного и дочернего(список) */

int create_mdi_listview(TCHAR * wnd_class, TCHAR * caption, HWND * parent, HWND * child, column_t * cols)

{

      HWND hMainWnd = CreateMDIWindow(wnd_class, (LPCTSTR)caption,

            MDIS_ALLCHILDSTYLES /*| WS_VSCROLL*/ | WS_CLIPCHILDREN, CW_USEDEFAULT, 0,

            CW_USEDEFAULT, 0, hMDIClientWnd, hInstance, (LPARAM)NULL);

      if (!hMainWnd)

            return 0;

      *parent = hMainWnd;

      HWND hListWnd = CreateWindowEx (0, "SysListView32", 0,

            LVS_SHOWSELALWAYS + LVS_SINGLESEL + LVS_SORTASCENDING + LVS_REPORT + WS_CHILD + WS_VISIBLE,

                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainWnd, 0, hInstance, 0);

      if (!hListWnd)   

            return 0;

      *child = hListWnd;

      /* Q230049 */

      SendMessage (hListWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

      int i = 0;

      LVCOLUMN lvc;

      lvc.mask = LVCF_TEXT + LVCF_WIDTH;

      while (cols[i].type != CT_NULL)

      {

            lvc.cx = cols[i].width;

            lvc.pszText = cols[i].name;

            ListView_InsertColumn(hListWnd, i++, &lvc);

      }

      SetWindowLong(hListView, GWL_WNDPROC, (DWORD)LVWndProc);

      return 1;

}

/* создание 2 окон - главного и дочернего(список) */

int create_result_listview(TCHAR * wnd_class, TCHAR * caption, HWND * parent, HWND * child, column_t * cols)

{

      HWND hMainWnd = CreateMDIWindow(wnd_class, (LPCTSTR)caption,

            MDIS_ALLCHILDSTYLES /*| WS_VSCROLL*/ | WS_CLIPCHILDREN, CW_USEDEFAULT, 0,

            CW_USEDEFAULT, 0, hMDIClientWnd, hInstance, (LPARAM)NULL);

      if (!hMainWnd)

            return 0;

      *parent = hMainWnd;

      HWND hListWnd = CreateWindowEx (0, "SysListView32", 0,

            LVS_SHOWSELALWAYS + LVS_SINGLESEL + LVS_SORTASCENDING + LVS_REPORT + WS_CHILD + WS_VISIBLE,

                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMainWnd, 0, hInstance, 0);

      if (!hListWnd)   

            return 0;

      *child = hListWnd;

      /* Q230049 */

      SendMessage (hListWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

      int i = 0;

      LVCOLUMN lvc;

      lvc.mask = LVCF_TEXT + LVCF_WIDTH;

      while (cols[i].type != CT_NULL)

      {

            lvc.cx = cols[i].width;

            lvc.pszText = cols[i].name;

            ListView_InsertColumn(hListWnd, i++, &lvc);

      }

      ShowWindow (hListWnd, SW_SHOWNORMAL);

      UpdateWindow(hListWnd);

      ShowWindow(hMainWnd, SW_SHOWMINIMIZED);

      return 1;

}

int create_mdi_table(LVWnd_t * wnd)

{

      wnd->hTable = CreateMDIWindow (table_wnd_class, (LPCTSTR)wnd->name,

            MDIS_ALLCHILDSTYLES /*| WS_VSCROLL*/ | WS_CLIPCHILDREN | WS_VISIBLE,

            CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, /* sizes */

            hMDIClientWnd, hInstance, (LPARAM)wnd);

      origLVWndProc = (WNDPROC) SetWindowLong (wnd->hLV, GWL_WNDPROC, (LONG)LVWndProc);

      SetWindowLong (wnd->hLV, GWL_USERDATA, (LONG)wnd);

      LVCOLUMN lvc;

      lvc.mask = LVCF_TEXT + LVCF_WIDTH;

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

      {

            lvc.cx = table[wnd->tid][i].width;

            lvc.pszText = table[wnd->tid][i].name;

            ListView_InsertColumn(wnd->hLV, i, &lvc);

      }

      return 0;

}

LRESULT CALLBACK TableWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

      switch (message)

      {

      case WM_CREATE:

      {

            MDICREATESTRUCT * mcs = (MDICREATESTRUCT*)*(LONG*)lParam;

            LVWnd_t * wnd = (LVWnd_t*)mcs->lParam;

            wnd->editCol = -1;

            wnd->editRow = -1;

            SetWindowLong (hWnd, GWL_USERDATA, (LONG)wnd);