ListView滚动条闪烁

时间:2011-06-01 13:33:44

标签: c winapi listview

我使用纯WinAPI编写我的第一个程序。但我遇到了一些奇怪的问题。

表单上有2个ListView元素可输出一些值。当滚动条出现在第二个ListView上时,表单上的所有子对象都会消失。 ListView的滚动条闪烁。当我推动ListView时,所有都恢复正常。我不知道该怎么做。

但是这个问题仅适用于表单上的第二个ListView元素hListViewCh。第一个元素没问题。

以下是代码:

case WM_CREATE:
    {
    GetClientRect(hWnd, &Rect);

    h_Chk1 = CreateWindow(TEXT("button"), TEXT("Graphic"),
             WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
             Rect.right - 550, 
     300  + 10, 
     100, 
     20,
     hWnd, (HMENU)0xCB01, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
        h_Chk2 = CreateWindow(TEXT("button"), TEXT("Diagram"),
             WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
             Rect.right - 550, 
     300  + 35, 
     100, 
     20,
     hWnd, (HMENU)0xCB02, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
        CheckDlgButton(hWnd, 0xCB01, BST_UNCHECKED);
    CheckDlgButton(hWnd, 0xCB02, BST_UNCHECKED);

            hListViewCh = CreateWindow(
                WC_LISTVIEW, 
                _T("MyList"),
                LVS_REPORT|WS_CHILD|WS_VISIBLE,
                Rect.right - 265,
                377,
                     250,
                200,
                hWnd, (HMENU)listViewCh, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
            //--
            LVCOLUMN lvColumn = {0};
            lvColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT;
            lvColumn.fmt = LVCFMT_CENTER;
            lvColumn.pszText = "№";
            lvColumn.cx = 30;
            ListView_InsertColumn(hListViewCh, 0, &lvColumn);
            lvColumn.pszText = "Property";
            lvColumn.cx = 70;
            ListView_InsertColumn(hListViewCh, 1, &lvColumn);
            lvColumn.pszText = "Value";
            lvColumn.cx = 120;
            ListView_InsertColumn(hListViewCh, 2, &lvColumn);
            //--
         hListView = CreateWindow(
          WC_LISTVIEW,
          _T("Set of variate values"),
          LVS_REPORT|WS_CHILD|WS_VISIBLE,
          Rect.right - 550,
          Rect.top   +  15,
          535,
          275,
          hWnd,
          (HMENU)listView,
          (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
          NULL);
            //--
            lvColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT;
            lvColumn.pszText = "No";
            lvColumn.fmt = LVCFMT_CENTER;
            lvColumn.cx = 43;
                            ListView_InsertColumn(hListView, 0, &lvColumn);
            //--
            lvColumn.pszText = "[ a[i-1]      ,         a[i] )";
            lvColumn.cx = 151;
            ListView_InsertColumn(hListView, 1, &lvColumn);
            //--
            lvColumn.pszText = "xi";
            lvColumn.cx = 85;
            ListView_InsertColumn(hListView, 2, &lvColumn);
            //--
            lvColumn.pszText = "ni";
            ListView_InsertColumn(hListView, 3, &lvColumn);
            //--
            lvColumn.pszText = "V";
            ListView_InsertColumn(hListView, 4, &lvColumn);
            //--
            lvColumn.pszText = "EV";
            ListView_InsertColumn(hListView, 5, &lvColumn);
            break;
}

WM_PAINT中有一些重绘函数可以使ListViews在最大化的窗口中移动。

        //-- LISTVIEW POSITION
        SetWindowPos(hListViewCh, NULL,\
                            Rect.right - 265,
                            312,
                            250,
                            200,
                            SWP_NOSIZE);
        //-- LISTVIEW POSITION
        SetWindowPos(hListView, NULL,\
                            Rect.right - 550,\
                            Rect.top   +  15,\
                            535,\
                            340,\
                            SWP_NOSIZE|SWP_NOZORDER);
        //--

1 个答案:

答案 0 :(得分:3)

调整WM_PAINT中的子窗口大小是完全错误的,我怀疑这是您问题的重要部分。

应该运行定位子窗口的代码以响应WM_WINDOWPOSCHANGED消息。